自定义类处理的形式嵌入 [英] Custom Class for dealing with embedding in Forms

查看:170
本文介绍了自定义类处理的形式嵌入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在,我继承并扩展部分C#中的自定义类文件。我想的重系数的现在,因为我有刚够诀窍知道,喜欢的东西的泛型的(我认为)我可以极大地压缩此类。

I have a custom class file in C# that I inherited and partially extended. I am trying to re factor it now as I have just enough knowhow to know that with something like generics(I think) I could greatly condense this class.

作为一个没有经验的个人开发我将不胜AP preciate任何指示或建设性critism任何可以提供。

As an inexperienced solo dev I would greatly appreciate any direction or constructive critism any can provide.

不要温柔!我AP preciate你的时间,并有一个幸福的一天!我是preemptively遗憾的长度。

Don't be gentle! I appreciate your time and have a blessed day! I am preemptively sorry for the length.

using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraTab;

namespace psWinForms
{
    public static class WinFormCustomHandling
    {
        public static void ShowXFormInControl(Form frm, 
            ref XtraTabPage ctl, FormBorderStyle style)
        {
            frm.TopLevel = false;
            frm.ControlBox = false;
            frm.Parent = ctl;
            frm.FormBorderStyle = style;
            frm.Left = 0;
            frm.Top = 0;
            frm.Width = ctl.Width + 4;
            frm.Dock = DockStyle.Fill;
            frm.Show();

            //IMPORTANT: .Show() fires a form load event
            frm.BringToFront();
        }

        public static void ShowXFormInControl(Form frm, 
            ref XtraPanel ctl, FormBorderStyle style)
        {
            frm.TopLevel = false;
            frm.ControlBox = false;
            frm.Parent = ctl;
            frm.FormBorderStyle = style;
            frm.Left = 0;
            frm.Top = 0;
            frm.Width = ctl.Width + 4;
            frm.Dock = DockStyle.Fill;
            frm.Show();
            //IMPORTANT: .Show() fires a form load event
            frm.BringToFront();

        }

        public static void ShowXFormInControl(XtraForm Xfrm, 
            ref XtraTabPage ctl, FormBorderStyle style)
        {
            Xfrm.TopLevel = false;
            Xfrm.ControlBox = false;
            Xfrm.Parent = ctl;
            Xfrm.FormBorderStyle = style;
            Xfrm.Left = 0;
            Xfrm.Top = 0;
            Xfrm.Width = ctl.Width + 4;
            Xfrm.Dock = DockStyle.Fill;
            Xfrm.Show();
            //IMPORTANT: .Show() fires a form load event
            Xfrm.BringToFront();

        }

        public static void ShowXFormInControl(XtraForm Xfrm, 
            ref XtraPanel ctl, FormBorderStyle style)
        {
            Xfrm.TopLevel = false;
            Xfrm.ControlBox = false;
            Xfrm.Parent = ctl;
            Xfrm.FormBorderStyle = style;
            Xfrm.Left = 0;
            Xfrm.Top = 0;
            Xfrm.Width = ctl.Width + 4;
            Xfrm.Dock = DockStyle.Fill;
            Xfrm.Show();
            //IMPORTANT: .Show() fires a form load event
            Xfrm.BringToFront();

        }

        public static void ShowFormInControl(Form frm, 
            ref Panel ctl, FormBorderStyle style)
        {
            {
                frm.TopLevel = false;
                frm.ControlBox = false;
                frm.Parent = ctl;
                frm.FormBorderStyle = style;
                frm.Left = 0;
                frm.Top = 0;
                frm.Width = ctl.Width + 4;
                frm.Dock = DockStyle.Fill;
                frm.Show();
                //IMPORTANT: .Show() fires a form load event
                frm.BringToFront();
            }
            //.SetBounds(ctl.Left, ctl.Top, ctl.Width, ctl.Height)
        }
        public static void ShowFormInControl(Form frm, 
            ref TabPage ctl, FormBorderStyle style)
        {
            {
                frm.TopLevel = false;
                frm.ControlBox = false;
                frm.Parent = ctl;
                frm.FormBorderStyle = style;
                frm.Left = 0;
                frm.Top = 0;
                frm.Width = ctl.Width + 4;
                frm.Dock = DockStyle.Fill;
                frm.Show();
                //IMPORTANT: .Show() fires a form load event
                frm.BringToFront();
            }
        }
        public static void ShowFormInControl(Form frm, 
            Panel ctl, FormBorderStyle style, FormWindowState state)
        {
            {
                frm.TopLevel = false;
                frm.ControlBox = false;
                frm.Parent = ctl;
                frm.FormBorderStyle = style;
                frm.Left = 0;
                frm.Top = 0;
                frm.Width = ctl.Width + 4;
                frm.WindowState = state;
                frm.Dock = DockStyle.Fill;
                frm.Show();
                //IMPORTANT: .Show() fires a form load event
                frm.BringToFront();
            }
            //.SetBounds(ctl.Left, ctl.Top, ctl.Width, ctl.Height)
        }
        public static void ShowFormInControl(Form frm, 
            TabPage ctl, FormBorderStyle style, FormWindowState state)
        {
            {
                frm.TopLevel = false;
                frm.ControlBox = false;
                frm.Parent = ctl;
                frm.FormBorderStyle = style;
                frm.Left = 0;
                frm.Top = 0;
                frm.Width = ctl.Width + 4;
                frm.WindowState = state;
                frm.Dock = DockStyle.Fill;
                frm.Show();
                //IMPORTANT: .Show() fires a form load event
                frm.BringToFront();
            }
        }
        public static void ShowFormInControl(Form frm, 
            ref Panel ctl, FormBorderStyle style, int left, int top)
        {
            {
                frm.TopLevel = false;
                frm.ControlBox = false;
                frm.Parent = ctl;
                frm.FormBorderStyle = style;
                frm.Left = left;
                frm.Top = top;
                frm.Width = ctl.Width + 4;
                frm.Dock = DockStyle.Fill;
                frm.Show();
                //IMPORTANT: .Show() fires a form load event
                //.Activate()
                frm.BringToFront();
            }
            //.SetBounds(ctl.Left, ctl.Top, ctl.Width, ctl.Height)
        }
        public static void ShowFormInControl(Form frm, 
            ref TabPage ctl, FormBorderStyle style, int left, int top)
        {
            {
                frm.TopLevel = false;
                frm.ControlBox = false;
                frm.Parent = ctl;
                frm.FormBorderStyle = style;
                frm.Left = left;
                frm.Top = top;
                frm.Width = ctl.Width + 4;
                frm.Dock = DockStyle.Fill;
                frm.Show();
                //IMPORTANT: .Show() fires a form load event
                //.Activate()
                frm.BringToFront();
            }
        }
        public static void ShowFormInControl(Form frm, 
            Panel ctl, FormBorderStyle style, int left, int top, string title)
        {
            {
                frm.TopLevel = false;
                frm.ControlBox = false;
                frm.Parent = ctl;
                frm.FormBorderStyle = style;
                frm.Left = left;
                frm.Top = top;
                frm.Width = ctl.Width + 4;
                frm.Text = title;
                frm.Dock = DockStyle.Fill;
                frm.Show();
                //IMPORTANT: .Show() fires a form load event
                frm.BringToFront();
            }
            //.SetBounds(ctl.Left, ctl.Top, ctl.Width, ctl.Height)
        }
        public static void ShowFormInControl(Form frm, 
            TabPage ctl, FormBorderStyle style, int left, int top, string title)
        {
            {
                frm.TopLevel = false;
                frm.ControlBox = false;
                frm.Parent = ctl;
                frm.FormBorderStyle = style;
                frm.Left = left;
                frm.Top = top;
                frm.Width = ctl.Width + 4;
                frm.Text = title;
                frm.Dock = DockStyle.Fill;
                frm.Show();
                //IMPORTANT: .Show() fires a form load event
                frm.BringToFront();
            }
        }
    }
}



我有可恨时间发帖code在这里,它转向了寻找体面!

I have the darnedest time posting code here and it turning out looking decent!

推荐答案

您不需要一般要做到这一点:

You don't need generic to do this:

public static void ShowFormInControl(Control ctl, Form frm) {
  frm.TopLevel = false;
  frm.FormBorderStyle = FormBorderStyle.None;  // Others rarely make sense
  frm.Dock = DockStyle.Fill;
  frm.Visible = true;
  ctl.Controls.Add(frm);
}

使用范例:

public Form1() {
  InitializeComponent();
  ShowFormInControl(this.panel1, new Form2());
}

这篇关于自定义类处理的形式嵌入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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