Winform C# equivalent methods to VBA UserForm_Initialize and UserForm_Activate

Giacomo Raucci 321 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

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,272 questions
0 comments No comments
{count} votes

Accepted answer
  1. Michael Taylor 48,581 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