首页 > 编程 > C# > 正文

C#画笔的用法

2023-05-14 16:26:33
字体:
来源:转载
供稿:网友

本文演示了在C#中使用画笔的源代码,供大家参考使用。下面的源代码中首先定义了一个矩形类(Rectangle),这个类从Shape类中派生出来,在类中定义了两个变量成员来代表画笔的起点和终点。

public class Rectangle : Shape
{
        protected Point m_Start; 
        protected Point m_End; 
        public Rectangle(Point start, Point end, Color fgColor) 
        { 
                m_Start = start; 
                m_End = end; 
                m_Color = fgColor; 
        } 
        public override void Draw(Form canvas) 
        { 
                if (canvas == null) 
                { 
                        return; 
                } 
                InitializeGraphics(canvas); 
                Point startPoint = canvas.PointToScreen(m_Start); 
                Point endPoint = canvas.PointToScreen(m_End); 
                MainForm mainForm = (MainForm)canvas; 
                Color bgColor = GetBackgroundColor(m_Color); 
                Size rectSize = new Size(m_End.X - m_Start.X, m_End.Y - m_Start.Y); 
                System.Drawing.Rectangle rectToDraw = new System.Drawing.Rectangle(startPoint, rectSize); 
                ControlPaint.DrawReversibleFrame(rectToDraw, bgColor, FrameStyle.Thick); 
        }
}

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表