C# 窗体边角圆弧处理及在C#中调用外部程序(执行批处理,打开窗口等)

时间:2022-01-07 04:57:49

1、窗体边角圆弧处理

在窗体的Paint事件中或者Resize事件中处理这个过程,具体代码如下:

private void SetFormCircle()
        {

            int radian = 4;           //圆弧角的比率,可以自己改变这个值看具体的效果
            int w = this.Width;    //窗体宽
            int h = this.Height;   //窗体高

            //对于矩形的窗体,要在一个角上画个弧度至少需要2个点,所以4个角需要至少8个点

            Point p1 = new Point(radian, 0);
            Point p2 = new Point(w - radian, 0);
            Point p3 = new Point(w, radian);
            Point p4 = new Point(w, h - radian);
            Point p5 = new Point(w - radian, h);
            Point p6 = new Point(radian, h);
            Point p7 = new Point(0, h - radian);
            Point p8 = new Point(0, radian);

            System.Drawing.Drawing2D.GraphicsPath shape = new System.Drawing.Drawing2D.GraphicsPath();

            Point[] p = new Point[] { p1, p2, p3, p4, p5, p6, p7, p8 };
            shape.AddPolygon(p);

            //将窗体的显示区域设为GraphicsPath的实例  
            this.Region = new System.Drawing.Region(shape);

       }

2、c#中调用外部程序

比如要打开一“c:\windows”这个目录,可以这些做

Process.Start("explorer.exe",@"c:\windows");

要执行一个DOS批处理,可以这样做

                    //sPath是批处理文件的路径

                    myProcess.StartInfo.FileName = sPath;
                    myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                    myProcess.StartInfo.Verb = "open";
                    myProcess.StartInfo.CreateNoWindow = false;
                    myProcess.StartInfo.UseShellExecute = false;
                    myProcess.Start();