Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Windows Form Focus

Posted on 2006-10-23
2
Medium Priority
?
168 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 64

Accepted Solution

by:
Fernando Soto earned 1000 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

Independent Software Vendors: 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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

688 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