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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top