DateTimePicker怎么用代码打开(关闭)下拉日历?
怎样用代码打开和关闭DateTimePicker的下拉日历啊?
[解决办法]
日历下拉实际上是日历数据内容显示在一个div,点击的时候show这个div,点击到其他地方时就close这个div,你需要用js去控件show()和close(),而不是.cs代码去控制
[解决办法]
DateTimePicker1.Focus()
My.Computer.Keyboard.SendKeys("%{DOWN}")
[解决办法]
新建一个类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication1
{
class MyDtPicker : DateTimePicker
{
[DllImport("user32.dll", EntryPoint = "SendMessage")]
static extern int SendMessage(
int hwnd,
int wMsg,
int wParam,
int lParam
);
const int WM_LBUTTONDOWN = 0x201;
const int WM_LBUTTONUP = 0x202;
public void PreformClick()
{
int lparam = (this.ClientRectangle.Width - 10) + (this.ClientRectangle.Height - 10) * 65536;
SendMessage(this.Handle.ToInt32(), WM_LBUTTONDOWN, 0, lparam);
SendMessage(this.Handle.ToInt32(), WM_LBUTTONUP, 0, lparam);
}
}
}