Adjusting Combo Box Height Property

S

Steve Le Monnier

I've designed a user interface the uses the flat xp look for my controls,
but the crazy decision by ms to make the combo box 1 pixel higher than a
text box is really messing up my design.

I really need to adjust the size of this control without having to resort to
creating my own.

I have found a vb api call that solves my problem, but...

1. should i use it.
2. how do i convert it to csharp.
3. could i hold place this code in an inherited combo class componet.

The code is as follows:

Private Declare Auto Function SendMessage Lib "user32.dll" (ByVal hwnd As
IntPtr, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32)
As Int32

Private Sub SetComboEditHeight(ByVal Control As ComboBox, ByVal NewHeight As
Int32)
Const CB_SETITEMHEIGHT As Int32 = &H153
SendMessage(Control.Handle, CB_SETITEMHEIGHT, -1, NewHeight)
Control.Refresh()
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
SetComboEditHeight(Me.ComboBox1, 14)
End Sub
 
J

Jeff Gaines

I've designed a user interface the uses the flat xp look for my
controls, but the crazy decision by ms to make the combo box 1 pixel
higher than a text box is really messing up my design.

I really need to adjust the size of this control without having to
resort to creating my own.

I have found a vb api call that solves my problem, but...

1. should i use it.
2. how do i convert it to csharp.
3. could i hold place this code in an inherited combo class componet.

I wish my eyes were still young enough to notice a 1 pixel height
difference :)

You can turn off AutoSize for the TextBox and set it to any height you
wish.

If that is not a good solution for you then there is no reason not to
use API calls. A good place to check prototypes is www.pinvoke.net, the
following works for SendMessage:

[DllImport("user32.dll", EntryPoint="SendMessage", SetLastError=true,
CallingConvention=CallingConvention.StdCall)]
public static extern int SendMessage(IntPtr hwnd, uint Msg, int wParam,
int lParam);

You can then use it in the same way as the VB version you quoted.

You can also use it in a class inherited from ComboBox.
 
S

Steve Le Monnier

Thanks Jeff

I know it sounds like nit picking but with my flat style design like
Microsoft Great Plains does the non-standard height of the combo box really
stands out when the controls are placed together.

I don't understand why the dam think is 21 pixels in the first place, if you
look at the combo control it doesn't need to be that height and also the
height of the combos in MS Great Plains is only 20, that's why there form
design looks so good.

I'm sure MS do this just to annoy us.

Thanks for the help. I don't want to use an API but it is the less of the
two evils... the other being MS.

Thanks again and have a good xmas.

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top