c# - 只绘制矩形的角

标签 c# picturebox rectangles drawrectangle

我用过

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

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

最佳答案

可以通过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);
}

这是一个用例,也许您需要其他坐标,但您可以轻松修复它。

关于c# - 只绘制矩形的角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20626766/

相关文章:

c# - 在具有外部Visual Studio版本的Windows(2017)上,无法为PC Standalone生成Unity5项目

c# - 尝试在 c# 中为电路板创建数组中的图片框网格

javascript - 算法 - 给定所有其他矩形的 x Axis 和 y Axis ,定位足够的空间来绘制一个矩形

c# - 垂直六角网格 : Get x rings of tiles surrounding a specific coordinate

c# - 在C#中将AM/PM时间转换为标准时间格式hh:mm

c# - 将图像从 Url 异步加载到 PictureBox

python - 如何将一组重叠范围划分为非重叠范围?

python - 如何测试区域是否重叠 (Python)

c# - 如何使用 WPF 在 C#.NET 中访问 MySql 数据库?

c# - 如何在 C# 中放大和缩小图像?