I created a custom label control, I try to draw lines on it.
after I draw it on form, it doesn't repaint the area after resize it...
My Code -:
using System.Drawing;
using System.Windows.Forms;
namespace SevenSegmentDigit
{
public partial class DigitDisplay : Label
{
Graphics grx;
Pen roundPen;
public DigitDisplay()
{
InitializeComponent();
SetAutoSizeMode(AutoSizeMode.GrowAndShrink);
this.ResizeRedraw = true;
AutoSize = false;
grx = this.CreateGraphics();
roundPen = new Pen(Brushes.Black, 2);
roundPen.StartCap = System.Drawing.Drawing2D.LineCap.Round;
roundPen.EndCap = System.Drawing.Drawing2D.LineCap.Round;
}
protected override void OnPaint(PaintEventArgs pe)
{
showDigit();
base.OnPaint(pe);
}
protected override void OnSizeChanged(System.EventArgs e)
{
showDigit();
Invalidate();
}
protected override void OnResize(System.EventArgs e)
{
showDigit();
Invalidate();
}
private void showDigit()
{
grx.Clear(this.BackColor);
switch (digitValue)
{
case 1:
drawOne();
break;
case 2:
drawTwo();
break;
};
}
private int digitValue = 0;
public int DisplayDigit
{
get { return digitValue; }
set { digitValue = value; showDigit(); }
}
private void drawOne()
{
grx.DrawLine(roundPen, 30, 10, 30, 24);
grx.DrawLine(roundPen, 30, 26, 30, 40);
}
private void drawTwo()
{
grx.DrawLine(roundPen, 14, 10, 29, 10);
grx.DrawLine(roundPen, 30, 10, 30, 24);
grx.DrawLine(roundPen, 14, 25, 29, 25);
grx.DrawLine(roundPen, 14, 26, 14, 40);
grx.DrawLine(roundPen, 14, 41, 29, 41);
}
}
}
but it show the same result... :-(
thanks in advance..