我正在实现对表单控件进行子类化的自定义行为,但我无法访问ComboBox的DroppedDown属性。在帮助中,它应该在CF.NET 2.0中得到支持:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace xCustomControls
{
public partial class xComboBox : System.Windows.Forms.ComboBox
{
private ComboBox comboBox1;
public xComboBox()
{
InitializeComponent();
this.KeyDown += new KeyEventHandler(this.KeyDownHandler);
}
private void KeyDownHandler(object sender, KeyEventArgs e)
{
// DroppedDown doesn't appear in the IntelliSense of ComboBox.
// or this.comboBox1.
if (((ComboBox)sender).DroppedDown) // fail!
return;
switch (e.KeyData)
{
case Keys.Up:
case Keys.Enter:
case Keys.Down:
e.Handled = true;
this.Parent.SelectNextControl((Control)sender, e.KeyData != Keys.Up, true, true, true);
...
失败,'System.Windows.Forms.ComboBox'不包含'DroppedDown'的定义,也没有扩展方法'DroppedDown'接受类型'System.Windows.Forms.ComboBox'的第一个参数可以找到
我如何进入酒店?
TIA, 巴勃罗
答案 0 :(得分:1)
DroppedDown
属性不在紧凑框架中,但你可以使用这样的东西:
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;
}
取自:http://msdn.microsoft.com/en-us/netframework/bb735847.aspx