在Windows窗体上使用ToolStrip的最佳实践 [英] Best Practice using ToolStrip on Windows Form

查看:217
本文介绍了在Windows窗体上使用ToolStrip的最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始为朋友设计一个小型的E:Mail控制程序,但我想在深入潜入之前就最佳实践提出一些建议。



我有一个包含2个ComboBox的表单,所选数据决定发送什么,包含哪些附件以及SQL-Server数据库查找将确定将E:Mails发送给谁。这是目前在VS2010表单设计器中设计的,而不是在代码中。



我现在想要使用以下按钮添加ToolStrip:发送邮件(这是当前和主要形式),首选项管家(数据库维护)......



所以...当用户选择偏好管家时,我应该隐藏我的主表格吗?显示一个新表格,如果他再次选择发送邮件,我会隐藏这个新表格&重新打开隐藏的主表格...无限广告,以便有1-3个表格,但任何时候只能看到一个...



或..我应该只有一个表单,并且每次单击一个Button时我都会在代码中重建它吗?

解决方案

如果应用程序构建为单个文档界面(SDI) );也就是说,您只需要每个窗口的一个实例,在窗体设计器中将三个屏幕中的每一个创建为单独的用户控件。在应用程序的持续时间内创建每个实例,并根据需要在主窗体中添加或删除这三个用户控件中的每一个。这比隐藏/显示它们更清晰(如果它们是非常复杂的形式,我可能会隐藏/显示以节省资源)。



你会注意到我建议使用用户控件而不是表单。您实际上可以使用其中之一,但这是用户控件的意思。有几个原因。


  • 用户控件重量更轻。
  • 用户控件可以添加到表单中在表单设计器中,您仍然可以与它们进行交互。子表单不能在Designer中使用。
  • 表单在使用前需要特殊准备( Form.TopLevel = false )。



实施例


I'm right at the start of designing a small E:Mail control program for a friend, but would just like to ask some advice on best practice before I dive in at the deep end.

I have a Form with 2 ComboBoxes and the data selected decides what to send, what attachments to include and a SQL-Server database look-up will ascertain who to send the E:Mails to. This is currently designed in VS2010 Form Designer, not in the code.

I now want to add a ToolStrip with the following buttons: Send Mail (this is the current & main form), Preferences, Housekeeping (Database maintenance) ...

So ... When the user chooses Preferences or Housekeeping, should I hide my Main Form & display a new Form, then if he chooses Send Mail again, I hide this new Form & re-open the hidden Main Form ... ad infinitum so that there are 1 - 3 Forms but only one is visible at any time ...

Or ... Should I have just a single Form and I rebuild it in the code every time a Button is clicked ?

解决方案

If the application built as a single document interface (SDI); that is, you only ever need one instance of each of these windows, create each of the three screens as separate User Controls in Form Designer. Create one instance of each for the duration of the application, and add or remove each of these three user controls to your main form as necessary. This is a little cleaner than hiding/showing them (If they were very complex forms I might hide/show to conserve resources).

You will note that I recommend using a User Control instead of a Form. You could actually use either, but this is what user controls are meant for. There are a few reasons.

  • User controls are lighter-weight.
  • User controls can be added to a form in the Form Designer and you can still interact with them. Sub-forms cannot be used in the Designer.
  • Forms require special preparation before being used (Form.TopLevel = false).

Example


这篇关于在Windows窗体上使用ToolStrip的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆