【问题标题】:Draw only corner of a rectangle只画一个矩形的角
【发布时间】:2014-01-04 18:41:54
【问题描述】:

我用过

Pen pen = new Pen(Color.Red);
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;

塑造矩形的边框,但现在我只需要显示该矩形的角。

【问题讨论】:

    标签: c# picturebox rectangles drawrectangle


    【解决方案1】:

    您可以通过Paint 事件处理程序中的DrawLine 函数自己绘制它,如下所示:

    Pen pen = new Pen(Color.Red);
    
    private void Form1_Load(object sender, System.EventArgs e)
    {
        pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint);
    
        pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
    }
    
    private void pictureBox1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
    {
        Graphics g = e.Graphics;
    
        g.DrawLine(pen, 0, 0, pictureBox1.Right, 0);
    
        g.DrawLine(pen, 0, 0, 0, pictureBox1.Bottom);
    }
    

    这是一个用例,也许你需要其他坐标,但你可以很容易地修复它。

    【讨论】:

      【解决方案2】:

      你可以使用 2 行来获得你想要的效果:

          private void MainForm_Paint(object sender, PaintEventArgs e)
          {
              Pen pen = new Pen(Color.Red);
              pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
              e.Graphics.DrawLine(pen, 0, 0, 50, 0 );
              e.Graphics.DrawLine(pen, 0, 0, 0, 50);
          }
      

      这会在表单的左上角绘制一个矩形的角。

      【讨论】:

        猜你喜欢
        • 2016-03-19
        • 2018-10-03
        • 1970-01-01
        • 1970-01-01
        • 2017-03-21
        • 1970-01-01
        • 2019-11-18
        • 1970-01-01
        • 2015-06-19
        相关资源
        最近更新 更多