0

我有一个使用 MDI 表单的 Winform 应用程序。在 MDI 表单上,我有一个带有按钮(按钮有图像)的 ToolStrip,用作应用程序的主菜单按钮。因此,当用户单击工具条上的按钮时,该按钮的 mdichild 表单将打开子表单。

所以我有六个按钮,其中已经创建了图像并在项目中。但我希望用户选择他们想要出现在工具条上的按钮。所以用户打开应用程序,工具条上只有一个按钮。用户单击该按钮,将打开一个子屏幕,显示工具条上所有可用的现有按钮。用户选择他们希望出现在工具条上的按钮,然后单击子屏幕上的保存按钮。

我想要的是,一旦用户单击该保存按钮,用户选择的按钮应该自动出现在工具条上。现在我必须让用户关闭应用程序,然后重新打开它,以便他们选择出现在工具条上的按钮。

如何让按钮自动出现?

4

2 回答 2

1

Just create all of the ToolStripButtons, and set each one's Visible property to false. When the user picks them to be shown, change the Visible property of the ToolStripButton to true. They'll automatically appear on the ToolStrip.

I tested using VS2010 with Oxygene from RemObjects (formerly AKA Delphi Prism).

  • Start a new WinForms application
  • Drop a ToolStrip on the window. Right-click it and choose Insert standard items.
  • Double-click the New button (newToolStripButton, the one on the left end), and add the following code to the newToolStripButton_Click handler:
// Oxygene version: helpToolStripButton.Visible := not helpToolStripButton.Visible;
helpToolStripButton.Visible != helpToolStripButton.Visible;
  • Run the application, and click the newTooStripButton repeatedly, and watch the right-most ToolStripButton (the Help button) appear and disappear from the ToolStrip.
于 2013-06-20T18:27:26.773 回答
0

您可以创建任何 ToolStrip 并将其添加到 MenuStrip.DropDownItems.Add。click EventHandler 必须是 (s,e) 函数。

ToolStripMenuItem ts = new ToolStripMenuItem();
ts.Name = $"MyMenuStrip";
ts.Text = "New MenuStrip";
ts.Click += new EventHandler(this.ToolStripMenuItem_Click);

private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
    ToolStripMenuItem clickedMenuItem = sender as ToolStripMenuItem;
    Trace.WriteLine($"Clicked: {clickedMenuItem.Text}");
}
于 2021-03-15T16:42:26.810 回答