controls["labelname"]找到label,修改背景图片 或 protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); BackColor = Color.Transparent; Graphics g = e.Graphics; Pen p = new Pen(Color.Black, 1); Rectangle rect = ClientRectangle; rect.Location = new Point(2, 2); rect.Width = ClientRectangle.Width - 4; rect.Height = ClientRectangle.Height - 4; }重绘
重载Control(可以是窗体,也可以是自定义控件)的OnPaint事件,计算好相应的坐标,调用GDI+进行绘图就好了。protected override void OnPaint(PaintEventArgs e) { e.Graphics.DrawRectange(Colors.Blue,0,0,100,100); //draw a blue rect e.Graphics.DrawString("4010", "宋体" ....... }
e.Graphics.DrawImage();用这个方法可以画图
差不多就是这样了,还需要用到什么吗?
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < 10; i++)
{
dd=new Button();
if (i <= 5)
{
this.dd.Location = new System.Drawing.Point(12, 12 + i * 30); }
else
{
this.dd.Location = new System.Drawing.Point(96, 12 + (i - 5) * 30);
}
this.dd.Name = "button"+i;
this.dd.Size = new System.Drawing.Size(75, 23);
this.dd.TabIndex = i;
this.dd.Text = "button" + i;
this.dd.UseVisualStyleBackColor = true;
this.Controls.Add(dd);
this.dd.Click += new EventHandler(onMessage_Click); }
}
public void onMessage_Click(object sender, EventArgs e)
{
Button but = ((Button)sender);
MessageBox.Show(but.Text);
} 这些代码能生成一些按钮, 这种方法也能生成其他的一些控件。(希望对你有用)至于图片怎样放上去,还不清楚。知道了告诉我
或
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
BackColor = Color.Transparent;
Graphics g = e.Graphics;
Pen p = new Pen(Color.Black, 1);
Rectangle rect = ClientRectangle;
rect.Location = new Point(2, 2);
rect.Width = ClientRectangle.Width - 4;
rect.Height = ClientRectangle.Height - 4;
}重绘
{
e.Graphics.DrawRectange(Colors.Blue,0,0,100,100); //draw a blue rect
e.Graphics.DrawString("4010", "宋体" .......
}
那些小的图标可以调用DrawIcon来绘制
e.Graphics.DrawIcon.其他的你只需要进行条件控制确定相应的颜色、坐标就行了。如果考虑到效率,可以启用双缓冲。SetStyle(ControlStyles.DoubleBuffer).