Solved

Windows Form Focus

Posted on 2006-10-23
2
163 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 63

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

735 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