本文整理汇总了C#中System.Windows.Forms.TextBoxRenderer类的典型用法代码示例。如果您正苦于以下问题:C# TextBoxRenderer类的具体用法?C# TextBoxRenderer怎么用?C# TextBoxRenderer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TextBoxRenderer类属于System.Windows.Forms命名空间,在下文中一共展示了TextBoxRenderer类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Form1
//引入命名空间
using System;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
namespace TextBoxRendererSample
{
class Form1 : Form
{
public Form1()
: base()
{
this.Size = new Size(350, 200);
CustomTextBox TextBox1 = new CustomTextBox();
Controls.Add(TextBox1);
}
[STAThread]
static void Main()
{
// The call to EnableVisualStyles below does not affect whether
// TextBoxRenderer draws the text box; as long as visual styles
// are enabled by the operating system, TextBoxRenderer will
// draw the text box.
Application.EnableVisualStyles();
Application.Run(new Form1());
}
}
public class CustomTextBox : Control
{
private TextFormatFlags textFlags = TextFormatFlags.Default;
ComboBox comboBox1 = new ComboBox();
Rectangle textBorder = new Rectangle();
Rectangle textRectangle = new Rectangle();
StringBuilder textMeasurements = new StringBuilder();
public CustomTextBox()
: base()
{
this.Location = new Point(10, 10);
this.Size = new Size(300, 200);
this.Font = SystemFonts.IconTitleFont;
this.Text = "This is a long sentence that will exceed " +
"the text box bounds";
textBorder.Location = new Point(10, 10);
textBorder.Size = new Size(200, 50);
textRectangle.Location = new Point(textBorder.X + 2,
textBorder.Y + 2);
textRectangle.Size = new Size(textBorder.Size.Width - 4,
textBorder.Height - 4);
comboBox1.Location = new Point(10, 100);
comboBox1.Size = new Size(150, 20);
comboBox1.SelectedIndexChanged +=
new EventHandler(comboBox1_SelectedIndexChanged);
// Populate the combo box with the TextFormatFlags value names.
foreach (string name in Enum.GetNames(typeof(TextFormatFlags)))
{
comboBox1.Items.Add(name);
}
comboBox1.SelectedIndex = 0;
this.Controls.Add(comboBox1);
}
// Use DrawText with the current TextFormatFlags.
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if (TextBoxRenderer.IsSupported)
{
TextBoxRenderer.DrawTextBox(e.Graphics, textBorder, this.Text,
this.Font, textRectangle, textFlags, TextBoxState.Normal);
this.Parent.Text = "CustomTextBox Enabled";
}
else
{
this.Parent.Text = "CustomTextBox Disabled";
}
}
// Assign the combo box selection to the display text.
void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
this.textFlags = (TextFormatFlags)Enum.Parse(
typeof(TextFormatFlags),
(string)comboBox1.Items[comboBox1.SelectedIndex]);
Invalidate();
}
}
}
开发者ID:.NET开发者,项目名称:System.Windows.Forms,代码行数:98,代码来源:TextBoxRenderer
注:本文中的System.Windows.Forms.TextBoxRenderer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论