控件中的嵌入式表单或作为用户控件的表单 [英] Embedded Form in a control or Form as User Control

查看:19
本文介绍了控件中的嵌入式表单或作为用户控件的表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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);
            }

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

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