Archive Browser
Download GetComboBoxInfoDemo.zip version 1.0.0.0, last updated 29/09/2013 (8.49 KB)
Download- md5: 4fcc1a5a01f589b63820d14e3288db50
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace GetComboBoxInfoDemo
{
// Getting the hWnd of the edit component within a ComboBox contro
// http://cyotek.com/blog/getting-the-hwnd-of-the-edit-component-within-a-combobox-control
public partial class MainForm : Form
{
#region Constructors
public MainForm()
{
InitializeComponent();
}
#endregion
#region Overridden Members
protected override void OnLoad(EventArgs e)
{
object[] words;
base.OnLoad(e);
words = new object[]
{
"Alpha", "Beta", "Gamma", "Delta", "Epsilon", "Zeta", "Eta", "Theta", "Iota", "Kappa", "Lambda", "Mu", "Nu", "Xi", "Omicron", "Pi", "Rho", "Sigma", "Tau", "Upsilon", "Phi", "Chi", "Psi", "Omega"
};
dropDownComboBox.Items.AddRange(words);
dropDownListComboBox.Items.AddRange(words);
simpleComboBox.Items.AddRange(words);
}
#endregion
#region Members
private void GetEditHandle(IWin32Window control)
{
this.ShowComboBoxInfo(control, true);
}
private void GetListHandle(IWin32Window control)
{
this.ShowComboBoxInfo(control, false);
}
private void ShowComboBoxInfo(IWin32Window control, bool showEditHandle)
{
NativeMethods.COMBOBOXINFO info;
info = new NativeMethods.COMBOBOXINFO();
info.cbSize = Marshal.SizeOf(info);
if (NativeMethods.GetComboBoxInfo(control.Handle, ref info))
{
IntPtr handle;
handle = showEditHandle ? info.hwndEdit : info.hwndList;
MessageBox.Show(handle == IntPtr.Zero ? "This control does not support this mode." : string.Format("The requested handle is {0}.", handle), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
MessageBox.Show("Failed to obtain requested information.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
#endregion
#region Event Handlers
private void closeButton_Click(object sender, EventArgs e)
{
this.Close();
}
private void dropDownEditButton_Click(object sender, EventArgs e)
{
this.GetEditHandle(dropDownComboBox);
}
private void dropDownListButton_Click(object sender, EventArgs e)
{
this.GetListHandle(dropDownComboBox);
}
private void dropDownListEditButton_Click(object sender, EventArgs e)
{
this.GetEditHandle(dropDownListComboBox);
}
private void dropDownListListButton_Click(object sender, EventArgs e)
{
this.GetListHandle(dropDownListComboBox);
}
private void simpleEditButton_Click(object sender, EventArgs e)
{
this.GetEditHandle(simpleComboBox);
}
private void simpleListButton_Click(object sender, EventArgs e)
{
this.GetListHandle(simpleComboBox);
}
#endregion
}
}
Donate
This software may be used free of charge, but as with all free software there are costs involved to develop and maintain.
If this site or its services have saved you time, please consider a donation to help with running costs and timely updates.
Donate