获取parentform的控制值 [英] get controlvalues of parentform

查看:75
本文介绍了获取parentform的控制值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我有一个主窗体,默认情况下,该主窗体是我的应用程序所有其他窗体的MDIPARENT,默认情况下,此窗体已打开,并且从此窗体的菜单栏导航到其他窗体
它就像


In my application i have a mainform which is the MDIPARENT of all other forms of my application on login by default this form is opened and from menustrip in this form we are navigating to other forms
itsis like


public partial class MainMenuForm : Form
        {
            public MainMenuForm()
            {
               
                InitializeComponent();
                this.WindowState = FormWindowState.Maximized;
            }
      private void humanResourceToolStripMenuItem_Click(object sender, EventArgs e)
            {
                HumanResourceForm humanresourceform = new HumanResourceForm();
                humanresourceform.MdiParent = this;
                humanresourceform.Show();
    
            }
    
    }



在humanreformform里面,我有一个按钮,它将导航到另一个表单,例如,employeetransferform





inside the humanresourceform i had a button which will navigate to anotherform say employetransferform



private void button1_Click(object sender, EventArgs e)
           {
               Administraror.Humanresource.EmployetransferForm emptranfrm = new    Administraror.Humanresource.EmployetransferForm();

               emptranfrm.ShowDialog();

           }



现在我的问题是在emplyeetransferform内部,我想从Humanresources控件中获取一些值
同样,当员工转移表单处于打开或活动状态时,也不应允许用户关闭人力资源表单

我也想以emplyeetransferform之类的人力资源文本框来获取文本属性,例如



Now my problem is Inside the emplyeetransferform I want to get some values from the controls of Humanresources
also the user should not be allowed to close the humanresourceform when the employee trnsfer form is open or active

I also want to get the textproperty of a textbox of humanresource in emplyeetransferform like

public partial class EmpLoctnChangeForm : Form 
    {
        public EmpLoctnChangeForm( )
        {
            InitializeComponent();
           
        }

        private void EmpLoctnChangeForm_Load(object sender, EventArgs e)
        {
          intemppk= humanresourceform.txtpk.text;
        }
    }




希望所有人都提供一些不错的建议.预先感谢




expecting some nice advice from all Thanks in advance

推荐答案

我建​​议对用户界面和代码进行一些重新设计.

  • 不要在表单之间直接通信.而是对数据和逻辑使用单独的类.如果需要,这些类可能会相互作用.
  • 如果在打开另一个窗体时无法关闭某个窗体,通常,防止关闭的窗体应该是模式对话框,而不是MDI子窗体
  • 如果您不想使用模式对话框,那么我建议您将数据放在单个表单上,可能放在单独的选项卡上.
I would suggest some redesign of the user interface and code.

  • Don''t communicate between the forms directly. Instead use a separate classes for the data and the logic. If needed, these classes may interact.
  • If a form cannot be closed while another form is open, typically the form preventing the close should be a modal dialog, not an MDI child
  • If you don''t want to use a modal dialog, then I would suggest placing the data on single form, possibly on separate tabs.


您始终可以在要访问值的表单上创建公共属性,而只需访问控件的值即可.通常不认为是好的做法,但又好又快.最好使用MVC/MVP模式,其中数据与视图位于单独的类中.

另外,您可以在表单上使用bool公共属性来指示该表单无法关闭.在关闭事件上,检查是否设置了此标志,然后取消关闭.我不会说依赖于对话框必然是一种好习惯,因为可能要与两种形式进行交互,第二种形式是详细的信息形式或其他形式. Microsoft更改其位置的情况是Office中的查找替换"对话框.现在,您可以在查找替换表单和主表单之间切换.
You can always create a public property on form you want access to the values, and just access the control''s value. Not generally considered good practice, but a good quick and dirty. Would be better to use an MVC/MVP pattern where the data is in a separate class from the view.

Also, you can use a bool public property on the form to indicate that form cannot be closed. On the close event check if this flag is set, and cancel the close. I would not say that depending on dialog is necessarily good practice since may want to interact with both forms, the second form being a detailed information form or something else. A case where Microsoft has changed their position is the find replace dialog in Office. Now you can go between the find replace form and the main form.


这篇关于获取parentform的控制值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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