更改自定义TextBox

时间:2015-09-30 22:08:50

标签: c# winforms textbox

我创建了自定义TextBox,但是当我将其Font设置为新的 public class TextLayer : TextBox { public TextLayer() { SetStyle(ControlStyles.SupportsTransparentBackColor | ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.UserPaint, true); BackColor = Color.Transparent; BorderStyle = BorderStyle.None; //font = new Font(FontFamily.GenericMonospace, 20); Font = new Font(FontFamily.GenericMonospace, 20); Size = new Size(22, 22); } protected override void OnTextChanged(EventArgs e) { base.OnTextChanged(e); var size = TextRenderer.MeasureText(Text, Font); if (size.Width < 30) Width = 30; else Width = size.Width; if (size.Height < 30) Height = 30; else Height = size.Height; } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); ControlPaint.DrawBorder( e.Graphics, ClientRectangle, Color.White, 1, ButtonBorderStyle.Dotted, Color.White, 1, ButtonBorderStyle.Dotted, Color.White, 1, ButtonBorderStyle.Dotted, Color.White, 1, ButtonBorderStyle.Dotted); } } 时,它无法正常工作:

TextBox

我在这里想念什么,迫使queryString呈现它的默认字体?

编辑: C# How to change font of a label我已经在我的代码中执行此操作并且它无法正常工作,那么它是如何重复的?

0 个答案:

没有答案