日期:2014-05-18  浏览次数:20837 次

小女子,求助,急急,30分 winform monthCalendar可见性的问题
下面这行代码,能实现鼠标在其他任何地方点击,能关闭monthCalendar这个控件,但是 点击 上一个月 下一个月 按钮时,monthCalendar控件 关闭了我要的是显示,不能关闭。因为这样的话,我的在点击一下文本框才能显示日期 

public partial class Form1 : Form, IMessageFilter
  {

  public Form1()
  {
  InitializeComponent();
  Application.AddMessageFilter(this);

  }
  public bool PreFilterMessage(ref Message m)
  {
  if (monthCalendar1.Visible)
  {
  if (m.Msg >= 0x0201 && m.Msg <= 0x0209)
  {
  monthCalendar1.Visible = false;
  }
  }

  if (monthCalendar2.Visible)
  {
  if (m.Msg >= 0x0201 && m.Msg <= 0x0209)
  {
  monthCalendar2.Visible = false;
  }
  }

  return false;
  }

------解决方案--------------------
这个多半应该判断鼠标点击的位置是否在控件区域内,在就不隐藏,不在就隐藏
------解决方案--------------------
C# code

if (m.Msg >= 0x0201 && m.Msg <= 0x0209)
{
    Point pMouse = this.PointToClient(MousePosition);
    Point pCalendar = monthCalendar1.Location;
    if (!(pMouse.X > pCalendar.X && pMouse.X < (pCalendar.X + monthCalendar1.Width) && pMouse.Y > pCalendar.Y && pMouse.Y < (pCalendar.Y + monthCalendar1.Height)))
    {
        monthCalendar1.Visible = false;
    }
}