在用户控件窗体中添加textBox1,label1public class UnderlineText:UserControl
{
private Color lineColor;
[DefaultValue("Black"),Category("Appearance")]
public Color LineColor
{
get
{
return lineColor;
}
set
{
lineColor=value;
}
}
public UnderLineText()
{
initialComponent();
}
//在label1中画下划线
private void drawLine()
{
label1.AutoSize=false;
label1.Left=textBox1.Left;
label1.Top=textBox1.Top+textBox1.Height;
label1.Width=textBox1.Width;
label1.Text="";
Graphics g=label1.CreateGraphics();
SolidBrush brush=new SolidBrush(lineColor,2);
g.DrawLine(brush,0,2,label1.Width-2,2);
}
private void UnderlineText_Load(object sender,EventArgs e)
{
drawLine();
}
}编译时,在设计器中为什么结果没有显示下划线? 是不是事件有问题?
{
private Color lineColor;
[DefaultValue("Black"),Category("Appearance")]
public Color LineColor
{
get
{
return lineColor;
}
set
{
lineColor=value;
}
}
public UnderLineText()
{
initialComponent();
}
//在label1中画下划线
private void drawLine()
{
label1.AutoSize=false;
label1.Left=textBox1.Left;
label1.Top=textBox1.Top+textBox1.Height;
label1.Width=textBox1.Width;
label1.Text="";
Graphics g=label1.CreateGraphics();
SolidBrush brush=new SolidBrush(lineColor,2);
g.DrawLine(brush,0,2,label1.Width-2,2);
}
private void UnderlineText_Load(object sender,EventArgs e)
{
drawLine();
}
}编译时,在设计器中为什么结果没有显示下划线? 是不是事件有问题?
可以看看MSDN,以前vb6有画线工具,但现在没有了,MSDN给的建议是用Label来做。Text="_________"就算是下划线了。