View Poll Results: What do you think of this code?

Voters
1. You may not vote on this poll
  • Excellent

    1 100.00%
  • Good

    0 0%
  • Bad

    0 0%
  • Awful

    0 0%
Results 1 to 17 of 17

Thread: Easiest way to have a Borderless Combo! (Without using Forms 2.0 or Third Party)

  1. #1

    Thread Starter
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192

    Easiest way to have a Borderless Combo! (Without using Forms 2.0 or Third Party)

    I was investigating the forums searching for a way to resize the default ComboBox control (Not the one of Forms 2.0) but there were few samples and all tried to use subclassing and some even were buggy...

    So I thought maybe it would be as useful for my purposes to find a way to make the combobox be borderless... but, I found the same kind of samples which were complex (I wanted something simple because I am using an already complex class for my purposes) and I thought of this code which is fairly simple.

    Originally the code used no APIs but it required the Combo to be embedded already, so I just added one simple API to the code and one more line and I believe it is pretty simple.

    Anyway, I would have liked to have been able to do it without the aid of another control or that I could simply declare it as "New" and then fill it without having it on the Form. If you have an idea, a comment or a suggestion I would like to hear from you.
    Attached Files Attached Files
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    OK, but why do you want it borderless?

    I would modify your the bottom of your NoBorder function to look like this.

    VB Code:
    1. NoBorder = True
    2.  
    3.     Exit Function
    4. EndFunction:
    5.     MsgBox Err.Number & " " & Err.Description
    6. End Function

    It would also be better to change the return type of the function to Integer and return err.number rather than displaying the error message (if any) in the function.

  3. #3

    Thread Starter
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192
    Thanks for the reply, Martin.

    Regarding your suggestion, I don't think I can use it because I am just interested in knowing if the Control was resized or not in run-time.

    I can actually tell what the error might be already (A control without Width or Height or maybe they didn't give a PictureBox). And I don't want to annoy the user of the program with a messagebox of something he doesn't know about.

    I want to avoid messages like the ones of Microsoft thay say "Error the memory could not be: READ". I prefer to know if there was no problem with the function and recover if there was one and I want to do it neatly without annoying the user.

    Anyway, that's a discussion about using error messages or not... Some programmers prefer to use a status bar for that purpose.

    Oh, and why do I want a borderless combobox? An image is worth thousand words. I attach the reason as a picture.

    Greetings!
    Attached Images Attached Images  
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    I can see why you want it borderless and it looks good.

    I agree that it's not a good idea to display the error in the function. I think that every function should have a return and it should be up to the calling procedure to decide what to do with the return value. The use of a Boolean can only say success/non-success. An Integer however can say success (when 0) and non-success (any other value). The advantage of the Integer is of course that if you want to know why it failed, the value will tell you.

  5. #5

    Thread Starter
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192
    I see your point, Martin... You are right. I was thinking about that after I replied to you and I came to the same conclusion.

    And I agree it would be a nice idea to use it to know which is the source of the error, but currently (since I am the only one who uses the class in the project ) the interesting would be to see if the function works or not.

    In a future I might consider (for more complex functions) incorporate your suggestion. I really appreciate it.

    I also made the borderless Combo because I found there were some threads with people asking for a flat combo or a borderless combo. The flat combo could be easily achieved using this idea and so I posted it.
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

  6. #6

  7. #7

    Thread Starter
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192
    Yeah, I used to pass by reference Arrays of Integers when I didn't know how to return Arrays without using Variants.

    (Now I know, of course) but it is a pretty good idea. I will post some code in the DataBank as soon as I can solve some issues of the project. I don't want to post a buggy code there.

    Could you please check my other post?

    Thanks again
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

  8. #8

  9. #9

    Thread Starter
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192
    Thanks, Martin. I meant this one:

    http://www.vbforums.com/showthread.p...hreadid=285872
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

  10. #10
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284

    Re: Easiest way to have a Borderless Combo! (Without using Forms 2.0 or Third Party)

    vb Code:
    1. Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
    2. Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
    3.  
    4. 'The function is not designed just for Combos, it can be used for any control!
    5. Public Function NoBorder(ctrlGiven As Control, Optional iOffSet As Integer = 0) As Boolean
    6. On Error GoTo EndFunction
    7.  Dim iBorder As Integer
    8.  Dim picTemp As PictureBox
    9.  
    10.  Set picTemp = ctrlGiven.Parent.Controls.Add("VB.PictureBox", "HideBorder_" + CStr(ctrlGiven.Name))
    11.  SetParent picTemp.hwnd, GetParent(ctrlGiven.hwnd) 'move the new object to the proper container, otherwise it will be simply added to the main form.
    12.  
    13.  With picTemp
    14.   .Left = ctrlGiven.Left
    15.   .Top = ctrlGiven.Top
    16.   '.Visible = ctrlGiven.Visible 'Not really work at all.
    17.   .Visible = True
    18.  End With
    19.  
    20.  iBorder = ((picTemp.Width - picTemp.ScaleWidth) / 2) - iOffSet
    21.  
    22.  SetParent ctrlGiven.hwnd, picTemp.hwnd
    23.  With picTemp
    24.   .BorderStyle = 0
    25.   .Width = ctrlGiven.Width - iBorder * 2
    26.   .Height = ctrlGiven.Height - iBorder * 2
    27.  End With
    28.  
    29.  With ctrlGiven
    30.   .Left = -iBorder
    31.   .Top = -iBorder
    32.  End With
    33.  
    34.  NoBorder = True
    35.  
    36.  Set picTemp = Nothing
    37. EndFunction:
    38. End Function
    39.  
    40. Private Sub Form_Load()
    41.   Me.Show
    42.   DoEvents
    43.  
    44.   NoBorder Combo1, 0
    45.   NoBorder File1, 0
    46.   NoBorder Text1, 0
    47. End Sub

    Think ive found a way, that you dont have to add a picturebox at design time, but rather than that it is simply ough to add it at runtime, just when you calling the method "noborder".

    After, setting the parents, the controls (objects) will be merged somehow, that means i cant remove the picTemp control anymore. But it seems to me that vb will remove it, with the parent control at when destroying the form and its contained controls. I found no any leaks so far, but please someone can confirm it?
    Last edited by Jim Davis; Feb 4th, 2009 at 03:31 PM.

  11. #11

  12. #12
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284

    Re: Easiest way to have a Borderless Combo! (Without using Forms 2.0 or Third Party)

    The thread was, but the problem isnt to me, i just wanted to remove the border. I thought its a good idea to posting here, because this way is belongs to this thread. I have just extended the original code.

  13. #13
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Easiest way to have a Borderless Combo! (Without using Forms 2.0 or Third Party)

    Quote Originally Posted by MartinLiss
    Jim, did you realize that this thread was almost 5 years old?
    I never understood that, why would it matter how old the thread is? As long as the post is on topic..... VB6 and earlier hasn't changed, the code is still the same.

  14. #14
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Easiest way to have a Borderless Combo! (Without using Forms 2.0 or Third Party)

    Yes, but everyone who has subscribed to the thread (which I presume is most people who posted in it, and others) will get notification of it - which is likely to annoy them.

    In addition to that, having a new reply means that the thread becomes active again, and other people will spend time try to help the OP who is almost certainly not going to be interested any more (and usually don't reply to say that either).



    What Jim did was basically OK, as it will help those who search - but ideally there should have been some kind of indication that the thread was old to stop people attempting to help the OP, hence why moderators/admins (and others) post something to that effect if it isn't included already.
    Last edited by si_the_geek; Feb 5th, 2009 at 05:10 AM.

  15. #15
    Frenzied Member
    Join Date
    Mar 2008
    Posts
    1,210

    Re: Easiest way to have a Borderless Combo! (Without using Forms 2.0 or Third Party)

    Jim,

    I wonder if you need the API calls; e.g. you may be able to replace the first one with;

    Set picTemp.Container = ctrlGiven.Parent

    and the second with;

    Set ctrlGiven.Container = picTemp

    Following that a;

    picTemp.TabStop = False

    may be handy too.

  16. #16
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284

    Re: Easiest way to have a Borderless Combo! (Without using Forms 2.0 or Third Party)

    @MagicInk you were right, it is simply enough to set the containers from within vb instead of using the parent api's.

    Code:
    Set picTemp.Container = ctrlGiven.Container 'using the .parent may not work in some cases, if you use two or more frames.
    
    '....
    Set ctrlGiven.Container = picTemp: picTemp.TabStop = False
    Nice, thanks!

  17. #17
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284

    Re: Easiest way to have a Borderless Combo! (Without using Forms 2.0 or Third Party)

    Quote Originally Posted by si_the_geek
    Yes, but
    Right. However, everyone have the option to remove subscriptions from their list . That would be also nice, the system should automatically >close< an old thread (in case there were no additions in the last half or 1 year for example) and >mark it as "[Archived]"< or something, to prevent this to happening. Or, just simply remove the subscriptions from the users, if the thread is marked as outdated/archived.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width