本文介绍了以编程方式打开 DateTimePicker C# 控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何打开 DateTimePicker 以编程方式进行 C# 控制?我想通过向控件发送键来在日期时间选择器控件中显示日历.有没有办法做到这一点?
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?
推荐答案
请尝试以下操作
//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);
}
这篇关于以编程方式打开 DateTimePicker C# 控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!