处理创建的多个表单中的表单 - 对发件人表单进行寻址 [英] Handling form in multiple forms created -Addressing the sender form

查看:85
本文介绍了处理创建的多个表单中的表单 - 对发件人表单进行寻址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我是vb.net的新手。我有三种形式。

第一种是MDIparent格式(Mainform) )将创建无限MDIchild形式的(Mpfform).Mpfform包含数据网格视图。

每个Mpfform只能创建一个(Dmfform -non MDI)。

Dmfform包含一个开始按钮。



我的问题是,我如何处理由Mainform创建的特定Mpfform或从特定Mpfform创建的
Dmfform?



我尝试过使用下面的代码但没有成功。请帮帮我。



1)Mainform中的代码:创建Mpfform



 公共 mpf( 50  As  Mpfform()
公共 num 作为 整数 = 0

私有 Sub NewMenuItem_File_Click( ByVal sender As System。 Object ByVal e As System.EventArgs)句柄 NewMenuItem_File.Click

num + = 1
mpf(num)= Mpfform()

' 创建Mpfform

mpf(num).Text = ModbusPoll:& CStr (num)
mpf(num).Name = ModbusPollFormFull& num

' 创建Dmfform
mpf(num).dmf .Text = 显示模式:& CStr (num)
mpf(num).dmf.Name = 显示模式:& num

' 仅显示Mpfform
mpf(num)。 TopLevel = False
mpf(num).BringToFront()
mpf(num).Show()


结束 Sub









2)Mpfform中的代码 - 显示Dmfform



 公开 dmf 作为  Dmfform 

私有 Sub DataDisplayModeMenuItem_Click( ByVal 发​​件人作为系统。对象 ByVal e As System.EventArgs)句柄 DataDispl ayModeMenuItem.Click

dmf.Show()

结束 Sub





3)Dmfform中的代码 - 解决问题



 私有  Sub  Start_Click( ByVal 发​​件人作为系统。对象 ByVal  e  As  System.EventArgs)句柄 Start.Click 

如果 Mainform.mpf(Mainform.num).Datagridview.RowCount<> Nothing 然后

.mytimer3.Interval = 1000
.mytimer3.Start()
Else
MsgBox( 定义modbus属性目前不可用。& vbNewLine& 请在Measurement中定义属性窗口:通信>> Modbus属性

结束 如果

结束 Sub





我如何在这段代码中找到正确的Mpfform DGV?



Mainform.mpf(Mainform。 NUM ).Datagridview.RowCount?

解决方案

首先,你根本不应该对DGV进行处理 - 它会锁定两个独立的对象mpfform和 dmfform在一起,所以你不能改变它们的工作方式而不考虑对另一方的影响。你应该通过掩盖内部工作的属性来工作。



我会做一些不同的事情:我会在dmfform中创建一个创建的mpfform实例的事件它处理。当事件由dmfform发出信号时,事件处理程序将在dmfform实例中设置一个属性(它甚至不需要保存实例,因为它可以使用 sender 事件参数,用于标识要求数据的确切实例。



另一个解决方案更简单,但更麻烦。每个控件(和表单是一个Control)有一个Tag属性 - 当你创建一个dmfform的实例时,你可以将它的标签设置为创建它的mpfform。然后dmfform可以读取Tag,将其转换为mpfform实例并使用属性来读取DGV计数。这很讨厌,因为它要求每个dmfform都是由mpfform(或者是从mpfform派生的类)创建的,并且不能在其他地方轻易重用。


< blockquote>以下是这个想法:谁需要MDI?为什么要折磨自己并吓跑你的用户?

帮自己一个大忙:根本不要使用MDI。你可以更容易实现设计出来,质量更好。 MDI甚至被微软高度劝阻,事实上,微软将其从WPF中删除并且很难支持它。更重要的是,如果您使用MDI,您将吓跑所有用户。只是不要。请参阅:

http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages [ ^ ],

如何在WPF中创建MDI父窗口? [ ^ ]。



我可以解释做什么。请看我过去的答案:

如何在WPF中创建MDI父窗口? [解决方案2 ],

关于在WPF中使用MDI窗口的问题 [ ^ ],

麦当劳给出错误 [ ^ ],

如何设置子窗体最大化,最后一个子窗体最小化 [ ^ ]。



-SA

Hi,

I am new to vb.net.I have three form.
The first one is MDIparent form (Mainform) which will created unlimited MDIchild form of (Mpfform).Mpfform contain Data Grid View.
Each Mpfform can create only one (Dmfform -non MDI).
Dmfform contain one "Start" button.

My problem is, how can i address the specific Mpfform created by Mainform or
Dmfform created from specific Mpfform?

Ive tried using my code below with no success. Please help me.

1) code in Mainform : to create Mpfform

Public mpf(50) As Mpfform()
Public num As Integer = 0
 
Private Sub NewMenuItem_File_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewMenuItem_File.Click
 
        num += 1
        mpf(num) = New Mpfform()
 
'creating Mpfform

        mpf(num).Text = "ModbusPoll:" & CStr(num)
        mpf(num).Name = "ModbusPollFormFull" & num

'creating Dmfform
        mpf(num).dmf.Text = "Display Mode:" & CStr(num)
        mpf(num).dmf.Name = "Display Mode:" & num
 
'showing only Mpfform
        mpf(num).TopLevel = False
        mpf(num).BringToFront()
        mpf(num).Show()
  
 
End Sub





2) code in Mpfform - Showing Dmfform

Public dmf As New Dmfform

Private Sub DataDisplayModeMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataDisplayModeMenuItem.Click
 
        dmf.Show()
        
End Sub



3)code in Dmfform - addressing problem

Private Sub Start_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Start.Click
        
        If Mainform.mpf(Mainform.num).Datagridview.RowCount <> Nothing Then
        
            Me.mytimer3.Interval = 1000
            Me.mytimer3.Start()
        Else
            MsgBox("Definition of the modbus properties is currently not available." & vbNewLine & "Please define the properties in the Measurement window : Communication >> Modbus Properties")

        End If
       
End Sub



How can i address the correct DGV of Mpfform to this code?

"Mainform.mpf(Mainform.num).Datagridview.RowCount" ?

解决方案

First off, you shouldn''t be addressing the DGV at all - it locks the two separate objects "mpfform" and "dmfform" together, so you can''t change how they work without considering the effects on the other. You should be working via properties which mask the inner workings.

I would do things a little differently: I would create an Event in the dmfform which the mpfform instance that creates it handles. When teh event was signalled by the dmfform, the event handler would set a property in the dmfform instance (it doesn''t even need to save the instance(s) since it can use the sender Event parameter to identify the exact instance that is asking for the data.

The other solution is simpler, but nastier. Every Control (and Form is a Control) has a Tag property - when you create an instance of a dmfform you can set it''s Tag to the mpfform that created it. The dmfform can then read the Tag, cast it to an mpfform instance and use a property to read the DGV count. It''s nasty, because it requires that each dmfform is created by a mpfform (or by a class derived from mpfform) and can''t be easily reused somewhere else.


Here is the idea: who needs MDI, ever? Why torturing yourself and scaring off your users?
Do yourself a great favor: do not use MDI at all. You can do much easier to implement design without it, with much better quality. MDI is highly discouraged even by Microsoft, in fact, Microsoft dropped it out of WPF and will hardly support it. More importantly, you will scare off all your users if you use MDI. Just don''t. Please see:
http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages[^],
How to Create MDI Parent Window in WPF?[^].

I can explain what to do instead. Please see my past answers:
How to Create MDI Parent Window in WPF? [Solution 2],
Question on using MDI windows in WPF[^],
MDIContainer giving error[^],
How to set child forms maximized, last childform minimized[^].

—SA


这篇关于处理创建的多个表单中的表单 - 对发件人表单进行寻址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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