Solved

Windows Form Focus

Posted on 2006-10-23
2
157 Views
Last Modified: 2012-05-05
I have a MDI Parent with child windows included.  When more than one child window is opened the user can click between these windows.  When a user clicks on the window I need it to get focus and change a label value that is on the MDI Parent.  Any suggestions?
0
Comment
Question by:dhathsato
2 Comments
 
LVL 10

Expert Comment

by:Kinger247
ID: 17788084
You need to trigger an event in the child for for the mdi to receive.

Create an MDI called 'MDIForm' which opens 2 forms using withevents, Add a panel and a label in the panel.
With the following code:

Public Class MDIForm

    Private WithEvents form2 As New Form2
    Private WithEvents form3 As New Form3

    Private Sub MDIForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        form2.MdiParent = Me
        form2.Show()

        form3.MdiParent = Me
        form3.Show()
    End Sub

    Private Sub HasFocus(ByVal FormName As String) Handles form2.HasFocus, form3.HasFocus
        Label1.Text = FormName
    End Sub
End Class


Add 2 more forms with default names and add the following code to both (mind the form name)

Public Class Form2
    Public Event HasFocus(ByVal FormName As String)

    Private Sub Form2_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.GotFocus
        RaiseEvent HasFocus(Me.Text)
    End Sub
End Class
0
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 250 total points
ID: 17788929
Hi dhathsato;

All you need to do is in each child form create an event handler called Activated. Add the text to the MDI parent label as shown below. Each child form has a reference to the parent MDI form. Cast that reference to the form type of the MDI parent as shown below.

In the sample code the name of the MDI parent form is MyMDIParent and the MyMDIParent form has a label called Label1. The below code will take the text in the child form title bar text and add it to the label of the MDI parent form.

    Private Sub Child_Activated(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles MyBase.Activated

        CType(Me.MdiParent, MyMDIParent).Label1.Text = Me.Text

    End Sub


Fernando
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now