Hiding combo box border and drop-down box 
Author Message
 Hiding combo box border and drop-down box

I use this function to hide the border and drop box for
combo boxes. Open to critism. Just wondering if there is a
faster way.

Option Explicit

' RECTANGLE CONSTRUCT
Type typRECT
    X1_LEFT As Long
    Y1_TOP As Long
    X2_RIGHT As Long
    Y2_BOTTOM As Long
End Type

' API CALLS FOR WINDOWS CLIPPING
Public Declare Function GetSystemMetrics Lib "user32.dll" _
        (ByVal nIndex As Long) As Long
Public Declare Function GetWindowRect Lib "user32.dll" _
        (ByVal hwnd As Long, lpRect As typRECT) As Long
Public Declare Function SetWindowRgn Lib "user32.dll" _
        (ByVal hwnd As Long, ByVal hRgn As Long, _
       ByVal bRedraw As Boolean) As Long
Public Declare Function CreateRectRgn Lib "gdi32.dll" _
        (ByVal X1 As Long, ByVal Y1 As Long, _
        ByVal X2 As Long, ByVal Y2 As Long) As Long
Public Declare Function CreateRoundRectRgn Lib "gdi32.dll"
_
        (ByVal X1 As Long, ByVal Y1 As Long, _
        ByVal X2 As Long, ByVal Y2 As Long, _
        ByVal X3 As Long, ByVal Y3 As Long) As Long
Public Declare Function DeleteObject Lib "gdi32.dll" _
        (ByVal hObject As Long) As Long

' API CONSTANTS FOR GetSystemMetrics
Public Const SM_CXEDGE = 45
Public Const SM_CYEDGE = 46
Public Const SM_CXHSCROLL = 21
Public Const SM_CYVSCROLL = 20

Public Sub DrawEditModeCombo(cntCONTROL As Control,
boolEDIT_MODE As Boolean)

    Dim hndREGION_TEMP As Long
    Dim lng3DVBORDER_WIDTH As Long
    Dim lng3DHBORDER_WIDTH As Long
    Dim lngXSCROLL_WIDTH As Long
    Dim lngRETURN As Long
    Dim typCOMBO As typRECT

    lngRETURN = SetWindowRgn(cntCONTROL.hwnd, 0, True)

    lng3DVBORDER_WIDTH = GetSystemMetrics(SM_CXEDGE)
    lng3DHBORDER_WIDTH = GetSystemMetrics(SM_CYEDGE)
    lngXSCROLL_WIDTH = GetSystemMetrics(SM_CXHSCROLL)

    lngRETURN = GetWindowRect(cntCONTROL.hwnd, typCOMBO)

    If (cntCONTROL.Enabled) And (boolEDIT_MODE) Then
        hndREGION_TEMP = 0
    Else
        hndREGION_TEMP = CreateRectRgn(1, 1, _
                typCOMBO.X2_RIGHT - typCOMBO.X1_LEFT - 1 -
lngXSCROLL_WIDTH, _
                typCOMBO.Y2_BOTTOM - typCOMBO.Y1_TOP - 1)
    End If

    lngRETURN = SetWindowRgn(cntCONTROL.hwnd,
hndREGION_TEMP, True)

    lngRETURN = DeleteObject(hndREGION_TEMP)

End Sub

Thanks,

Bill



Tue, 07 Jun 2005 02:38:32 GMT  
 Hiding combo box border and drop-down box
Forgot to mention this code must be win95 compatible,
that's why I use the Systemmetrics to figure the
coordinates of the drop down buttons.

Bill



Tue, 07 Jun 2005 02:49:41 GMT  
 Hiding combo box border and drop-down box
Not sure what the requirements are but if you start a new project and drop a
commandbutton, a combobox and a textbox on the form and run the code below, it may be
"good enough"
'=======
Option Explicit

Private Sub Form_Load()
   Text1.BorderStyle = 0
   Text1.Visible = False
End Sub

Private Sub Text1_GotFocus()
   Text1.Visible = False
   Combo1.Visible = True
   Combo1.SetFocus
End Sub

Private Sub Combo1_LostFocus()
   With Combo1
      Text1.Move .Left, .Top, .Width, .Height
      Text1.Text = .Text
      Text1.Visible = True
      .Visible = False
   End With
End Sub
'=======

--
Ken Halter - MS-MVP-VB - http://www.vbsight.com - Please keep it in the groups..


Quote:
> I use this function to hide the border and drop box for
> combo boxes. Open to critism. Just wondering if there is a
> faster way.

> Option Explicit

> ' RECTANGLE CONSTRUCT
> Type typRECT
>     X1_LEFT As Long
>     Y1_TOP As Long
>     X2_RIGHT As Long
>     Y2_BOTTOM As Long
> End Type

> ' API CALLS FOR WINDOWS CLIPPING
> Public Declare Function GetSystemMetrics Lib "user32.dll" _
>         (ByVal nIndex As Long) As Long
> Public Declare Function GetWindowRect Lib "user32.dll" _
>         (ByVal hwnd As Long, lpRect As typRECT) As Long
> Public Declare Function SetWindowRgn Lib "user32.dll" _
>         (ByVal hwnd As Long, ByVal hRgn As Long, _
>        ByVal bRedraw As Boolean) As Long
> Public Declare Function CreateRectRgn Lib "gdi32.dll" _
>         (ByVal X1 As Long, ByVal Y1 As Long, _
>         ByVal X2 As Long, ByVal Y2 As Long) As Long
> Public Declare Function CreateRoundRectRgn Lib "gdi32.dll"
> _
>         (ByVal X1 As Long, ByVal Y1 As Long, _
>         ByVal X2 As Long, ByVal Y2 As Long, _
>         ByVal X3 As Long, ByVal Y3 As Long) As Long
> Public Declare Function DeleteObject Lib "gdi32.dll" _
>         (ByVal hObject As Long) As Long

> ' API CONSTANTS FOR GetSystemMetrics
> Public Const SM_CXEDGE = 45
> Public Const SM_CYEDGE = 46
> Public Const SM_CXHSCROLL = 21
> Public Const SM_CYVSCROLL = 20

> Public Sub DrawEditModeCombo(cntCONTROL As Control,
> boolEDIT_MODE As Boolean)

>     Dim hndREGION_TEMP As Long
>     Dim lng3DVBORDER_WIDTH As Long
>     Dim lng3DHBORDER_WIDTH As Long
>     Dim lngXSCROLL_WIDTH As Long
>     Dim lngRETURN As Long
>     Dim typCOMBO As typRECT

>     lngRETURN = SetWindowRgn(cntCONTROL.hwnd, 0, True)

>     lng3DVBORDER_WIDTH = GetSystemMetrics(SM_CXEDGE)
>     lng3DHBORDER_WIDTH = GetSystemMetrics(SM_CYEDGE)
>     lngXSCROLL_WIDTH = GetSystemMetrics(SM_CXHSCROLL)

>     lngRETURN = GetWindowRect(cntCONTROL.hwnd, typCOMBO)

>     If (cntCONTROL.Enabled) And (boolEDIT_MODE) Then
>         hndREGION_TEMP = 0
>     Else
>         hndREGION_TEMP = CreateRectRgn(1, 1, _
>                 typCOMBO.X2_RIGHT - typCOMBO.X1_LEFT - 1 -
> lngXSCROLL_WIDTH, _
>                 typCOMBO.Y2_BOTTOM - typCOMBO.Y1_TOP - 1)
>     End If

>     lngRETURN = SetWindowRgn(cntCONTROL.hwnd,
> hndREGION_TEMP, True)

>     lngRETURN = DeleteObject(hndREGION_TEMP)

> End Sub

> Thanks,

> Bill



Tue, 07 Jun 2005 02:52:46 GMT  
 Hiding combo box border and drop-down box
What is the goal of this exercise????  Knowing that will help in identifying
the correct response.

--

Randy Birch
MVP Visual Basic
http://www.mvps.org/vbnet/
Please respond only to the newsgroups so all can benefit.



Tue, 07 Jun 2005 07:15:48 GMT  
 Hiding combo box border and drop-down box
The goal was to turn off not only the border but also the
drop button on data combo boxes in a Win95 environment.

The field is intended to exist in two drawn states: an
editable state (with border and button visible) and a non-
editable state (with border and button not visible).



Tue, 07 Jun 2005 23:05:25 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Hiding drop-down arrow in combo box

2. Drop Down Combo box with smaller down arrow icon

3. Drop Down List Box - Drop Down portion does not always disappear after Click event

4. Combo box drop down on got focus

5. Values in drop-down combo box

6. Drop-down(Combo box) text limit?

7. Character limit of Combo Box - Drop Down Item

8. REPOST: How to display a user control on combo box drop down (OwnerDrawn)

9. Thanks for the Help (Combo Box Automatically Drops down)

10. Help Drop Down a Combo box automatically !!?

11. drop-down combo box

12. Drop Down Combo Box Events

 

 
Powered by phpBB® Forum Software