简体   繁体   中英

Opening a dateTimePicker using a PictureBox

Is there any way to open a dateTimePicker using a PictureBox in c# windowsform? I wanted to minimize the dateTimePicker size so it can only show the drop down arrow and the calendar picture but thats not possible, so now i want to open the calendar using a PictureBox, is that possible? Thanks

Although it is not possible to programatically show picker in DateTimePicker, you can create your own this way:

[ToolboxItem(true)]
public class CustomDateTimePicker : DateTimePicker
{
    private const int WM_KEYDOWN = 0x100;
    private const int VK_F4 = 0x73;
    private const int F4_KEYDOWN_LPARAM = 0x003e0001;

    public void ShowPicker()
    {
        Focus();
        var m = Message.Create(Handle, WM_KEYDOWN, new IntPtr(VK_F4), new IntPtr(F4_KEYDOWN_LPARAM));
        WndProc(ref m);
    }
}

Than in Click handler of your picture box just call that ShowPicker method.

private void PictureBox1_Click(object sender, EventArgs e)
{
    customDateTimePicker1.ShowPicker();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM