This code shows how we can use combobox in our winforms application using c#.
public partial class frmComboBox_Demo : Form { public frmComboBox_Demo() { InitializeComponent(); comboBox1.Items.Add("Item 4"); comboBox1.Items.Add("Item 5"); comboBox1.Items.Add("Item 6"); comboBox1.SelectedIndex = 2; } private void button1_Click(object sender, EventArgs e) { MessageBox.Show("Selected text of combobox is: " + comboBox1.SelectedText); MessageBox.Show("Text of combobox is: " + comboBox1.Text); } private void button2_Click(object sender, EventArgs e) { comboBox1.Focus(); MessageBox.Show("Selected text of combobox is: " + comboBox1.SelectedText); MessageBox.Show("Text of combobox is: " + comboBox1.Text); } }
public class NativeMethods {
[System.Runtime.InteropServices.DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")]
public static extern System.IntPtr CreateRoundRectRgn
(
int nLeftRect, // x-coordinate of upper-left corner
int nTopRect, // y-coordinate of upper-left corner
int nRightRect, // x-coordinate of lower-right corner
int nBottomRect, // y-coordinate of lower-right corner
int nWidthEllipse, // height of ellipse
int nHeightEllipse // width of ellipse
);
[System.Runtime.InteropServices.DllImport("gdi32.dll", EntryPoint = "DeleteObject")]
public static extern bool DeleteObject(System.IntPtr hObject);
[System.Runtime.InteropServices.DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture();
[System.Runtime.InteropServices.DllImportAttribute("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam); }