Solved

Windows Form Focus

Posted on 2006-10-23
2
164 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
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 …

752 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