在派生形式中编辑VS 2013设计器中的控件 [英] Edit controls in VS 2013 designer in a derived form

查看:114
本文介绍了在派生形式中编辑VS 2013设计器中的控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在使用Visual Studio 2013进行C#解决方案。

现在我从Form1中导出了Form2项目。在Form1中是一个TableLayoutPanel,包含一行中的几个按钮。所有控件都设置为受保护。



为什么我不能在设计器窗口中编辑属性?

它适用于其他控件在同一个小组中,来自更高级别。



非常感谢您提前!



我尝试过的事情:



我也试过公开让所有人参加。

进一步调查显示问题是TableLayoutPanel而不是按钮。当我将它们拖出那里时它们工作正常。

这个控件一般都有故障吗?或者它可能甚至打算像这样行事???

Hello everybody,

I'm using Visual Studio 2013 for a C# solution.
Now I derived Form2 from Form1 within one project. In Form1 is a TableLayoutPanel containing several buttons in a row. all controls are set to protected.

Why can I not edit the properties in the designer window?
It works fine for the other controls in the same panel that are derive from an even higher class.

Thank you very much in advance!

What I have tried:

I also tried public for all in between.
Further investigations have shown that the problem is TableLayoutPanel and not the buttons. They work fine when I drag them out of there.
Does this control have a malfunction in general? OR is it maybe even inteded to behave like this???

推荐答案

编辑...在查阅我的笔记之后......



MS明确警告使用从表格中继承TableLayoutPanel的Form:
edit ... after consulting my notes ...

MS clearly warns about using a Form that inherits from a Form with a TableLayoutPanel on it:
The TableLayoutPanel control does not support visual inheritance in the Windows Forms Designer. A TableLayoutPanel control in a derived class appears as "locked" at design time.

[ ^ ]。实际上,现在这有点奇怪,因为在继承表格中出现的表单中定义的每个Control都将显示为已锁定。



我建议你阅读仔细阅读MS doc页面,并注意关于TableLayoutPanel使用的注意事项和建议。



我强烈建议你不要尝试使用TableLayoutPanel作为网格的替代品。如果你需要一个网格,搜索CodeProject,并检查一些有趣的自定义控件,如Philippe Piper的



你所观察到的,不幸的是,只是事情是在Windows窗体中。默认情况下,从另一个继承的Form / UserControl / Component锁定它继承的Controls。



我刚刚在C#论坛上就这个问题给出了一个冗长的答案;我认为它可能对您有所帮助:[ ^ ]。它显示了一种获取对继承控件的引用的技术。



而且,是的,TableLayoutPanel存在特定的问题,我需要回到我的笔记中去更清楚地描述。我今天晚些时候会回答你的问题。 TableLayoutPanel的具体问题包括AutoSize和AutoScroll的问题。



顺便说一句,关于使用WinForms Designer,绝对没有错误或第二类创建/实现用户界面设计,Visual Studio提供了一组功能强大的工具,可帮助您定位和对齐控件,将它们捕捉到网格等。

[^]. Now that's a bit strange, actually, because every Control defined in a Form that appears in an inheriting Form is going to appear "locked."

I suggest you read the above MS doc page carefully and note the number of cautions, and suggestions, regarding the use of the TableLayoutPanel.

I strongly suggest you don't attempt to use the TableLayoutPanel as a substitute for a "Grid." If you need a Grid, search on CodeProject, and examine some of the interesting custom Controls written about, like Philippe Piper's

What you observe is, unfortunately, just the "way things are" in Windows Forms. A Form/UserControl/Component that inherits from another locks the Controls it inherits ... by default.

I just gave a lengthy answer to a question on the C# forum about this issue; I think it may be helpful for you: [^]. It shows a technique for getting a reference to an inherited Control.

And, yes, there are specific problems with the TableLayoutPanel that I need to go back to my notes to describe more clearly. I will respond later today to your question. Specific problems with TableLayoutPanel include problems with AutoSize, and AutoScroll.

By the way, there's absolutely nothing "wrong," or "second class," about using the WinForms Designer to create/implement your user-interface design, and Visual Studio provides a powerful set of tools for helping you position, and align, Controls, snapping them to the "grid," etc.


正如您可以看到表单答案和注释,这是一个您需要编写自己的代码或以不同方式执行的区域,因为设计人员不能正确支持该方案。



解决方案1很好地解释了这个问题。我将尝试给出一些可能对您有用的解决方法。



根据实际的用户界面,可能会有不同的解决方案...



对于按钮,使用流布局而不是表格布局可能会更好。如果只有几个按钮对于所有派生表单都不可见,那么在基本表单中包含所有按钮可能更简单但隐藏那些不适用的按钮。



或者基本表单可能基本上具有空UI和受保护的实现函数,这些函数将用于代码共享目的。这样,每个表单都有自己的UI,可以根据需要进行自定义。



或者,您可以使用用户控件重用某些控件一起。但是,在某些情况下正确对齐控件可能更难,比如直接在窗体上对齐嵌入式按钮。



另一种解决方案是使用代码修改派生形式。因此,您可以使用设计器生成所需的布局,然后提取生成的代码以进行额外控制,并将该代码移动到派生类中。所以设计师只会用于初始设计。之后,所有修改都必须在代码中完成。
As you can see form answers and comments, this is an area in which you need to write your own code or do it differently as that scenario is not properly supported by the designer.

Solution 1 explain the problem quite well. I will try to give some workaround that might help you.

Depending on the actual UI, there might be different solutions...

For buttons, using flow layout instead of table layout might works better. It might be simpler to have all buttons in the base form but hide those that do not applies if you have only a few buttons that are not visible for all derived forms.

Or the base form might have essentially an empty UI and protected implementation functions that would be used for code sharing purpose. That way, each form have there own UI that can be customized as desired.

Alternatively, you might use user controls to reuse some controls together. However, it might be harder to properly align controls in some cases like aligning an embedded button with one directly on the form.

Another solution would be to use code to modify derived forms. Thus you can use the designer to generate desired layout and then extract generated code for extra controls and move that code in derived classes. So the designer would be used only for initial design. Afterward, all modification would have to be done in code.


这篇关于在派生形式中编辑VS 2013设计器中的控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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