DropDown

  • Thread starter Thread starter Claudio
  • Start date Start date
C

Claudio

I have a form with two buttons (b1 and b2), a datetimepicker and a combobox.
Is there a way to when a press b1 button the datetimepicker drops down, and
whe I press b2 the combobox drops down ?
 
The DateTimePicker will display it's calendar when it receives an F4
keypress. So you can simulate this by setting focus to the DateTimePicker
and then sending it an F4.

private void button1_Click(object sender, System.EventArgs e)
{
this.dateTimePicker1.Focus();
SendKeys.Send("{F4}");
}
 
I should have pointed out that this is a simple method that will work as
long as the F4 key is not being used as a shortcut to something else, like a
menu item. If this is the case then you could always PInvoke SendMessage and
send the message directly to the control.

using System.Runtime.InteropServices;

private const int WM_KEYDOWN = 0x0100;
private const int VK_F4 = 0x73;

[DllImport("User32.dll")]
private static extern int SendMessage(IntPtr hWnd, int iMsg, int wParam, int
lParam);

private void button1_Click(object sender, System.EventArgs e)
{
this.dateTimePicker1.Focus();
SendMessage(this.dateTimePicker1.Handle, WM_KEYDOWN, VK_F4, 0);
}
 
Or you can send it an Alt+Down key instead
this.dateTimePicker1.Focus();
SendKeys.Send("%{DOWN}");

/claes


Tim Wilson said:
I should have pointed out that this is a simple method that will work as
long as the F4 key is not being used as a shortcut to something else, like a
menu item. If this is the case then you could always PInvoke SendMessage and
send the message directly to the control.

using System.Runtime.InteropServices;

private const int WM_KEYDOWN = 0x0100;
private const int VK_F4 = 0x73;

[DllImport("User32.dll")]
private static extern int SendMessage(IntPtr hWnd, int iMsg, int wParam, int
lParam);

private void button1_Click(object sender, System.EventArgs e)
{
this.dateTimePicker1.Focus();
SendMessage(this.dateTimePicker1.Handle, WM_KEYDOWN, VK_F4, 0);
}

--
Tim Wilson
.Net Compact Framework MVP
{cf147fdf-893d-4a88-b258-22f68a3dbc6a}
Tim Wilson said:
The DateTimePicker will display it's calendar when it receives an F4
keypress. So you can simulate this by setting focus to the DateTimePicker
and then sending it an F4.

private void button1_Click(object sender, System.EventArgs e)
{
this.dateTimePicker1.Focus();
SendKeys.Send("{F4}");
}
 
Back
Top