首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

在label中画一条线如何就画不上呢

2012-02-20 
在label中画一条线怎么就画不上呢代码如下C# codeGraphics g label1.CreateGraphics()Pen p new Pen(

在label中画一条线怎么就画不上呢
代码如下

C# code
Graphics g = label1.CreateGraphics();            Pen p = new Pen(Color.Red, 1);            p.DashStyle = DashStyle.Solid;            g.DrawLine(p, 0, 0, 5, 5);            g.Dispose();
,这么写不可以么?

[解决办法]
把上面的代码写在Label的OnPaint事件应该就没问题了
[解决办法]
C# code
        private void label1_Paint(object sender, PaintEventArgs e)        {            e.Graphics.DrawLine(Pens.Red, new Point(0, 5), new Point(10, 5));        }
[解决办法]
在label的paint事件中完成
private void label1_Paint(object sender, PaintEventArgs e)
{
Pen p = new Pen(Color.Red, 1);
p.DashStyle = DashStyle.Solid;
e.Graphics.DrawLine(p, 0, 0, 5, 5);
e.Dispose();
}
[解决办法]
探讨
在label的paint事件中完成
private void label1_Paint(object sender, PaintEventArgs e)
{
Pen p = new Pen(Color.Red, 1);
p.DashStyle = DashStyle.Solid;
e.Graphics.DrawLine(p, 0, 0, 5, 5);
e.Dispose……

热点排行