Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open DateTimePicker C# control programmatically

Tags:

winforms

How can I open the DateTimePicker C# control programmatically? I want to show the Calendar in the Datetime Picker control by sending keys to the control. Is there a way we can do that?

like image 629
Rohit Gupta Avatar asked Mar 11 '10 19:03

Rohit Gupta


1 Answers

Try the following

//part of the usings
using System.Runtime.InteropServices;

//declares
[DllImport("user32.dll")]
private static extern bool PostMessage(
IntPtr hWnd, // handle to destination window
Int32 msg, // message
Int32 wParam, // first message parameter
Int32 lParam // second message parameter
);

const Int32 WM_LBUTTONDOWN = 0x0201;

//method to call dropdown
private void button1_Click(object sender, EventArgs e)
{
    Int32 x = dateTimePicker1.Width - 10;
    Int32 y = dateTimePicker1.Height / 2;
    Int32 lParam = x + y * 0x00010000;

    PostMessage(dateTimePicker1.Handle, WM_LBUTTONDOWN, 1,lParam);

}
like image 57
Adriaan Stander Avatar answered Oct 17 '22 03:10

Adriaan Stander