如果您想查看代码,我将在此处发布最好的代码,虽然不完整但可以帮助您入门:
[DllImport("user32")]
private static extern int GetComboBoxInfo(IntPtr hwnd, out COMBOBOXINFO comboInfo);
[DllImport("user32")]
private static extern int GetWindowRect(IntPtr hwnd, out RECT rect);
[DllImport("user32")]
private static extern int MoveWindow(IntPtr hwnd, int x, int y, int width, int height);
struct RECT
{
public int left, top, right, bottom;
}
struct COMBOBOXINFO
{
public int cbSize;
public RECT rcItem;
public RECT rcButton;
public int stateButton;
public IntPtr hwndCombo;
public IntPtr hwndItem;
public IntPtr hwndList;//This is the Handle of the drop-down list, the one we care here.
}
COMBOBOXINFO comboInfo = new COMBOBOXINFO();
comboInfo.cbSize = Marshal.SizeOf(comboInfo);//Set the size needed to hold the data of the drop-down list Handle
GetComboBoxInfo(comboBox.Handle, out comboInfo);//Get the Handle of the drop-down list of the combobox and pass out to comboInfo
//You use the MoveWindow() function to change the position and size of a window via its Handle.
//show the drop-down list
comboBox.DroppedDown = true;
//You use the GetWindowRect() to get the RECT of a window via its Handle
//this method just sets the new Width for a window
private void SetWidth(IntPtr hwnd, int newWidth){
RECT rect;
GetWindowRect(hwnd, out rect);
MoveWindow(hwnd, rect.left, rect.top, newWidth, rect.bottom-rect.top);
}
//Test on a drop-down list of a combobox
SetWidth(comboInfo.hwndList, 400);
//....
//Your problem is change the Height not the Width of the drop-down list of a combobox
//You have to notice that when the drop-down list is really dropped down, you will have to set new Height for the drop-down list only. However if it is popped-up, you will have to set new Height and calculate the new `Top` of the drop-down list to move the drop-down list accordingly. I've tested successfully.