當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。