我想在我的移动程序(.net cf 3.5)中打开一个组合框,但是紧凑框架中不存在像这样的属性。
访问 WinCE ComboBox DroppedDown 属性 (.NET CF 2.0)
但我不想获取当前状态,而是要设置它。我应该怎么做呢?
使用CB_SHOWDROPDOWN = 0x014F
消息:
public const int CB_GETDROPPEDSTATE = 0x0157;
public static bool GetDroppedDown(ComboBox comboBox)
{
Message comboBoxDroppedMsg = Message.Create(comboBox.Handle, CB_GETDROPPEDSTATE, IntPtr.Zero, IntPtr.Zero);
MessageWindow.SendMessage(ref comboBoxDroppedMsg);
return comboBoxDroppedMsg.Result != IntPtr.Zero;
}
public const int CB_SHOWDROPDOWN = 0x014F;
public static bool ToogleDropDown(ComboBox comboBox)
{
int expand = GetDroppedDown(comboBox) ? 0 : 1;
int size = Marshal.SizeOf(new Int32());
IntPtr pBool = Marshal.AllocHGlobal(size);
Marshal.WriteInt32(pBool, 0, expand); // last parameter 0 (FALSE), 1 (TRUE)
Message comboBoxDroppedMsg = Message.Create(comboBox.Handle, CB_SHOWDROPDOWN, pBool, IntPtr.Zero);
MessageWindow.SendMessage(ref comboBoxDroppedMsg);
Marshal.FreeHGlobal(pBool);
return comboBoxDroppedMsg.Result != IntPtr.Zero;
}
const int CB_SHOWDROPDOWN = 0x14F
作为你的消息。Message.Create(comboBox.Handle, CB_SHOWDROPDOWN , (IntPtr)1, IntPtr.Zero); // to open
Message.Create(comboBox.Handle, CB_SHOWDROPDOWN , (IntPtr)0, IntPtr.Zero); // to close
稍微改进了一点:
public bool ToogleDropDown()
{
int expand = GetDroppedDown() ? 0 : 1;
//int size = Marshal.SizeOf(new Int32());
//IntPtr pBool = Marshal.AllocHGlobal(size);
//Marshal.WriteInt32(pBool, 0, expand); // last parameter 0 (FALSE), 1 (TRUE)
Message comboBoxDroppedMsg = Message.Create(this.Handle, CB_SHOWDROPDOWN, (IntPtr)expand, IntPtr.Zero);
MessageWindow.SendMessage(ref comboBoxDroppedMsg);
//Marshal.FreeHGlobal(pBool);
return comboBoxDroppedMsg.Result != IntPtr.Zero;
}