本文整理汇总了C#中System.Windows.Forms.TextBox.CreateGraphics方法的典型用法代码示例。如果您正苦于以下问题:C# TextBox.CreateGraphics方法的具体用法?C# TextBox.CreateGraphics怎么用?C# TextBox.CreateGraphics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.TextBox
的用法示例。
在下文中一共展示了TextBox.CreateGraphics方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetTabWidth
public static void SetTabWidth(TextBox textbox, int tabWidth)
{
System.Drawing.Graphics graphics = textbox.CreateGraphics();
var characterWidth = (int)graphics.MeasureString("M", textbox.Font).Width;
SendMessage(textbox.Handle, EM_SETTABSTOPS, 1,
new int[] { tabWidth * characterWidth });
}
示例2: CreateTextBox
/// <summary>
/// Returns a default TextBox.
/// Its position is based on both parameters.
/// </summary>
/// <param name="position">Position of the TextBox.</param>
/// <param name="reqWidth">Requested width, as a number of characters.</param>
/// <returns></returns>
private TextBox CreateTextBox(Position position, int reqWidth)
{
TextBox txt = new TextBox();
txt.Multiline = false;
StringBuilder sb = new StringBuilder(reqWidth < 0 ? 0 : reqWidth);
for (int i = 0; i < reqWidth; i++)
sb.Append("o"); // take 'o' as the character to measure
int width = (int)(txt.CreateGraphics().MeasureString(sb.ToString(), txt.Font).Width);
if (width < position.WidthColumnTwo)
{
txt.Width = position.WidthColumnTwo;
txt.Location = new Point(position.StartColumnTwo, position.LinePosition - 5);
}
else
{
txt.Width = position.Width;
position.LinePosition += position.LineHeight;
txt.Location = new Point(position.StartColumnOne + position.Margin, position.LinePosition);
}
txt.TabIndex = position.NextTabIndex;
txt.Name = "textBox" + position.TabIndex.ToString();
txt.Leave += _entryLeave;
return txt;
}
示例3: IsNewLineNeeded
public static bool IsNewLineNeeded(string text, TextBox tb)
{
TextFormatFlags noPrefix = TextFormatFlags.NoPrefix;
using (Graphics graphics = tb.CreateGraphics())
{
System.Drawing.Size proposedSize = new System.Drawing.Size(0x7fffffff, 0x7fffffff);
System.Drawing.Size size2 = TextRenderer.MeasureText(graphics, text, tb.Font, proposedSize, noPrefix);
return (tb.ClientSize.Width < size2.Width);
}
}