我决定重新实现日期时间选择器,因为标准的日期时间选择器不可为空.用户想要以空白字段开头并键入(而不是选择)日期.
我已经创建了一个用户控件来做这件事,但是如果用户控件靠近表单的边缘,它将在表单边界上被切断.标准日期时间选择器不会遇到此问题.
这是一张显示问题的图片.我的用户控件在左侧,标准的datetimepicker在右侧:
替代文字http://img50.imageshack.us/img50/9104/datetimepickervu6.jpg
如您所见,标准控件将显示在表单和应用程序边界上.如何让我的控制中的月份选择器做同样的事情?
谢谢!
Jes*_*alm 25
ToolStripDropDown控件具有此功能,因此通过继承它,我们可以创建一个简单的PopupWindow.
/// <summary>
/// A simple popup window that can host any System.Windows.Forms.Control
/// </summary>
public class PopupWindow : System.Windows.Forms.ToolStripDropDown
{
private System.Windows.Forms.Control _content;
private System.Windows.Forms.ToolStripControlHost _host;
public PopupWindow(System.Windows.Forms.Control content)
{
//Basic setup...
this.AutoSize = false;
this.DoubleBuffered = true;
this.ResizeRedraw = true;
this._content = content;
this._host = new System.Windows.Forms.ToolStripControlHost(content);
//Positioning and Sizing
this.MinimumSize = content.MinimumSize;
this.MaximumSize = content.Size;
this.Size = content.Size;
content.Location = Point.Empty;
//Add the host to the list
this.Items.Add(this._host);
}
}
Run Code Online (Sandbox Code Playgroud)
用法:
PopupWindow popup = new PopupWindow(MyControlToHost);
popup.Show(new Point(100,100));
...
popup.Close();
Run Code Online (Sandbox Code Playgroud)