private void Form1_Paint(object sender, PaintEventArgs e)
{
//随机绘制25个矩形,然后一次性显示在窗口
Bitmap mybt = new Bitmap(this.ClientSize.Width, this.ClientSize.Height);
TextureBrush image = new TextureBrush(Image.FromFile(@"D:\项目代码\C#\WindowsFormsDrawGrid\WindowsFormsDrawGrid\Images\life16.png"));
for (int i = 0; i < 25; i++)
{
x = rnd.Next((this.ClientSize.Width-25) / 15);
y = rnd.Next((this.ClientSize.Height-25) / 15);
e.Graphics.FillRectangle(image, new Rectangle(x * 15, y * 15, 15, 15));
}
this.CreateGraphics().DrawImage(mybt, new Point(0, 0));
}
效果如下:
为什么图片显示的不对,没有居中填充????
{
//随机绘制25个矩形,然后一次性显示在窗口
Bitmap mybt = new Bitmap(this.ClientSize.Width, this.ClientSize.Height);
TextureBrush image = new TextureBrush(Image.FromFile(@"D:\项目代码\C#\WindowsFormsDrawGrid\WindowsFormsDrawGrid\Images\life16.png"));
for (int i = 0; i < 25; i++)
{
x = rnd.Next((this.ClientSize.Width-25) / 15);
y = rnd.Next((this.ClientSize.Height-25) / 15);
e.Graphics.FillRectangle(image, new Rectangle(x * 15, y * 15, 15, 15));
}
this.CreateGraphics().DrawImage(mybt, new Point(0, 0));
}
效果如下:
为什么图片显示的不对,没有居中填充????
解决方案 »
- 打印
- Directory.GetFiles(txtSource.Text) 怎么获取文件对象
- CSDN最后的希望··updata更新access出错,但同样的语句在sql中没问题
- 【。】请教个问题,ie发送乱码了呢?而chrome等浏览器正常的,还有iis正常的,nginx时从log里面发现ie请求的是gb2312的,而其他浏览器....
- winform 滚动条问题
- 求,用C#代码在Excel中画圆圈的方法!(在线等待...)
- 怎样dataGridView绑定代码生成的datatable
- 问个字符串搜索的问题
- 控制台能使用Timer吗?
- 一个关于XML的问题 ..........急、急、急、急、急!!!
- (十万火急)
- listview的操作
你要居中 要把每个(单元格.Width-pic.Width)/2 (单元格.Height-pic.Height)/2 做为左上角的起始点
e.Graphics.FillRectangle(image, new Rectangle((x+1) * 15, (y+1) * 15, 15, 15));