Winform C# equivalent methods to VBA UserForm_Initialize and UserForm_Activate

Giacomo Raucci 366 Reputation points
2021-11-19T20:05:03.767+00:00

I am in the process of converting Excel VBA Userforms (Excel 2010) to Winform C# Winforms. With VBA Userforms, there is a USERFORM_INITIALIZE sub and USERFORM_ACTIVATE sub. Is there an equivalent method for the 2 VBA subroutines? I am using Visual Studio 2019. Thank you, Jack

Developer technologies | Visual Basic for Applications
Developer technologies | ASP.NET | Other
0 comments No comments
{count} votes

Answer accepted by question author
  1. Michael Taylor 61,116 Reputation points
    2021-11-19T20:39:11.197+00:00

    The closest equivalent to the UserForm_Initialize is OnLoad. This method is called just before the form is displayed the first time and is where you want to do any runtime initialization of your UI, such as loading data. You could also use the less common OnShown method if you wanted.

    The equivalent to UserForm_Activate is OnActivated. It is called when the form is given input focus. However it depends upon what you're doing inside that handler as to whether this is the best method to use or not.

    The following doc provides the order in which events/methods are called in Winforms to help you determine where you should put your code. In some cases you may have several options.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.