萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> 編程語言綜合 >> 解析C#中如何把控件的邊框角畫為圓弧

解析C#中如何把控件的邊框角畫為圓弧

以下是對C#中把控件的邊框角畫為圓弧的實現代碼進行了介紹,需要的朋友可以參考下   復制代碼 代碼如下:
private void Draw(Graphics graphics, Control control)
        {
            float X = float.Parse(control.Width.ToString()) - 1;
            float Y = float.Parse(control.Height.ToString()) - 1;
            PointF[] pointfs = {
                new PointF(2,     0),
                new PointF(X-2,   0),
                new PointF(X-1,   1),
                new PointF(X,     2),
                new PointF(X,     Y-2),
                new PointF(X-1,   Y-1),
                new PointF(X-2,   Y),
                new PointF(2,     Y),
                new PointF(1,     Y-1),
                new PointF(0,     Y-2),
                new PointF(0,     2),
                new PointF(1,     1)
                };

            GraphicsPath path = new GraphicsPath();
            path.AddLines(pointfs);

            Pen pen = new Pen(Color.FromArgb(150, Color.Blue), 1);
            pen.DashStyle = DashStyle.Solid;
            graphics.DrawPath(pen, path);
        }


首先要把控件注冊一個事件:控件名稱.Paint+=事件名稱,然後把以上函數進行傳參,如:Draw(e.Graphics, this.control);

copyright © 萬盛學電腦網 all rights reserved