HOW TO:將控制項加入 ToolStripContentPanel
您可以用程式設計方式在 ToolStripContentPanel 中加入一或多個控制項。
範例
下列程式碼範例示範如何將 RichTextBox 加入至 ToolStripContentPanel。
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Public Class Form1
Inherits Form
Private tsc As ToolStripContainer
Private rtb As RichTextBox
Public Sub New()
InitializeComponent()
End Sub
<STAThread()> _
Shared Sub Main()
Application.EnableVisualStyles()
Application.Run(New Form1())
End Sub
Private Sub InitializeComponent()
Me.tsc = New System.Windows.Forms.ToolStripContainer()
Me.rtb = New System.Windows.Forms.RichTextBox()
Me.tsc.ContentPanel.Controls.Add(Me.rtb)
Me.Controls.Add(tsc)
End Sub
End Class
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
public class Form1 : Form
{
private ToolStripContainer tsc;
private RichTextBox rtb;
public Form1()
{
InitializeComponent();
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new Form1());
}
private void InitializeComponent()
{
this.tsc = new System.Windows.Forms.ToolStripContainer();
this.rtb = new System.Windows.Forms.RichTextBox();
this.tsc.ContentPanel.Controls.Add(this.rtb);
this.Controls.Add(this.tsc);
}
}
編譯程式碼
此程式碼範例需要:
- System、System.Data 和 System.Windows.Forms 組件的參考。
如需從 Visual Basic 或 Visual C# 的命令列建置這個範例的詳細資訊,請參閱從命令列建置 (Visual Basic) 或使用 csc.exe 建置命令列。 您也可以透過將程式碼貼入新的專案,在 Visual Studio 中建置此範例。 如需詳細資訊,請參閱HOW TO:使用 Visual Studio 編譯及執行完整的 Windows Form 程式碼範例 和 HOW TO:使用 Visual Studio 編譯及執行完整的 Windows Form 程式碼範例 和 HOW TO:使用 Visual Studio 編譯及執行完整的 Windows Form 程式碼範例 和 HOW TO:使用 Visual Studio 編譯及執行完整的 Windows Form 程式碼範例 和 如何:使用 Visual Studio 編譯及執行完整的 Windows Form 程式碼範例.
如需詳細資訊,請參閱ToolStripContainer 工作對話方塊 和 ToolStripContainer 工作對話方塊 和 ToolStripContainer 工作對話方塊 和 ToolStripContainer 工作對話方塊 和 ToolStripContainer 工作對話方塊.