相关疑难解决方法(0)

用户控件在设计时作为容器

我正在设计一个简单的扩展器控件.

我派生自UserControl,绘制内部控件,构建,运行; 一切都好.

由于内部控件是Panel,我想在设计时将其用作容器.的确,我使用了以下属性:

[Designer(typeof(ExpanderControlDesigner))]
[Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", typeof(IDesigner))] 
Run Code Online (Sandbox Code Playgroud)

太棒了,我说.但它不是......

结果是我可以在设计时将它用作容器,但是:

  • 添加的控件返回已嵌入用户控件中的内部控件
  • 即使我在设计时将顶部控件添加到顶部,在运行时也会再次返回嵌入到用户控件中的控件
  • 我无法在设计时将容器区域限制为Panel区域

我错过了什么?这是完整性的代码...为什么这段代码不起作用?

[Designer(typeof(ExpanderControlDesigner))]
[Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", typeof(IDesigner))] 
public partial class ExpanderControl : UserControl
{
    public ExpanderControl()
    {
        InitializeComponent();
....

[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")] 
internal class ExpanderControlDesigner : ControlDesigner
{
    private ExpanderControl MyControl;

    public override void Initialize(IComponent component)
    {
        base.Initialize(component);

        MyControl = (ExpanderControl)component;

        // Hook up events
        ISelectionService s = (ISelectionService)GetService(typeof(ISelectionService));
        IComponentChangeService c = (IComponentChangeService)GetService(typeof(IComponentChangeService));

        s.SelectionChanged += new EventHandler(OnSelectionChanged);
        c.ComponentRemoving += new ComponentEventHandler(OnComponentRemoving);
    }

    private void OnSelectionChanged(object sender, System.EventArgs e) …
Run Code Online (Sandbox Code Playgroud)

c# user-controls winforms

17
推荐指数
1
解决办法
2万
查看次数

折叠"按钮"以进行拆分容器控制

我在WinForms桌面应用程序中使用Microsoft splitcontainer控件(.net 4/c#/ vs 2010).

我想在spliiter控件的面板之间放一个小按钮(或任何漂亮的UI元素)来折叠其中一个面板.例如,一个"按钮"有两个部分,如果我点击一个部分,右侧面板会折叠,如果我点击另一个部分,左侧面板会折叠.

我怎么能解决这个问题呢?

Thx提前!

.net c# visual-studio-2010 splitcontainer winforms

7
推荐指数
1
解决办法
2万
查看次数