preferred way to access mainform

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I need to access some components on my main form. I found out that making a
static public variable it is accessible. It has to be from several forms,
so I dont want to pass a reference of main form to all of them. Is thsi a
preferred way of coding ?

partial class Main: Form
{
static public Main MainForm;

public Main()
{
InitializeComponent();
MainForm = this;
 
Hi,

I don't know your context, but guess this would work.

Use the child form's MdiParent property to get the main form, and cast it to
the requried type to access the components.

HTH,
Rakesh Rajan
 
Back
Top