关于SetStyle方法 [英] About the SetStyle method

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

问题描述

(A)我编写了一个窗口表单应用程序,下面有一些组件:
1.主要形式(MainForm).
2.将ToolStripContainer(ToolStripContainer_a)添加到MainForm中.
3.有服务器运行时创建的表单,这些表单将添加到
ToolStripContainer_a.
4.我发现这些表格(A.3以上)不能设置为MainForm的子元素
(即这些表格没有MDI功能),因为这些表格不是
直接添加到MainForm中,但又添加到ToolStripConanier_a中.

(B)我的问题的描述:
1.通常,窗体可以具有SetStyle方法:

(A) I write a window form application, there are components below :
1. a main form (MainForm).
2. a ToolStripContainer (ToolStripContainer_a) which is added into MainForm.
3. there are serveral runtime created forms which will be added into
ToolStripContainer_a.
4. I found that these form (above A.3) can not be set as a child of MainForm
(ie there is no MDI feature for these forms), since these form is not
directly added into MainForm, but is added into ToolStripConanier_a.

(B) The description of my question :
1. normally, a form can have a method of SetStyle, :

form.SetStyle(ControlStyles.DoubleBuffer, true);


2.但是,我想上面A.3中的表单不能具有SetStyle方法. 这是因为这些表格不是"MainForm的子级",是
对吗?
3.如何让那些表格(在A.3以上)具有SetStyle方法,或者是否存在
还有其他方法可以达到相同的功能吗?由于我还将设置不透明度"
这些形式的属性,但是没有用于设置的不透明度"属性.


2. however, the forms, in above A.3, can not have the SetStyle method, I suppose
this is due to that these forms are ''not a child of MainForm'', is that
right ?
3. how can I let those forms (in above A.3) have SetStyle method, or, is there
any other way to reach same function ? Since I also would set the ''Opacity''
attribute of those forms, however there is no ''Opacity'' attribute for setting.

推荐答案

体育,

都错了,抱歉.

让我们从表单之间的父/子关系开始.正式存在这种关系,因为FormControl,所以可以通过Control.ParentControl.Controls建立此关系.但是,对于Forms,此关系被设为不起作用的:尝试使Form实例成为任何子项的尝试时将引发异常.您可以通过将Form.TopLevel设置为false(当然,默认值为true)来违反此规则.最好不要尝试:它看起来很丑陋:整个窗体及其所有非客户区域都是其他窗体或控件(如面板)的子窗体.我不知道什么时候可能有用.它看起来像是在丑陋地违反了预期的UI设计原则.

请参阅 http://msdn.microsoft.com/en-us/library/system .windows.forms.control.aspx [ ^ ].

现在,所有与MdiChild/MdiParent关系无关的关系都可以为您工作,但是使用MDI的整个想法真的很糟糕.参见:
http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages [在WPF中使用MDI窗口的问题 [ ^ ],
MDIContainer提供错误 [ http://msdn.microsoft.com/en-us/library /system.windows.forms.control.setstyle.aspx [ ^ ].

我们开始使用Control.SetStyle进行双重缓冲.您需要添加样式:
System.Windows.Forms.ControlStyles.AllPaintingInWmPaint | System.Windows.Forms.ControlStyles.OptimizedDoubleBuffer;如果您渲染动画或交互式图形,这对于避免闪烁非常重要.

请参阅 http://msdn.microsoft.com/en-us/library/system .windows.forms.controlstyles.aspx [ ^ ].

最后,为Form添加双缓冲和/或透明度属性.它具有自己的属性.您可以简单地使用属性< codeform.doublebuffered>添加双缓冲.并使用< code> Form.TransparencyKey和/或Form.AllowTransparencyForm.Opacity来控制透明度.

请参阅 http://msdn.microsoft.com/en-us/library/system .windows.forms.form.aspx [ ^ ].

我建议您只是更全面地阅读MSDN帮助.这基本上就是您所需要的.

—SA
Sports,

All wrong, sorry.

Let''s start from parent/child relationships between form. Formally, this relationship exist, because Form is Control, so, this relationship could be established via Control.Parent and Control.Controls. For Forms, however, this relationship is made non-functional: an exception will be thrown at the attempt to make a Form instance a child of anything. You can violate this rule by setting Form.TopLevel to false (default is true, of course). Better don''t try it: it looks ugly: the whole form with all its non-client areas as a child of other form or control like a panel. I don''t know the situations when it could be useful. It looks like an ugly violation of intended UI design principles.

See http://msdn.microsoft.com/en-us/library/system.windows.forms.control.aspx[^].

Now, all that has nothing to do with MdiChild/MdiParent relationship, which can work for you, but the whole idea of using MDI is really bad. See:
http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages[^],
Question on using MDI windows in WPF[^],
MDIContainer giving error[^].

Now, about Control.SetStyle. You can use this method for all Controls including Form and in some cases you have to do this. You always can do it and you always have it; why did you say you don''t? Perhaps you did not pay attention that this method is protected. So, you will use it only in the code of you class derived from Control — as simple as that.

See http://msdn.microsoft.com/en-us/library/system.windows.forms.control.setstyle.aspx[^].

We came to use of Control.SetStyle for double buffering. You need to add styles:
System.Windows.Forms.ControlStyles.AllPaintingInWmPaint | System.Windows.Forms.ControlStyles.OptimizedDoubleBuffer; this can be very important if you render animated or interactive graphics, to avoid flicker.

See http://msdn.microsoft.com/en-us/library/system.windows.forms.controlstyles.aspx[^].

Finally, adding double buffering and/or transparency properties for Form. It has its own properties. You can add double buffering simply by using the property <codeform.doublebuffered> and control transparency using <code>Form.TransparencyKey and/or Form.AllowTransparency with Form.Opacity.

See http://msdn.microsoft.com/en-us/library/system.windows.forms.form.aspx[^].

I would advise you just to read MSDN help a bit more thoroughly; that''s basically all you need.

—SA


这篇关于关于SetStyle方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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