本文介绍了我如何...使用多个表单常见的Windows表单。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在处理工资单应用程序,在工资单模块中,Advance Entry表单中有一个名为(Employee List)的按钮,当用户点击Employee list按钮时,一个表单就会出现,我想要通过传递像Advance Entry这样的查询来调用该表单,因为这个员工列表表单将以其他形式使用,所以我不想创建特定的表单....任何建议都将被赞赏... I am working on payroll application,In payroll module Advance Entry form is there in that one button named (Employee List), when user click on Employee list button one form will come, I want to call that form by passing query like "Advance Entry" because this employee list form will be used in other forms, so I don't want to create particular form....Any suggestions will be appreciated...推荐答案 private void MainForm_Load(object sender, EventArgs e){ TheCommonForm = new CommonForm();} 3。当任何表格需要显示'CommonForm'时 MainForm.TheCommonForm.Show(); 然后,当然,您需要考虑在'CommonForm实例中需要公开哪些元素/数据/控件,以便显示它的任何表单都可以访问它需要访问的内容。 如果您需要在显示时将自定义数据传递到'CommonForm实例中,您可以定义一个自定义的'Show运算符,如下所示:3. When any Form needs to display the 'CommonForm"MainForm.TheCommonForm.Show();Then, of course, you will need to consider what elements/data/Controls you need to expose in the instance of 'CommonForm so that any Form which displays it can access what it needs to access.If you need to pass custom data into the instance of 'CommonForm when you display it, you can define a custom 'Show operator like this:// in 'CommonFormprivate List<string> Data { set; get; }public void Show(List<string> data = null){ if (data != null) Data = data; base.Show();}在这个简短的例子中,任何显示'CommonForm的Form都可以传递一个字符串类型数据列表供'CommonForm中的内部使用:如果没有传入数据(Show with 'null,或空列表),然后内部'数据列表(如果有的话)保持原样。 如果你希望'CommonForm执行一个查询然后将查询结果返回到另一个表单或表单,可以通过多种方式处理,包括: 1.让'CommonForm定义一个事件到任何感兴趣的表单都可以订阅,该事件返回查询会导致继承自EventArgument或其他数据结构的自定义类。 2.通过引用传递数据结构到'CommonForm,并在'CommonForm'处理之后使用修改过的数据结构。 再一次,有很多方法可以解决这个问题,并且不知道你的场景更详细,这里的例子不能声称是b est practice。In this brief example, any Form that displays the 'CommonForm can pass a List of string Type data in for internal use in 'CommonForm: if no data is passed in (Show called with 'null, or an empty List), then the internal 'Data list (if any) is left as-is.If you wished the 'CommonForm to execute a query and then return query results to another Form, or Forms, that can be handled a number of ways, incluiding:1. have the 'CommonForm define an Event to which any interested Form can subscribe, with that Event returning query results in a custom Class inheriting from EventArgument, or other data structure.2. pass a data structure by reference to the 'CommonForm, and use the modified data structure after it is handled by 'CommonForm.Again, there are many ways you might go about this, and without knowing your scenario in more detail, the example here cannot claim to be "best practice." 这篇关于我如何...使用多个表单常见的Windows表单。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-31 00:11