private int lineSepra; [DefaultValue("Multiline"), Description("控制编辑控件的文本是否可以跨越多行。"), Category("Appearance")]
private int _Percent;
public int Percent
{
get
{
return _Percent;
}
set
{
_Percent = value;
}
}
public UserControl1()
{
InitializeComponent();
} private void UserControl1_Paint(object sender, PaintEventArgs e)
{
//Invalidate();
//lineSepra = (this.Height * 2)/10;
DrawText();
DrawRect();
} private void DrawText()
{
Graphics theGraphics = Graphics.FromHwnd(this.Handle);
StringFormat format = new StringFormat(); format.LineAlignment = StringAlignment.Center;
format.Alignment = StringAlignment.Center;
string str = "%";
str = str + System.Convert.ToString(this._Percent);
theGraphics.DrawString(str, this.Font,new SolidBrush(this.ForeColor), new Rectangle(0,this.Height-lineSepra,this.Width,this.Height),format);
} private void DrawRect()
{
Graphics theGraphics = Graphics.FromHwnd(this.Handle); Pen blackPen = new Pen(Color.Red, 2);
Rectangle rect = new Rectangle(0, 0, this.Width, this.Height - lineSepra);
// Draw rectangle to screen
theGraphics.DrawRectangle(blackPen, rect);
} private void UserControl1_SizeChanged(object sender, EventArgs e)
{
Invalidate();
lineSepra = (this.Height * 2) / 10;
DrawText();
DrawRect();
} private void UserControl1_Load(object sender, EventArgs e)
{
lineSepra = (this.Height * 2)/10;
this._Percent = 0;
this.BackColor = System.Drawing.Color.Lavender;
} private void UserControl1_AutoSizeChanged(object sender, EventArgs e)
{
Invalidate();
lineSepra = (this.Height * 2) / 10;
DrawText();
DrawRect();
}这是一个自定义控件.我在引入在别的工程后,改变大小的时候.界面上显示的没有改变.当工程运行时显示的是改变的.还有就是我那句画的文字没有显示出来.帮帮忙.谢
private int _Percent;
public int Percent
{
get
{
return _Percent;
}
set
{
_Percent = value;
}
}
public UserControl1()
{
InitializeComponent();
} private void UserControl1_Paint(object sender, PaintEventArgs e)
{
//Invalidate();
//lineSepra = (this.Height * 2)/10;
DrawText();
DrawRect();
} private void DrawText()
{
Graphics theGraphics = Graphics.FromHwnd(this.Handle);
StringFormat format = new StringFormat(); format.LineAlignment = StringAlignment.Center;
format.Alignment = StringAlignment.Center;
string str = "%";
str = str + System.Convert.ToString(this._Percent);
theGraphics.DrawString(str, this.Font,new SolidBrush(this.ForeColor), new Rectangle(0,this.Height-lineSepra,this.Width,this.Height),format);
} private void DrawRect()
{
Graphics theGraphics = Graphics.FromHwnd(this.Handle); Pen blackPen = new Pen(Color.Red, 2);
Rectangle rect = new Rectangle(0, 0, this.Width, this.Height - lineSepra);
// Draw rectangle to screen
theGraphics.DrawRectangle(blackPen, rect);
} private void UserControl1_SizeChanged(object sender, EventArgs e)
{
Invalidate();
lineSepra = (this.Height * 2) / 10;
DrawText();
DrawRect();
} private void UserControl1_Load(object sender, EventArgs e)
{
lineSepra = (this.Height * 2)/10;
this._Percent = 0;
this.BackColor = System.Drawing.Color.Lavender;
} private void UserControl1_AutoSizeChanged(object sender, EventArgs e)
{
Invalidate();
lineSepra = (this.Height * 2) / 10;
DrawText();
DrawRect();
}这是一个自定义控件.我在引入在别的工程后,改变大小的时候.界面上显示的没有改变.当工程运行时显示的是改变的.还有就是我那句画的文字没有显示出来.帮帮忙.谢
DrawRect(); DrawText();
这样就应该能显示文字了吧 因该是刷新的问题吧