W
Wapiti
I'm trying to use SendMessage to control the combobox's dropdown area's
width. This was a no brainer in VB6, and seems very comparible in vb.net.
But for some reason, the list area isn't expanding to the number of pixels I
specify. It appears that others have made this work, so I must be doing
something wrong.
SendMessage continually returns the width of the control as it resides on
the form, rather than the value I send it.
Public Class Form1
Inherits System.Windows.Forms.Form
Friend WithEvents cmbTEST As System.Windows.Forms.ComboBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
Protected Overrides Sub OnLoad(ByVal e As EventArgs)
MyBase.OnLoad(e)
setComboboxWidth(cmbTEST, 400)
End Sub 'OnLoad
'For ComboBox width (see setComboboxWidth below)
Declare Function SendMessage Lib "coreDll.dll" (ByVal hwnd As IntPtr, ByVal
wMsg As Int32, ByVal wParam As Boolean, Optional ByVal lParam As Integer =
0) As Integer
Declare Function GetCapture Lib "coredll.dll" () As IntPtr
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
MyBase.Dispose(disposing)
End Sub
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Private Sub InitializeComponent()
Me.MainMenu1 = New System.Windows.Forms.MainMenu
Me.cmbTEST = New System.Windows.Forms.ComboBox
Me.Button1 = New System.Windows.Forms.Button
'
'cmbTEST
'
Me.cmbTEST.Items.Add("this is a test")
Me.cmbTEST.Items.Add("this is a nother test")
Me.cmbTEST.Items.Add("this is another another test")
Me.cmbTEST.Location = New System.Drawing.Point(32, 112)
Me.cmbTEST.Size = New System.Drawing.Size(64, 22)
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(72, 184)
Me.Button1.Text = "Button1"
'
'Form1
'
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.cmbTEST)
Me.Menu = Me.MainMenu1
Me.Text = "Form1"
End Sub
#End Region
'I've tried LONG and INT, both give the same results - no change to the
width of the list area. ??
Public Sub setComboboxWidth(ByVal cmb As ComboBox, ByVal pxWidth As Long)
Const CB_SETDROPPEDWIDTH = &H160
cmb.Capture = True
Dim hwnd As IntPtr = GetCapture()
cmb.Capture = False
Dim rtn As Integer
rtn = SendMessage(hwnd, CB_SETDROPPEDWIDTH, pxWidth, 0)
If (rtn = -1) Then
MsgBox("An error occurred in sendmessage! (" & rtn & ")")
Else
MsgBox("SendMessage returned (" & rtn & ")")
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Me.Close()
End Sub
End Class
width. This was a no brainer in VB6, and seems very comparible in vb.net.
But for some reason, the list area isn't expanding to the number of pixels I
specify. It appears that others have made this work, so I must be doing
something wrong.
SendMessage continually returns the width of the control as it resides on
the form, rather than the value I send it.
Public Class Form1
Inherits System.Windows.Forms.Form
Friend WithEvents cmbTEST As System.Windows.Forms.ComboBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
Protected Overrides Sub OnLoad(ByVal e As EventArgs)
MyBase.OnLoad(e)
setComboboxWidth(cmbTEST, 400)
End Sub 'OnLoad
'For ComboBox width (see setComboboxWidth below)
Declare Function SendMessage Lib "coreDll.dll" (ByVal hwnd As IntPtr, ByVal
wMsg As Int32, ByVal wParam As Boolean, Optional ByVal lParam As Integer =
0) As Integer
Declare Function GetCapture Lib "coredll.dll" () As IntPtr
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
MyBase.Dispose(disposing)
End Sub
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Private Sub InitializeComponent()
Me.MainMenu1 = New System.Windows.Forms.MainMenu
Me.cmbTEST = New System.Windows.Forms.ComboBox
Me.Button1 = New System.Windows.Forms.Button
'
'cmbTEST
'
Me.cmbTEST.Items.Add("this is a test")
Me.cmbTEST.Items.Add("this is a nother test")
Me.cmbTEST.Items.Add("this is another another test")
Me.cmbTEST.Location = New System.Drawing.Point(32, 112)
Me.cmbTEST.Size = New System.Drawing.Size(64, 22)
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(72, 184)
Me.Button1.Text = "Button1"
'
'Form1
'
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.cmbTEST)
Me.Menu = Me.MainMenu1
Me.Text = "Form1"
End Sub
#End Region
'I've tried LONG and INT, both give the same results - no change to the
width of the list area. ??
Public Sub setComboboxWidth(ByVal cmb As ComboBox, ByVal pxWidth As Long)
Const CB_SETDROPPEDWIDTH = &H160
cmb.Capture = True
Dim hwnd As IntPtr = GetCapture()
cmb.Capture = False
Dim rtn As Integer
rtn = SendMessage(hwnd, CB_SETDROPPEDWIDTH, pxWidth, 0)
If (rtn = -1) Then
MsgBox("An error occurred in sendmessage! (" & rtn & ")")
Else
MsgBox("SendMessage returned (" & rtn & ")")
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Me.Close()
End Sub
End Class