Gewusst wie: Verknüpfen von ToolStripPanels

Sie können ToolStrip-Steuerelemente zur Laufzeit mit ToolStripPanel verknüpfen, wodurch Sie die Flexibilität von MDI (Multiple Document Interface-)Anwendungen erhalten.

Beispiel

Im folgenden Codebeispiel wird veranschaulicht, wie ToolStrip-Steuerelemente mit ToolStripPanel verknüpft werden.

' Create ToolStripPanel controls.
Dim tspTop As New ToolStripPanel()
Dim tspBottom As New ToolStripPanel()
Dim tspLeft As New ToolStripPanel()
Dim tspRight As New ToolStripPanel()

' Dock the ToolStripPanel controls to the edges of the form.
tspTop.Dock = DockStyle.Top
tspBottom.Dock = DockStyle.Bottom
tspLeft.Dock = DockStyle.Left
tspRight.Dock = DockStyle.Right

' Create ToolStrip controls to move among the 
' ToolStripPanel controls.
' Create the "Top" ToolStrip control and add
' to the corresponding ToolStripPanel.
Dim tsTop As New ToolStrip()
tsTop.Items.Add("Top")
tspTop.Join(tsTop)

' Create the "Bottom" ToolStrip control and add
' to the corresponding ToolStripPanel.
Dim tsBottom As New ToolStrip()
tsBottom.Items.Add("Bottom")
tspBottom.Join(tsBottom)

' Create the "Right" ToolStrip control and add
' to the corresponding ToolStripPanel.
Dim tsRight As New ToolStrip()
tsRight.Items.Add("Right")
tspRight.Join(tsRight)

' Create the "Left" ToolStrip control and add
' to the corresponding ToolStripPanel.
Dim tsLeft As New ToolStrip()
tsLeft.Items.Add("Left")
tspLeft.Join(tsLeft)
// Create ToolStripPanel controls.
ToolStripPanel tspTop = new ToolStripPanel();
ToolStripPanel tspBottom = new ToolStripPanel();
ToolStripPanel tspLeft = new ToolStripPanel();
ToolStripPanel tspRight = new ToolStripPanel();

// Dock the ToolStripPanel controls to the edges of the form.
tspTop.Dock = DockStyle.Top;
tspBottom.Dock = DockStyle.Bottom;
tspLeft.Dock = DockStyle.Left;
tspRight.Dock = DockStyle.Right;

// Create ToolStrip controls to move among the 
// ToolStripPanel controls.

// Create the "Top" ToolStrip control and add
// to the corresponding ToolStripPanel.
ToolStrip tsTop = new ToolStrip();
tsTop.Items.Add("Top");
tspTop.Join(tsTop);

// Create the "Bottom" ToolStrip control and add
// to the corresponding ToolStripPanel.
ToolStrip tsBottom = new ToolStrip();
tsBottom.Items.Add("Bottom");
tspBottom.Join(tsBottom);

// Create the "Right" ToolStrip control and add
// to the corresponding ToolStripPanel.
ToolStrip tsRight = new ToolStrip();
tsRight.Items.Add("Right");
tspRight.Join(tsRight);

// Create the "Left" ToolStrip control and add
// to the corresponding ToolStripPanel.
ToolStrip tsLeft = new ToolStrip();
tsLeft.Items.Add("Left");
tspLeft.Join(tsLeft);

Kompilieren des Codes

Für dieses Beispiel sind erforderlich:

  • Verweise auf die Assemblys System.Design, System.Drawing und System.Windows.Forms.

Informationen zum Erstellen dieses Beispiels über die Befehlszeile für Visual Basic oder Visual C# finden Sie unterErstellen von der Befehlszeile aus (Visual Basic) und Erstellen über die Befehlszeile mit csc.exe. Sie können dieses Beispiel auch in Visual Studio erstellen, indem Sie den Code in ein neues Projekt einfügen. Weitere Informationen finden Sie unter Gewusst wie: Kompilieren und Ausführen eines vollständigen Windows Forms-Codebeispiels mit Visual Studio und Gewusst wie: Kompilieren und Ausführen eines vollständigen Windows Forms-Codebeispiels mit Visual Studio und Gewusst wie: Kompilieren und Ausführen eines vollständigen Windows Forms-Codebeispiels mit Visual Studio und Gewusst wie: Kompilieren und Ausführen eines vollständigen Windows Forms-Codebeispiels mit Visual Studio und Gewusst wie: Kompilieren und Ausführen eines vollständigen Windows Forms-Codebeispiels mit Visual Studio.

Siehe auch

Aufgaben

Gewusst wie: Verwenden von ToolStripPanels für MDI

Referenz

ToolStrip

ToolStripPanel