用以下代码绘出的网格出现了畸变

shijies 2021-04-18 10:57:18
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{

Graphics g = pictureBox1.CreateGraphics();
Pen bluePen = new Pen(Color.Blue, 3);

for (int i = 0; i < this.pictureBox1.Width; i++)
{
;
g.DrawLine(bluePen, new Point(i, 0), new Point(i, this.pictureBox1.Height));
i += 60;
}

for (int j = 0; j < this.pictureBox1.Height; j++)
{
g.DrawLine(bluePen, new Point(0, j), new Point(this.pictureBox1.Width, j));
j += (this.pictureBox1.Height - 6) / 10;
}

}
}
}

我怎么感觉画出的线在有些地方长了,有些地方没有对齐。
...全文
152 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
爱喝茶的助手 2021-04-19
  • 打赏
  • 举报
回复
要把线的粗度考虑进去,绘制(x=0,y=Height)和(x=Width,y=0)的时候线只会显示一半 而且也没必要写两个for吧

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧