日期:2014-05-20  浏览次数:20697 次

在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……