Click here to Skip to main content
13,196,730 members (61,775 online)
Rate this:
Please Sign up or sign in to vote.
See more:

I am new to

I have three form.The first one is Main form (Mainform) which wil created multiple form of (Mpfform). Each Mpfform can create only one (Dmfform). Dmfform contain one "Start" button. The problem is when i click "Start" button in one of Dmfform, all the buttons event in other Dmfform will be trigger as well. What is the problem here? I only want the button clicked in that particular form to trigger.The code below is the button event in Dmfform .

Private Sub Start_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Start.Click
        If Me.NewModbusSetting.DGV_AddVariable.RowCount <> Nothing Then
            Me.mytimer3.Interval = 1000
            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

and the code below for how i created Dmfform window.

Public Newdisplaymode As New Dmfform
    Private Sub DataDisplayModeMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataDisplayModeMenuItem.Click
        Newdisplaymode.Text = "Display Measurement: " & Me.Text
    End Sub

and the code below is when i created Mpfform

Public mpf(30) 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()
        mpf(num).Text = "ModbusPoll:" & CStr(num)
        mbv.Text = "Modbuspoll Values:" & CStr(num)
        mpf(num).Name = "ModbusPollFormFull" & num
        mpf(num).TopLevel = False
End Sub

Thanks in advance
Posted 10-Jan-13 23:41pm
Updated 17-Jan-13 2:08am
Sergey Alexandrovich Kryukov 11-Jan-13 13:24pm
Not clear. What do you mean by "X" Forms and "X" Windows. (I believe it's not X Windows :-)
Sergey Alexandrovich Kryukov 11-Jan-13 13:27pm
When you say "will be trigger as well", you only assume what you say, you don't observe it directly (I can explain it). You need to tell us what happens in the terms of something really observable. First of all, use the debugger — you will see everything.


1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Please see my comments to the question.

Sorry for giving you somewhat incomplete answer, but I hope it' be enough for you to address and resolve your problem.

Your observation itself is not quite correct, and not because you could not see what's going on, but by a more basic reason: there is no such concept as "trigger a button". Here is what happens in fact: the button class has an event instance Click. What you do is: you add your handler to the event invocation list of the event instance of one and only one instance of your button. Unlike "regular" delegate instanced, the event instance is very strictly limited in use; and the only purpose of the separate concept of event is the set of limitation. One important limitation is this: nothing can invoke the event instance except the code of the declaring class, that is, the class where this event is declared. And again, nothing can invoke the event instance from the code of some other object. In the case of Click, only a physical click on the button can invoke your event instance, and nothing else, and of course, never a click on some other button or other control.

Now, you might disagree and ask, how come you still can have the mess you have? The answer is very simple: all of the above does not mean that nothing can call the particular event handle you used to add to some event instance invocation list. Are you getting the idea? This handler is just some method, and some other code could call it, especially if this is a named method (that is one of the reasons that I most usually advise in favor of using anonymous methods; in VB.NET, it can be used via AddHandle). Potentially, you could, accidentally or my conceptual confusion, add the same method to the invocation lists of different event instances. I just listed two possible reasons for your problem.

And here is the third possible reason: it could be just the side effect of the code of the event handler. For example, if you call MsgBox from different event handles (not really a good idea), it may look the way you don't really see where it was actually called from.

You can really easily find the ends if you simply execute it all under the debugger. When you execution comes into the body of some handler method, don't forget such a powerful tool as "Call Stack" — it will immediately show you where the call comes from.

I really hope you will do the rest by yourself.

Good luck,
juita 16-Jan-13 5:12am
thank you for your answer..ill try to solve it from here...
Sergey Alexandrovich Kryukov 16-Jan-13 13:31pm
Great. And when and if you see it makes sense, please don't forget to accept it formally (green button).
If not, or if you still have issues or further questions, you are welcome to ask, of course.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.171019.1 | Last Updated 17 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100