gpt4 book ai didi

winforms - 以编程方式打开 DateTimePicker C# 控件

转载 作者:行者123 更新时间:2023-12-03 05:19:34 26 4
gpt4 key购买 nike

如何打开 DateTimePicker C# 以编程方式控制?我想通过向控件发送按键来在日期时间选择器控件中显示日历。我们有办法做到这一点吗?

最佳答案

尝试以下操作

//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);

}

关于winforms - 以编程方式打开 DateTimePicker C# 控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2427962/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com