Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4619724
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:27:47+00:00 2026-05-22T02:27:47+00:00

I have a user control on a form that can spawn several non-modal child

  • 0

I have a user control on a form that can spawn several non-modal child forms. The child forms display data that the user can edit. The user control displays a different view of the same data, and I want to be able to spawn a reload of the data if the user has made changes in one or more of the child forms. I already have events set up to notify the user control of data changes in the child forms, but I can’t figure out which event (if it exists) I should capture on the user control to determine that it has gotten focus back from the child form(s). Is there an existing event I can use here?

EDIT: Code sample
(sorry, my client likes VB)

GotFocus only seems to fire when the UserControl is Disposed.

I add the control to a panel on the “main” form like this:

Dim mainControl as New MainUserControl()
Panel1.Controls.Add(mainControl)
mainControl.Doc = DocStyle.Fill
mainControl.Visible = True
mainControl.Show()

Then, the event handler code:

Private Sub MainUserControl_GotFocus(ByVal sender as Object, ByVal e as EventArgs) Handles Me.GotFocus
    MessageBox.Show("got focus")
End Sub

Then, there’s a “close” button on the user control that fires an event back to the main form, which then removes the user control from the panel and disposes it. Only when mainControl.Dispose() is called does GotFocus fire.

EDIT 2
I just tried handling the Enter event, but that only fires the first time and not every time the control receives focus.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T02:27:48+00:00Added an answer on May 22, 2026 at 2:27 am

    The best way to do this that I can find is by handling the parent form’s Activated event in the user control. From all the research I’ve done over the last few hours, I’ve learned that GotFocus is a tricky thing to work with, and that the Winforms user control doesn’t like to have focus at all, because it’s a container control. Say I have a user control MyUserControl that is loaded onto a form called ‘MyControlParentForm’, then the code I’m using is something like this:

    Private Sub MyUserControl_Load(ByVal sender as Object, ByVal e As EventArgs) Handles MyBase.Load
        Dim parent = TryCast(ParentForm, MyControlParentForm)
        If parent IsNot Nothing Then
            AddHandler parent.Activated, AddressOf Control_Activated
        End If
    End Sub
    
    Private Sub Control_Activated(ByVal sender As Object, ByVal e as EventArgs)
        Debug.WriteLine("activated")
    End Sub
    

    Then, if the form loses focus for any reason and then regains it, MyUserControl knows about it through Control_Activated. Hopefully this helps someone in the future.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a view user control that can post form. This control can be
i have a user control that descends from UserControl. When dropped onto the form
I have a user control in a repeater that I need to pass data
I have a user control that is pretty basic. It contains several TextBox controls,
I have a user control that I'm building. It's purpose is to display the
I have a UserControl that consists of three TextBoxes. On a form I can
I have a simple form on a view page, implemented as a user control,
I have several user drawn controls on a form, unfortunately when the form is
I have an ASP.NET web form that has a container usercontrol that hosts several
I have a usercontrol that is meant to take up the entire form. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.