Csharp/C Sharp by API/System.Windows.Forms/TabControl

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

TabControl.Alignment

<source lang="csharp">

using System; using System.Drawing; using System.Windows.Forms; public class TabControls : Form {

 public TabControls()
 {
   Size = new Size(325,375);
   TabControl tc = new TabControl();
   tc.Parent = this;
   tc.Size = new Size(275,300);
   tc.Location = new Point(25,25);
   tc.Anchor = AnchorStyles.Top | AnchorStyles.Bottom |
         AnchorStyles.Left | AnchorStyles.Right;
   tc.Alignment = TabAlignment.Top;
   tc.Appearance = TabAppearance.Normal;
   tc.HotTrack = true;
   tc.Multiline = true;
   tc.Padding = new Point(20,3);
   tc.SizeMode = TabSizeMode.FillToRight;
   tc.SelectedIndexChanged += new EventHandler(tc_Changed);
   tc.Text = "Some text";
   Image img = Image.FromFile("1.ico");
   ImageList imgList = new ImageList();
   imgList.Images.Add(img);
   tc.ImageList = imgList;
   TabPage tpAddress = new TabPage();
   tpAddress.Parent = tc;
   tpAddress.Text = "Address Book";
   TabPage tpDates = new TabPage();
   tpDates.Parent = tc;
   tpDates.Text = "Date Book";
   TabPage tpToDo = new TabPage();
   tpToDo.Parent = tc;
   tpToDo.Text = "ToDo List";
   TabPage tpMisc = new TabPage();
   tpMisc.Parent = tc;
   tpMisc.Text = "Email";
   tpMisc.ImageIndex = 0;
   Label lbl = new Label();
   lbl.Parent = tpAddress;
   lbl.Text = "Address book";
   lbl.AutoSize = true;
   lbl.Location = new Point(10,25);
   Panel pnl = new Panel();
   pnl.Parent = tpDates;
   pnl.BorderStyle = BorderStyle.Fixed3D;
   pnl.Location = new Point(10,10);
   pnl.Anchor = AnchorStyles.Top | AnchorStyles.Bottom |
         AnchorStyles.Left | AnchorStyles.Right;
   pnl.Size = new Size(tpDates.Width - 20, tpDates.Height - 20);
   MonthCalendar cal = new MonthCalendar();
   cal.Parent = pnl;
   cal.Location = new Point(25,25);
   RichTextBox rtxt = new RichTextBox();
   rtxt.Parent = tpToDo;
   rtxt.Dock = DockStyle.Fill;
   rtxt.BorderStyle = BorderStyle.FixedSingle;
 }
 static void Main() 
 {
   Application.Run(new TabControls());
 }
 private void tc_Changed(object sender, EventArgs e)
 {
   TabControl tc = (TabControl)sender;
   Console.WriteLine("Button " + tc.SelectedIndex.ToString());
 }

}

 </source>


TabControl.Appearance

<source lang="csharp">

using System; using System.Drawing; using System.Windows.Forms; public class TabControls : Form {

 public TabControls()
 {
   Size = new Size(325,375);
   TabControl tc = new TabControl();
   tc.Parent = this;
   tc.Size = new Size(275,300);
   tc.Location = new Point(25,25);
   tc.Anchor = AnchorStyles.Top | AnchorStyles.Bottom |
         AnchorStyles.Left | AnchorStyles.Right;
   tc.Alignment = TabAlignment.Top;
   tc.Appearance = TabAppearance.Normal;
   tc.HotTrack = true;
   tc.Multiline = true;
   tc.Padding = new Point(20,3);
   tc.SizeMode = TabSizeMode.FillToRight;
   tc.SelectedIndexChanged += new EventHandler(tc_Changed);
   tc.Text = "Some text";
   Image img = Image.FromFile("1.ico");
   ImageList imgList = new ImageList();
   imgList.Images.Add(img);
   tc.ImageList = imgList;
   TabPage tpAddress = new TabPage();
   tpAddress.Parent = tc;
   tpAddress.Text = "Address Book";
   TabPage tpDates = new TabPage();
   tpDates.Parent = tc;
   tpDates.Text = "Date Book";
   TabPage tpToDo = new TabPage();
   tpToDo.Parent = tc;
   tpToDo.Text = "ToDo List";
   TabPage tpMisc = new TabPage();
   tpMisc.Parent = tc;
   tpMisc.Text = "Email";
   tpMisc.ImageIndex = 0;
   Label lbl = new Label();
   lbl.Parent = tpAddress;
   lbl.Text = "Address book";
   lbl.AutoSize = true;
   lbl.Location = new Point(10,25);
   Panel pnl = new Panel();
   pnl.Parent = tpDates;
   pnl.BorderStyle = BorderStyle.Fixed3D;
   pnl.Location = new Point(10,10);
   pnl.Anchor = AnchorStyles.Top | AnchorStyles.Bottom |
         AnchorStyles.Left | AnchorStyles.Right;
   pnl.Size = new Size(tpDates.Width - 20, tpDates.Height - 20);
   MonthCalendar cal = new MonthCalendar();
   cal.Parent = pnl;
   cal.Location = new Point(25,25);
   RichTextBox rtxt = new RichTextBox();
   rtxt.Parent = tpToDo;
   rtxt.Dock = DockStyle.Fill;
   rtxt.BorderStyle = BorderStyle.FixedSingle;
 }
 static void Main() 
 {
   Application.Run(new TabControls());
 }
 private void tc_Changed(object sender, EventArgs e)
 {
   TabControl tc = (TabControl)sender;
   Console.WriteLine("Button " + tc.SelectedIndex.ToString());
 }

}

 </source>


TabControl.Controls.Add

<source lang="csharp"> using System; using System.Collections.Generic; using System.ruponentModel; using System.Data; using System.Drawing; using System.Windows.Forms; using System.Text; class Form1 : Form {

   public Form1() {
       this.tabPage2 = new System.Windows.Forms.TabPage();
       this.textBoxMessage = new System.Windows.Forms.TextBox();
       this.tabPage1 = new System.Windows.Forms.TabPage();
       this.buttonShowMessage = new System.Windows.Forms.Button();
       this.tabControl1 = new System.Windows.Forms.TabControl();
       this.tabPage2.SuspendLayout();
       this.tabPage1.SuspendLayout();
       this.tabControl1.SuspendLayout();
       this.SuspendLayout();
       this.tabPage2.Controls.Add(this.textBoxMessage);
       this.tabPage2.Location = new System.Drawing.Point(4, 22);
       this.tabPage2.Name = "tabPage2";
       this.tabPage2.Padding = new System.Windows.Forms.Padding(3);
       this.tabPage2.Size = new System.Drawing.Size(259, 37);
       this.tabPage2.TabIndex = 1;
       this.tabPage2.Text = "Tab Two";
       this.textBoxMessage.Location = new System.Drawing.Point(72, 7);
       this.textBoxMessage.Name = "textBoxMessage";
       this.textBoxMessage.Size = new System.Drawing.Size(100, 20);
       this.textBoxMessage.TabIndex = 0;
       this.tabPage1.Controls.Add(this.buttonShowMessage);
       this.tabPage1.Location = new System.Drawing.Point(4, 22);
       this.tabPage1.Name = "tabPage1";
       this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
       this.tabPage1.Size = new System.Drawing.Size(259, 37);
       this.tabPage1.TabIndex = 0;
       this.tabPage1.Text = "Tab One";
       this.buttonShowMessage.Location = new System.Drawing.Point(74, 7);
       this.buttonShowMessage.Name = "buttonShowMessage";
       this.buttonShowMessage.Size = new System.Drawing.Size(107, 24);
       this.buttonShowMessage.TabIndex = 0;
       this.buttonShowMessage.Text = "Show Message";
       this.buttonShowMessage.Click += new System.EventHandler(this.buttonShowMessage_Click);
       this.tabControl1.Controls.Add(this.tabPage1);
       this.tabControl1.Controls.Add(this.tabPage2);
       this.tabControl1.Location = new System.Drawing.Point(13, 13);
       this.tabControl1.Name = "tabControl1";
       this.tabControl1.SelectedIndex = 0;
       this.tabControl1.Size = new System.Drawing.Size(267, 63);
       this.tabControl1.TabIndex = 0;
       this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
       this.ClientSize = new System.Drawing.Size(292, 83);
       this.Controls.Add(this.tabControl1);
       this.tabPage2.ResumeLayout(false);
       this.tabPage2.PerformLayout();
       this.tabPage1.ResumeLayout(false);
       this.tabControl1.ResumeLayout(false);
       this.ResumeLayout(false);
   }
   private void buttonShowMessage_Click(object sender, EventArgs e) {
       MessageBox.Show(this.textBoxMessage.Text);
   }
   private System.Windows.Forms.TabPage tabPage2;
   private System.Windows.Forms.TextBox textBoxMessage;
   private System.Windows.Forms.TabPage tabPage1;
   private System.Windows.Forms.Button buttonShowMessage;
   private System.Windows.Forms.TabControl tabControl1;
   [STAThread]
   static void Main() {
       Application.EnableVisualStyles();
       Application.Run(new Form1());
   }

}


 </source>


TabControl.HotTrack

<source lang="csharp">

using System; using System.Drawing; using System.Windows.Forms; public class TabControls : Form {

 public TabControls()
 {
   Size = new Size(325,375);
   TabControl tc = new TabControl();
   tc.Parent = this;
   tc.Size = new Size(275,300);
   tc.Location = new Point(25,25);
   tc.Anchor = AnchorStyles.Top | AnchorStyles.Bottom |
         AnchorStyles.Left | AnchorStyles.Right;
   tc.Alignment = TabAlignment.Top;
   tc.Appearance = TabAppearance.Normal;
   tc.HotTrack = true;
   tc.Multiline = true;
   tc.Padding = new Point(20,3);
   tc.SizeMode = TabSizeMode.FillToRight;
   tc.SelectedIndexChanged += new EventHandler(tc_Changed);
   tc.Text = "Some text";
   Image img = Image.FromFile("1.ico");
   ImageList imgList = new ImageList();
   imgList.Images.Add(img);
   tc.ImageList = imgList;
   TabPage tpAddress = new TabPage();
   tpAddress.Parent = tc;
   tpAddress.Text = "Address Book";
   TabPage tpDates = new TabPage();
   tpDates.Parent = tc;
   tpDates.Text = "Date Book";
   TabPage tpToDo = new TabPage();
   tpToDo.Parent = tc;
   tpToDo.Text = "ToDo List";
   TabPage tpMisc = new TabPage();
   tpMisc.Parent = tc;
   tpMisc.Text = "Email";
   tpMisc.ImageIndex = 0;
   Label lbl = new Label();
   lbl.Parent = tpAddress;
   lbl.Text = "Address book";
   lbl.AutoSize = true;
   lbl.Location = new Point(10,25);
   Panel pnl = new Panel();
   pnl.Parent = tpDates;
   pnl.BorderStyle = BorderStyle.Fixed3D;
   pnl.Location = new Point(10,10);
   pnl.Anchor = AnchorStyles.Top | AnchorStyles.Bottom |
         AnchorStyles.Left | AnchorStyles.Right;
   pnl.Size = new Size(tpDates.Width - 20, tpDates.Height - 20);
   MonthCalendar cal = new MonthCalendar();
   cal.Parent = pnl;
   cal.Location = new Point(25,25);
   RichTextBox rtxt = new RichTextBox();
   rtxt.Parent = tpToDo;
   rtxt.Dock = DockStyle.Fill;
   rtxt.BorderStyle = BorderStyle.FixedSingle;
 }
 static void Main() 
 {
   Application.Run(new TabControls());
 }
 private void tc_Changed(object sender, EventArgs e)
 {
   TabControl tc = (TabControl)sender;
   Console.WriteLine("Button " + tc.SelectedIndex.ToString());
 }

}

 </source>


TabControl.Multiline

<source lang="csharp">

using System; using System.Drawing; using System.Windows.Forms; public class TabControls : Form {

 public TabControls()
 {
   Size = new Size(325,375);
   TabControl tc = new TabControl();
   tc.Parent = this;
   tc.Size = new Size(275,300);
   tc.Location = new Point(25,25);
   tc.Anchor = AnchorStyles.Top | AnchorStyles.Bottom |
         AnchorStyles.Left | AnchorStyles.Right;
   tc.Alignment = TabAlignment.Top;
   tc.Appearance = TabAppearance.Normal;
   tc.HotTrack = true;
   tc.Multiline = true;
   tc.Padding = new Point(20,3);
   tc.SizeMode = TabSizeMode.FillToRight;
   tc.SelectedIndexChanged += new EventHandler(tc_Changed);
   tc.Text = "Some text";
   Image img = Image.FromFile("1.ico");
   ImageList imgList = new ImageList();
   imgList.Images.Add(img);
   tc.ImageList = imgList;
   TabPage tpAddress = new TabPage();
   tpAddress.Parent = tc;
   tpAddress.Text = "Address Book";
   TabPage tpDates = new TabPage();
   tpDates.Parent = tc;
   tpDates.Text = "Date Book";
   TabPage tpToDo = new TabPage();
   tpToDo.Parent = tc;
   tpToDo.Text = "ToDo List";
   TabPage tpMisc = new TabPage();
   tpMisc.Parent = tc;
   tpMisc.Text = "Email";
   tpMisc.ImageIndex = 0;
   Label lbl = new Label();
   lbl.Parent = tpAddress;
   lbl.Text = "Address book";
   lbl.AutoSize = true;
   lbl.Location = new Point(10,25);
   Panel pnl = new Panel();
   pnl.Parent = tpDates;
   pnl.BorderStyle = BorderStyle.Fixed3D;
   pnl.Location = new Point(10,10);
   pnl.Anchor = AnchorStyles.Top | AnchorStyles.Bottom |
         AnchorStyles.Left | AnchorStyles.Right;
   pnl.Size = new Size(tpDates.Width - 20, tpDates.Height - 20);
   MonthCalendar cal = new MonthCalendar();
   cal.Parent = pnl;
   cal.Location = new Point(25,25);
   RichTextBox rtxt = new RichTextBox();
   rtxt.Parent = tpToDo;
   rtxt.Dock = DockStyle.Fill;
   rtxt.BorderStyle = BorderStyle.FixedSingle;
 }
 static void Main() 
 {
   Application.Run(new TabControls());
 }
 private void tc_Changed(object sender, EventArgs e)
 {
   TabControl tc = (TabControl)sender;
   Console.WriteLine("Button " + tc.SelectedIndex.ToString());
 }

}

 </source>


TabControl.SelectedIndexChanged

<source lang="csharp">

using System; using System.Drawing; using System.Windows.Forms; public class TabControls : Form {

 public TabControls()
 {
   Size = new Size(325,375);
   TabControl tc = new TabControl();
   tc.Parent = this;
   tc.Size = new Size(275,300);
   tc.Location = new Point(25,25);
   tc.Anchor = AnchorStyles.Top | AnchorStyles.Bottom |
         AnchorStyles.Left | AnchorStyles.Right;
   tc.Alignment = TabAlignment.Top;
   tc.Appearance = TabAppearance.Normal;
   tc.HotTrack = true;
   tc.Multiline = true;
   tc.Padding = new Point(20,3);
   tc.SizeMode = TabSizeMode.FillToRight;
   tc.SelectedIndexChanged += new EventHandler(tc_Changed);
   tc.Text = "Some text";
   Image img = Image.FromFile("1.ico");
   ImageList imgList = new ImageList();
   imgList.Images.Add(img);
   tc.ImageList = imgList;
   TabPage tpAddress = new TabPage();
   tpAddress.Parent = tc;
   tpAddress.Text = "Address Book";
   TabPage tpDates = new TabPage();
   tpDates.Parent = tc;
   tpDates.Text = "Date Book";
   TabPage tpToDo = new TabPage();
   tpToDo.Parent = tc;
   tpToDo.Text = "ToDo List";
   TabPage tpMisc = new TabPage();
   tpMisc.Parent = tc;
   tpMisc.Text = "Email";
   tpMisc.ImageIndex = 0;
   Label lbl = new Label();
   lbl.Parent = tpAddress;
   lbl.Text = "Address book";
   lbl.AutoSize = true;
   lbl.Location = new Point(10,25);
   Panel pnl = new Panel();
   pnl.Parent = tpDates;
   pnl.BorderStyle = BorderStyle.Fixed3D;
   pnl.Location = new Point(10,10);
   pnl.Anchor = AnchorStyles.Top | AnchorStyles.Bottom |
         AnchorStyles.Left | AnchorStyles.Right;
   pnl.Size = new Size(tpDates.Width - 20, tpDates.Height - 20);
   MonthCalendar cal = new MonthCalendar();
   cal.Parent = pnl;
   cal.Location = new Point(25,25);
   RichTextBox rtxt = new RichTextBox();
   rtxt.Parent = tpToDo;
   rtxt.Dock = DockStyle.Fill;
   rtxt.BorderStyle = BorderStyle.FixedSingle;
 }
 static void Main() 
 {
   Application.Run(new TabControls());
 }
 private void tc_Changed(object sender, EventArgs e)
 {
   TabControl tc = (TabControl)sender;
   Console.WriteLine("Button " + tc.SelectedIndex.ToString());
 }

}

 </source>