none
请问,WinForm中的“Region”属性怎么用?如果我想将窗体变成圆角矩形,那么这个Region应该怎么设置呢? RRS feed

  • 问题

  • 看MSDN文档说明如下:

                RegionData data = new RegionData();

                data.Data="二进制数据"?(怎么设置这些数据啊?)

                this.Region = new Region(data);

    假如我想将窗体变成圆角矩形的外观,那么这个Region的Data应该怎么初始化?


    da jia hao!

    2015年2月14日 14:54

答案

  • 你好:

    参考这段代码:

    using System;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            [DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")]
            private static extern IntPtr CreateRoundRectRgn
            (
                int nLeftRect, // x-coordinate of upper-left corner
                int nTopRect, // y-coordinate of upper-left corner
                int nRightRect, // x-coordinate of lower-right corner
                int nBottomRect, // y-coordinate of lower-right corner
                int nWidthEllipse, // height of ellipse
                int nHeightEllipse // width of ellipse
             );
    
            public Form1()
            {
                InitializeComponent();
                this.FormBorderStyle = FormBorderStyle.None;
                Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(0, 0, Width, Height, 20, 20));
            }
        }
    }


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • 已标记为答案 liubin 2015年2月24日 16:12
    2015年2月23日 6:58
    版主