ctrl.Paint += new PaintEventHandler(ctrl_Paint); private void ctrl_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { Image img = this.Icon.ToBitmap(); switch(this.index) { case "平铺" : e.Graphics.DrawImage(img, new Rectangle(0,0,this.Width-1,this.Height-1)); break; case "层叠" : for(int i=0; i<=this.Width / img.Width; i++) for(int j=0; j<=this.Height/img.Height; j++) e.Graphics.DrawImage(img, new Point(i*img.Width, j*img.Height)); break; case "居中" : e.Graphics.DrawImage(img, new Point((this.Width-img.Width)/2, (this.Height-img.Height)/2)); break; } }关键就是上台这两短,谁会啊
你可以这样。 估计你的ctrl是个panel吧。vb.net里,支持事件的静态绑定。你可以先画好控件,然后双击panel,就可以直接编写paint事件了。 翻译如下; dim img as new Image(this.Icon.ToBitmap()) select case this.index case "平铺" e.Graphics.DrawImage(img, new Rectangle(0,0,this.Width-1,this.Height-1)) case "层叠" dim i,j as int32 for i=0 to i<=this.Width / img.Width for j=0 to j<=this.Height/img.Height next next e.Graphics.DrawImage(img, new Point(i*img.Width, j*img.Height)) case "居中" e.Graphics.DrawImage(img, new Point((this.Width-img.Width)/2, (this.Height-img.Height)/2)); end select
private void ctrl_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Image img = this.Icon.ToBitmap(); switch(this.index)
{
case "平铺" :
e.Graphics.DrawImage(img, new Rectangle(0,0,this.Width-1,this.Height-1));
break;
case "层叠" :
for(int i=0; i<=this.Width / img.Width; i++)
for(int j=0; j<=this.Height/img.Height; j++)
e.Graphics.DrawImage(img, new Point(i*img.Width, j*img.Height));
break;
case "居中" :
e.Graphics.DrawImage(img, new Point((this.Width-img.Width)/2, (this.Height-img.Height)/2));
break;
}
}关键就是上台这两短,谁会啊
估计你的ctrl是个panel吧。vb.net里,支持事件的静态绑定。你可以先画好控件,然后双击panel,就可以直接编写paint事件了。
翻译如下;
dim img as new Image(this.Icon.ToBitmap())
select case this.index
case "平铺"
e.Graphics.DrawImage(img, new Rectangle(0,0,this.Width-1,this.Height-1))
case "层叠"
dim i,j as int32
for i=0 to i<=this.Width / img.Width
for j=0 to j<=this.Height/img.Height
next
next
e.Graphics.DrawImage(img, new Point(i*img.Width, j*img.Height))
case "居中"
e.Graphics.DrawImage(img, new Point((this.Width-img.Width)/2, (this.Height-img.Height)/2));
end select