Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listbox Border - Anyways to remove?

Status
Not open for further replies.

ZOR

Technical User
Jan 30, 2002
2,963
GB
I know there are only two property changes, 3d or Flat, but flat leaves the listbox with a border. Any way to get rid of it? Thanks
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top