本文整理匯總了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();
}
}
}