gpt4 book ai didi

c# - 使用户控件显示在窗体边界之外

转载 作者:可可西里 更新时间:2023-11-01 07:51:42 28 4
gpt4 key购买 nike

我决定重新实现日期时间选择器,因为标准日期时间选择器不可为空。用户希望从空白字段开始并键入(而不是选择)日期。

我已经创建了一个用户控件来执行此操作,但是如果用户控件靠近窗体的边缘,它将在窗体边界上被切断。标准日期时间选择器不会遇到此问题。

这是显示问题的图片。我的用户控件在左边,标准的日期时间选择器在右边:

alt text http://img50.imageshack.us/img50/9104/datetimepickervu6.jpg

如您所见,标准控件将显示在窗体和应用程序边界上。如何让我控制的月份选择器执行相同的操作?

谢谢!

最佳答案

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);
}
}

用法:

PopupWindow popup = new PopupWindow(MyControlToHost);
popup.Show(new Point(100,100));
...
popup.Close();

关于c# - 使用户控件显示在窗体边界之外,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/280891/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com