1 Attachment(s)
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.
Re: Easiest way to have a Borderless Combo! (Without using Forms 2.0 or Third Party)
vb Code:
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
'The function is not designed just for Combos, it can be used for any control!
Public Function NoBorder(ctrlGiven As Control, Optional iOffSet As Integer = 0) As Boolean
On Error GoTo EndFunction
Dim iBorder As Integer
Dim picTemp As PictureBox
Set picTemp = ctrlGiven.Parent.Controls.Add("VB.PictureBox", "HideBorder_" + CStr(ctrlGiven.Name))
SetParent picTemp.hwnd, GetParent(ctrlGiven.hwnd) 'move the new object to the proper container, otherwise it will be simply added to the main form.
With picTemp
.Left = ctrlGiven.Left
.Top = ctrlGiven.Top
'.Visible = ctrlGiven.Visible 'Not really work at all.
.Visible = True
End With
iBorder = ((picTemp.Width - picTemp.ScaleWidth) / 2) - iOffSet
SetParent ctrlGiven.hwnd, picTemp.hwnd
With picTemp
.BorderStyle = 0
.Width = ctrlGiven.Width - iBorder * 2
.Height = ctrlGiven.Height - iBorder * 2
End With
With ctrlGiven
.Left = -iBorder
.Top = -iBorder
End With
NoBorder = True
Set picTemp = Nothing
EndFunction:
End Function
Private Sub Form_Load()
Me.Show
DoEvents
NoBorder Combo1, 0
NoBorder File1, 0
NoBorder Text1, 0
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?
Re: Easiest way to have a Borderless Combo! (Without using Forms 2.0 or Third Party)
Jim, did you realize that this thread was almost 5 years old?
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.
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.
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.
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.
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!
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.