我想在移動程序(.net cf 3.5)上從我的程序打開一個組合框。.NET CF set'DroppedDown'for combobox
但在緊湊的框架不存在的屬性一樣cmbBox.DroppedDown
Accesing WinCE ComboBox DroppedDown property (.NET CF 2.0) 但我不希望得到的當前狀態,但將其設置。
我該如何執行此操作?
我想在移動程序(.net cf 3.5)上從我的程序打開一個組合框。.NET CF set'DroppedDown'for combobox
但在緊湊的框架不存在的屬性一樣cmbBox.DroppedDown
Accesing WinCE ComboBox DroppedDown property (.NET CF 2.0) 但我不希望得到的當前狀態,但將其設置。
我該如何執行此操作?
您可以採用與參考文章中相同的方法併發送消息。
而不是使用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
使用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;
}
它的工作原理!謝謝。 – hellboy 2013-09-24 10:16:44
一點更加改進:
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;
}
剛編輯以添加所需投 – tcarvin 2013-03-15 15:57:16
我應該在哪裏放置這段代碼才能生效?我在combobox.SelectIndex = 0後將此代碼放入MyForm_Load事件中; combobox.Focus();而這段代碼沒有任何作用。 – hellboy 2013-09-24 09:10:55
上面的代碼片段是使被引用文章(問題中的文章)執行所需行爲所需的修改。你也需要檢查一下。 – tcarvin 2013-09-24 12:42:27