关于在c#中使用表单 [英] about using forms in c#

查看:85
本文介绍了关于在c#中使用表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我在我的程序中使用了menustrip控件,我想在一个窗口中打开所有表单,我的问题是使用多种形式和使用它们如隐藏一个并显示另一个或使用其他方式更好?

解决方案

这取决于您在应用程序中实际使用的表单数量。

如果有2-3个表格,最好使用面板去表示/隐藏方法,因为,一次,你会显示在形式和&隐藏其他人。所以代码就是这样,

 Panel1.Show(); 
Panel2.Hide();
Panel3.Hide();



但如果有很多表格,你会写很多隐藏/表演(这有点忙乱:笑:) 。



所以,两种方法都很好,但明智地使用它们。



-KR


似乎常识表示在任何时候完全可见多少UI元素(表格,等等)将与多少屏幕相关房地产你,或你的最终用户,有空。在现代应用程序设计中,imho,有一堆重叠的 UI元素是一件坏事。



是的,你可以创建一个WinForm MenuStrip并使用它来控制任何/所有UI元素的可见性:这很简单(使用可选的CheckBoxes)。



我建议你不要在另一个Windows中使用Windows窗体窗体,或位于Windows窗体上的其他控件内部。是的,你可以逃避这一点,但这不是Windows Forms的使用方式;这是技术浪费。并且,是的,旧的MDI架构正是这样做的,但是MDI现在是一个恐龙的原因很好。



如何使用表格或面板,或者其他容器控件用于显示应用程序的不同UI元素,以及在用户在运行时与元素交互时如何更改元素的外观,可见性或启用状态......应根据这些设计决策做出关于你的应用程序是什么,它是如何使用的清晰视野。



所以,我建议你从草图开始......甚至在纸上: )...你的应用程序如何在其生命周期中的不同点出现在屏幕上:它最初是如何出现的(启动画面?登录对话框?文件打开对话框?,恢复以前保存的状态) ?);它是如何出现在您认为最常见的使用模式中的;用户如何保存工作或退出应用程序?



对于您展示的每个表格:它的功能是什么?它是用户可能正在处理的众多文档之一;它是您想要在某些时间或所有时间看到的工具调色板吗?



您必须决定是否需要一个主表单的应用程序(默认情况下创建的类型,如果您在Visual Studio中打开一个新的WinForm项目...关闭该主表单将关闭Applicaton),或者具有多个独立表单的应用程序,只要其中任何一个保持打开状态应用程序一直在运行(要在WinForms中实现这一点,你需要使用Application Context工具)。



有很多选择,包括使用一些容器控件,比如TabControl,有选择地呈现UI元素。



如果您在此处提出有关应用程序设计的其他问题,我建议您提供更多详细信息,告诉我们应用程序的功能,告诉我们更多信息多个表格的用途。


Hello,

I am using a menustrip control in my program, and I want to open all forms in one window, my question is either use many forms and use them like hide one and show another or using some another way be better?

解决方案

It depends on how many forms you are actually using in your application.
If there are 2-3 forms, it'd be wise to use panels go for show/hide approach because, at a time, you'd show on form & hide the others. So code would be like this,

Panel1.Show();
Panel2.Hide();
Panel3.Hide();


But if there are many forms, you will write so many hide/show (and that is kinda hectic :laugh:).

So, both approaches are good, but use them wisely.

-KR


Seems "common-sense" to say that how many UI elements (Forms, whatever) are completely visible at any one time is going to be related to how much screen "real estate" you, or your end-users, have available. In modern application design, imho, having a bunch of overlapping UI elements is a bad thing.

Yes, you can create a WinForm MenuStrip and use it to control visibility of any/all UI elements: that's straightforward (use the optional CheckBoxes).

I suggest you do not use a Windows Form inside another Windows Form, or inside some other Control sited on a Windows Form. Yes, you can "get away with this," but it is not the way Windows Forms are meant to be used; it's technical waste. And, yes, the old MDI architecture did exactly this, but there are good reasons MDI is a "dinosaur" now.

How you use Forms, or Panels, or other Container Controls to present the different UI elements of your Application, and how you change the appearance, or visibility, or enabled state, of the elements as the user interacts with them at run-time ... those design decisions should be made based on your clear vision of what your application is, how it is meant to be used.

So, I suggest you start by making sketches ... on paper even :) ... of how your application might appear on-screen at different points in its "life-cycle:" how does it appear initially (splash screen ? log-in dialog ? file-open dialog ?, resumes previous saved "state" ?); how does it appear in what you think is the most common mode of use; how does it appear the user saves their work, or quits the application ?

For every Form you show: what is its function ? It it one-of-many "documents" that the user may be working on; is it a tool-palette you want visible some of the time, or all of the time ?

You have to decide if you want an Application with one "Main Form" (the kind created by default if you open a new WinForm project in Visual Studio ... where closing that Main Form will shut down the Applicaton), or an Application with multiple independent Forms where as long as any one of them stays open the Application keeps running (to implement this in WinForms you need to use the Application Context facility).

There are many choices available including using some Container Control, like a TabControl, to selectively present UI elements.

If you ask other questions here about application design, I suggest you give more details, tell us what the application does, tell us more about what the multiple Forms are for.


这篇关于关于在c#中使用表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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