制作形式疆外用户控制显示 [英] Make user control display outside of form boundry

查看:112
本文介绍了制作形式疆外用户控制显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我决定重新实现的日期时间选择器,作为一个标准的日期时间选择器不能为空。用户希望启动一个空白的领域和类型(不选择)的日期。

I've decided to reimplement the datetime picker, as a standard datetime picker isn't nullable. The user wants to start with a blank field and type (not select) the date.

我创建了一个用户控件做到这一点,但如果用户控件在靠近形式的边缘,这将是对形式疆切断。标准的日期时间选择器不存在这个问题。

I've created a user control to do just that, but if the user control is near the edge of the form, it will be cut off on the form boundry. The standard datetime picker doesn't suffer from this problem.

下面是显示问题的画面。我的用户控件是在左边,标准的DateTimePicker在右边:

Here is a picture showing the problem. My user control is on the left, the standard datetimepicker is on the right:

正如你所看到的,标准的控制将显示在形式和应用疆。我如何获得每月选取器在我的控制做同样的事情?

As you can see, the standard control will display over the form AND application boundry. How do I get the month picker in my control to do the same thing?

谢谢!

推荐答案

该ToolStripDropDown控件还具有以下functionallity所以由它继承我们可以做一个简单的PopupWindow。

The ToolStripDropDown control has this functionallity so by inheriting from it we can make a simple 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);
    }
}



用法:

Usage:

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

这篇关于制作形式疆外用户控制显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆