控件中的嵌入式表单或作为用户控件的表单

Embedded Form in a control or Form as User Control(控件中的嵌入式表单或作为用户控件的表单)
本文介绍了控件中的嵌入式表单或作为用户控件的表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Okay I have a large CRUD app that uses tabs with Forms embedded in them like so -->

public static void ShowFormInContainerControl(Control ctl, Form frm)
    {
        frm.TopLevel = false;
        frm.FormBorderStyle = FormBorderStyle.None;
        frm.Dock = DockStyle.Fill;
        frm.Visible = true;
        ctl.Controls.Add(frm);
    }

I then call the below in the Form Load event of the Parent Form -->

 // Embedd the child form in the this Parent
        WinFormCustomHandling.ShowFormInContainerControl(pnlModuleHost, _frmWWCModuleHost);

This was given to me HERE in response to my previous question.

As I have progressed in this I keep getting the nausiating feeling that multiple layers of embedded Forms are a disaster waiting to happen and User Controls keep popping up. Can anyone offer me some concrete advice on using user controls vs embedding forms?

See my previous question for the inspiration to this one. HERE

Also a screen shot of what my current embedded form layout looks like in action can be found HERE.

Thank You

解决方案

I would use a UserControl, its think there just simpler, you can see whats going on in the designer (if you want), Form has bunch of stuff you'll never need if your just going to use it as a view within a container.

Compare this to your method:

public static void DockControl(this Control control, UserControl userControl)
            {
                userControl.Dock = DockStyle.Fill;
                control.Controls.Clear();
                control.Controls.Add(userControl);
            }

这篇关于控件中的嵌入式表单或作为用户控件的表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)