當前位置: 首頁>>代碼示例>>C#>>正文


C# StringFormat.SetTabStops方法代碼示例

本文整理匯總了C#中System.Drawing.StringFormat.SetTabStops方法的典型用法代碼示例。如果您正苦於以下問題:C# StringFormat.SetTabStops方法的具體用法?C# StringFormat.SetTabStops怎麽用?C# StringFormat.SetTabStops使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Drawing.StringFormat的用法示例。


在下文中一共展示了StringFormat.SetTabStops方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: GetSetTabStopsExample2

public void GetSetTabStopsExample2(PaintEventArgs e)
{
    Graphics     g = e.Graphics;
             
    // Tools used for drawing, painting.
    Pen          redPen = new Pen(Color.FromArgb(255, 255, 0, 0));
    SolidBrush   blueBrush = new SolidBrush(Color.FromArgb(255, 0, 0, 255));
             
    // Layout and format for text.
    Font         myFont = new Font("Times New Roman", 12);
    StringFormat myStringFormat = new StringFormat();
    Rectangle    enclosingRectangle = new Rectangle(20, 20, 500, 100);
    float[]      tabStops = {150.0f, 100.0f, 100.0f};
             
    // Text with tabbed columns.
    string       myString =
        "Name\tTab 1\tTab 2\tTab 3\nGeorge Brown\tOne\tTwo\tThree";
             
    // Set the tab stops, paint the text specified by myString, draw the
    // rectangle that encloses the text.
    myStringFormat.SetTabStops(0.0f, tabStops);
    g.DrawString(myString, myFont, blueBrush,
        enclosingRectangle, myStringFormat);
    g.DrawRectangle(redPen, enclosingRectangle);
             
    // Get the tab stops.
    float   firstTabOffset;
    float[] tabStopsObtained = myStringFormat.GetTabStops(out firstTabOffset);
    for(int j = 0; j < tabStopsObtained.Length; j++)
    {
             
        // Inspect or use the value in tabStopsObtained[j].
        Console.WriteLine("\n  Tab stop {0} = {1}", j, tabStopsObtained[j]);
    }
}
開發者ID:.NET開發者,項目名稱:System.Drawing,代碼行數:35,代碼來源:StringFormat.SetTabStops

示例2: Form1

//引入命名空間
using System;
  using System.Drawing;
  using System.Drawing.Drawing2D;
  using System.Collections;
  using System.ComponentModel;
  using System.Windows.Forms;
  using System.Data;
  using System.Drawing.Imaging;

  public class Form1 : System.Windows.Forms.Form
  {
    public Form1()
    {
      InitializeComponent();
    }
    private void InitializeComponent()
    {
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
      this.ClientSize = new System.Drawing.Size(292, 273);
      this.Text = "";
      this.Resize += new System.EventHandler(this.Form1_Resize);
      this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);

    }
    static void Main() 
    {
      Application.Run(new Form1());
    }

    private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
    {      
      Graphics g = e.Graphics;
      g.FillRectangle(Brushes.White, this.ClientRectangle);

      Font f = new Font("Times New Roman", 12);
      Font bf = new Font(f, FontStyle.Bold);

      StringFormat sf = new StringFormat();
      float[] ts = { 10.0f, 70.0f, 100.0f, 90.0f };
      sf.SetTabStops(0.0f, ts);

      // The \t escape-sequence in these lines specifies the tab
      string s1 = "\tName\tEye Color\tHeight";
      string s2 = "\tBob\tBrown\t175cm";
      string s3 = "\tMary\tBlond\t161cm\n\tBill\tBlack\t168cm";

      g.DrawString(s1, bf, Brushes.Black, 20, 20, sf);
      g.DrawString(s2, f, Brushes.Blue, 20, 20 + bf.Height, sf);
      g.DrawString(s3, f, Brushes.Blue, 20,
                        20 + bf.Height + f.Height, sf);

      f.Dispose();
      bf.Dispose();
    }

    private void Form1_Resize(object sender, System.EventArgs e)
    {
      Invalidate();
    }
  }
開發者ID:C#程序員,項目名稱:System.Drawing,代碼行數:61,代碼來源:StringFormat.SetTabStops


注:本文中的System.Drawing.StringFormat.SetTabStops方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。