Modify Toolstripstatuslabel.Text of a parent MDI form from another child, and only the active MDI

0

Basically I have a project with MDI forms, one is father and the others children , the idea is that from MDI son they can modify the text of a toolstripstatuslabel that is part of a status bar has the parent form. The difficult thing would be that only the active form, son, is the one that can perform this action and that the others can not do it. An example would be: I have a project similar to the notepad, the parent form contains a status bar of how many lines the active document has, and there are three child forms containing a multilinear textbox, each containing different text. The idea is to show in your status bar the number of lines that have the text of the selected document or active form. And when this changes the bar update the corresponding data to the selected one. A code that I could do quite basic is the following! in child form:

  

TryCast (Me.MdiParent, Form1). updated ("works")

And in the father:

  

Public Sub updated (text As String)           toolstripstatuslabel.Text = text       End Sub

The code works but it lacks the active condition, which only the ActiveMdiChild is the only layers to modify toolstripstatuslabel.text

Any ideas?

    
asked by Bernardo Harreguy 25.10.2017 в 00:53
source

1 answer

0

I found this solution! a global SUB in a module. would be the following:

Public Sub mostrarmensaje(formulariohijo As Form, mensaje As String, Optional fondo As Integer = 0)
    If System.Windows.Forms.Application.OpenForms.Item(FORMULARIOPADRE.Name).ActiveMdiChild Is formulariohijo Then
        Dim informacion As ToolStripStatusLabel = DirectCast(formulariohijo.MdiParent, Sistema_TPV).informacionadicinallabel
        informacion.Text = mensaje
        Select Case fondo
            Case 1
                informacion.ForeColor = System.Drawing.Color.Green
            Case 2
                informacion.ForeColor = System.Drawing.Color.Orange
            Case 3
                informacion.ForeColor = System.Drawing.Color.Red
        End Select
    End If
End Sub

Where it says "FATHER FORM" would be the parent form or the name of the parent form. The sub is called by all the child forms, and only those that are active will work! I hope someone serves you!

    
answered by 25.10.2017 / 19:21
source