返回首页

我怎样才能改变这种代码以绘制一个圆角矩形


public partial class MikePainter : Form

{

   private Bitmap PicInMemory;

   private Graphics PaintOnMyPic;

 

   private int SecondX;   

   private int SecondY;

 

   public MikePainter()

   {

       InitializeComponent();

 

       PicInMemory = new Bitmap(panel1.Width, panel1.Height);

       Graphics PaintOnMyPic = Graphics.FromImage(PicInMemory);

 

///////////How to change this code to draw rounded rectangle////////////////



private void OnMouseMove(object sender, MouseEventArgs e)

{

  if (Selectedtool == Rect ) --> Check if the selectTool is rect 

  {

    Pen myPen = new Pen(Color.Black);

    Graphics PaintOnPanel = panel1.CreateGraphics();

    PaintOnPanel.DrawImage(PicInMemory, 0, 0);

    PaintOnPanel.DrawRectangle(myPen, SecondX,SecondY,e.X - SecondX,e.Y - SecondY);

  }

}

 

private void OnMouseUp(object sender, MouseEventArgs e)

{

  if (Selectedtool == Rect )

  {

    Graphics PaintOnPic = Graphics.FromImage(PicInMemory); 

    Pen myPen = new Pen(Color.Black);

    PaintOnPic.DrawRectangle(myPen, SecondX, SecondY, e.X - SecondX, e.Y - SecondY);

    Graphics PaintOnPanel = panel1.CreateGraphics();

    PaintOnPanel.DrawImage(PicInMemory, 0, 0);

  }

}

 

private void OnMouseDown(object sender, MouseEventArgs e)

{

   SecondX = e.X;

   SecondY = e.Y;

}

回答

评论会员:O 时间:2