当前位置: 首页>>代码示例>>C#>>正文


C# TextBox.CreateGraphics方法代码示例

本文整理汇总了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 });
 }
开发者ID:mblaine,项目名称:NbtViewer,代码行数:7,代码来源:Form1.cs

示例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;
 }
开发者ID:HAF-Blade,项目名称:MediaPortal-2,代码行数:31,代码来源:FormDesigner.cs

示例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);
     }
 }
开发者ID:huamanhtuyen,项目名称:VNACCS,代码行数:10,代码来源:ComponentProperty.cs


注:本文中的System.Windows.Forms.TextBox.CreateGraphics方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。