c# 如何实现 类似PS里的画图板背景功能? 就像下图一样:写代码实现,而不是加个背景图片。谢谢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 就用Graphics,一个for循环就搞定. 绘制?这是一个在PictureBox控件上绘制的代码 pictureBox1.Image = new Bitmap(400, 400); Graphics gr = Graphics.FromImage(pictureBox1.Image); bool IsWhite = true; for(int h=0;h<400;h+=10) for (int w = 0; w < 400; w += 10) { if (IsWhite) { gr.FillRectangle(Brushes.White, new Rectangle(new Point(w, h), new Size(10, 10))); IsWhite = false; } else { gr.FillRectangle(Brushes.Gray, new Rectangle(new Point(w, h), new Size(10, 10))); IsWhite = true; } } gr.Dispose(); private void Form1_Load(object sender, EventArgs e) { pictureBox1.Image = new Bitmap(400,400); Graphics gr = Graphics.FromImage(pictureBox1.Image); bool IsWhite = true; for (int h = 0; h < 400; h += 10) { if ((h / 10) % 2 == 0) { IsWhite = false; } else { IsWhite = true; } for (int w = 0; w < 400; w += 10) { if (IsWhite) { gr.FillRectangle(Brushes.White, new Rectangle(new Point(w, h), new Size(10, 10))); IsWhite = false; } else { gr.FillRectangle(Brushes.Gray, new Rectangle(new Point(w, h), new Size(10, 10))); IsWhite = true; } } } 就用Graphics,一个for循环就搞定. TransactionScope问题 矩形中心点旋转后,四个点新的坐标值 菜鸟求救:电梯向上下的优先判断 [WPF]ListView 如何添加一行数据 c#中的DataGridView更新问题,急等! 今天买了本《C#技术内幕》立志学好C# 在线等待C#的web打印例子 求解:基于流输入错误 GPRS/GPG/GIS 如何置空pictureBox->急 C/S结构的程序如何实现客户端与服务端的通信 PageSetupDialog 自定义纸张问题
这是一个在PictureBox控件上绘制的代码
pictureBox1.Image = new Bitmap(400, 400);
Graphics gr = Graphics.FromImage(pictureBox1.Image);
bool IsWhite = true;
for(int h=0;h<400;h+=10)
for (int w = 0; w < 400; w += 10)
{
if (IsWhite)
{
gr.FillRectangle(Brushes.White, new Rectangle(new Point(w, h), new Size(10, 10)));
IsWhite = false;
}
else
{
gr.FillRectangle(Brushes.Gray, new Rectangle(new Point(w, h), new Size(10, 10)));
IsWhite = true;
}
}
gr.Dispose();
{
pictureBox1.Image = new Bitmap(400,400);
Graphics gr = Graphics.FromImage(pictureBox1.Image);
bool IsWhite = true;
for (int h = 0; h < 400; h += 10)
{
if ((h / 10) % 2 == 0)
{
IsWhite = false;
}
else
{
IsWhite = true;
}
for (int w = 0; w < 400; w += 10)
{
if (IsWhite)
{
gr.FillRectangle(Brushes.White, new Rectangle(new Point(w, h), new Size(10, 10)));
IsWhite = false; }
else
{
gr.FillRectangle(Brushes.Gray, new Rectangle(new Point(w, h), new Size(10, 10)));
IsWhite = true; }
}
}