失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > Enabled设置为False时 前景色和背景色也不改变的TextBox 并居中

Enabled设置为False时 前景色和背景色也不改变的TextBox 并居中

时间:2020-08-05 21:32:41

相关推荐

Enabled设置为False时 前景色和背景色也不改变的TextBox 并居中

1.公共方法

public class MyTextBox:TextBox

{protected override void OnEnabledChanged(EventArgse)

{base .OnEnabledChanged(e); // 设置Enabled为False时 if ( this .Enabled)

{this .SetStyle(ControlStyles.UserPaint, false );

} else this .SetStyle(ControlStyles.UserPaint, true ); // 再描绘 this .Invalidate();

} // 描绘TextBox protected override void OnPaint(PaintEventArgse)

{base .OnPaint(e);

System.Drawing.Brushb = new System.Drawing.SolidBrush( this .ForeColor);

StringFormatsf = new StringFormat();

sf.LineAlignment = StringAlignment.Center;

sf.Alignment = StringAlignment.Center; // 描绘字符串 // e.Graphics.DrawString(this.Text,this.Font,b,-1,1); e.Graphics.DrawString( this .Text, this .Font,b, this .ClientRectangle,sf);

b.Dispose();

}

}

2.页面 designer.cs修改为 MyTextBox

如果觉得《Enabled设置为False时 前景色和背景色也不改变的TextBox 并居中》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。