It's okay, I've found a way to do it. For the benefit of others that might want to do the same. Put the listbox inside a picture box. The picturebox can be borderless. Set the listbox top/left/width properties to hide the border withing the picturebox, and there you have a borderless listbox.
Here's an API solution (you'll need a form with a command button and a listbox): [tt]
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const SWP_FRAMECHANGED = &H20
Private Const GWL_STYLE = (-16)
Private Const WS_BORDER = &H800000
Private Sub Command1_Click()
ToggleControlBorder List1
End Sub
' Warning: if targetcontrol is a listbox and its IntegralHeight property is set to true then toggling border back
' on is likely to cause the listbox to shrink in size because the client area gets recalculated due to SWP_FRAMECHANGED
' flag. Omitting the flag, however, means that frame (i.e border) would not get redrawn
' Assumption: control being passed has an hWnd property Private Function ToggleControlBorder(TargetControl As Control)
SetWindowLong TargetControl.hwnd, GWL_STYLE, GetWindowLong(TargetControl.hwnd, GWL_STYLE) Xor WS_BORDER
SetWindowPos TargetControl.hwnd, 0, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE Or SWP_FRAMECHANGED 'Or SWP_NOREDRAW
End Function
Thanks Strongm,
I will keep your info for future. Maybe what I have done is wasting a control, but placing an idle picture box on the form did it without anything other than me setting sizes. Thanks for comming back.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.