问题描述:

        项目中用到ComboBox.DropDown事件,来打开DateTimePicker?

代码如下:

 

        private void comboBox1_DropDown(object sender, EventArgs e)
        {
            dateTimePicker1.Focus();
            SendKeys.SendWait("%{DOWN}");
            comboBox1.Items.Add(dateTimePicker1.Value.ToString("dd/MM/yyyy"));
            comboBox1.SelectedIndex=0;
        }

        private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
        {
            comboBox1.Items.Clear();
            comboBox1.Items.Add(dateTimePicker1.Value.ToString("dd/MM/yyyy"));
            comboBox1.SelectedIndex = 0;
        }


或者:

[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;

Int32 x = dateTimePicker1.Width - 10;
Int32 y = dateTimePicker1.Height / 2;
Int32 lParam = x + y * 0x00010000;
PostMessage(dateTimePicker1.Handle, WM_LBUTTONDOWN, 1, lParam);
 

 

相关文章:

  • 2022-01-01
  • 2022-02-19
  • 2021-07-03
  • 2022-02-10
  • 2021-12-29
  • 2022-12-23
猜你喜欢
  • 2021-12-23
  • 2021-11-17
  • 2022-12-23
  • 2022-01-23
  • 2021-09-07
  • 2022-12-23
  • 2021-10-19
相关资源
相似解决方案