在创建.NET WinForm的圆角容器 [英] Creating Rounded corner container in .net winform

查看:137
本文介绍了在创建.NET WinForm的圆角容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建在WinForm的.NET圆角容器。我的目标是创建一个容器,这样,如果我放弃其中的任何其他控制,即控制也将成为圆形。

I want to create the rounded corner container in winform .net. My aim is to create a container such that if I dropped any other control within it, that control will also become round shape.

这可能吗?

推荐答案

您正在寻找的<一个href="http://msdn.microsoft.com/en-us/library/system.windows.forms.control.region.aspx"><$c$c>Control.Region物业,它允许你设置与特定控制关联的窗口区域。操作系统不会画或显示躺着一个窗口区域外的窗口的任何部分。

You're looking for the Control.Region property, which allows you to set the window region associated with a particular control. The operating system will not draw or display any portion of a window that lies outside of a window region.

该文件提供了如何使用区域属性来创建一个圆形按钮示例:

The documentation gives a sample of how to use the Region property to create a round button:

// This method will change the square button to a circular button by 
// creating a new circle-shaped GraphicsPath object and setting it 
// to the RoundButton objects region.
private void roundButton_Paint(object sender, PaintEventArgs e)
{
    System.Drawing.Drawing2D.GraphicsPath buttonPath = 
                            new System.Drawing.Drawing2D.GraphicsPath();

    // Set a new rectangle to the same size as the button's 
    // ClientRectangle property.
    System.Drawing.Rectangle newRectangle = roundButton.ClientRectangle;

    // Decrease the size of the rectangle.
    newRectangle.Inflate(-10, -10);

    // Draw the button's border.
    e.Graphics.DrawEllipse(System.Drawing.Pens.Black, newRectangle);

    // Increase the size of the rectangle to include the border.
    newRectangle.Inflate( 1,  1);

    // Create a circle within the new rectangle.
    buttonPath.AddEllipse(newRectangle);

    // Set the button's Region property to the newly created 
    // circle region.
    roundButton.Region = new System.Drawing.Region(buttonPath);
}

这篇关于在创建.NET WinForm的圆角容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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