473,505 Members | 15,036 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

preferred way to access mainform

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;

--
rgds, Wilfried
http://www.mestdagh.biz
Nov 17 '05 #1
2 2237
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

"Wilfried Mestdagh" wrote:
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;

--
rgds, Wilfried
http://www.mestdagh.biz

Nov 17 '05 #2
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

"Wilfried Mestdagh" wrote:
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;

--
rgds, Wilfried
http://www.mestdagh.biz

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2397
by: Sabine Oebbecke | last post by:
Hi Experts! I have several forms and reports where controls get their values with 'Forms!MainForm!Control' or 'Forms!MainForm!Subform!Control' resp 'Forms!MainForm!Subform.Form!Control' which...
1
2049
by: Terry | last post by:
Hello, Has anyone experienced the following problem following an Upsize from Access 97 to SQL 2000 using the MS Upsize Wizard? Or can anyone see what the problem might be. Before Upsize...
3
17892
by: Ray Stevens | last post by:
How do you access properties of the main program's class from another form? There does not apear to be an instance variable that can be used.
0
293
by: Wilfried Mestdagh | last post by:
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 ...
4
4033
by: sitemap | last post by:
Hello. I have a problem to accessing the right clindNodes from the xml. I have many "step" elements with id. I want to get the attributes from the 5 "matrix" elements, depending on parent...
5
1199
by: petergi | last post by:
Hello. I have a windows forms application (.NET 3.0) where I have a user control ( a sort of spine) on a Form (called imaginatively enough MainForm). In the spine I make a call to a WCF service...
13
3701
by: magickarle | last post by:
Hi, I got a pass-through query (that takes about 15 mins to process) I would like to integrate variables to it. IE: something simple: Select EmplID from empl_Lst where empl_lst.timestamp between...
10
1608
by: =?Utf-8?B?MjJQb20=?= | last post by:
Hi All, Thanks to Family Tree Mike I've managed to get a Solution up and running, now comes the fun part. How do I call forms from other Class Libraries and how do I use a Background form...
7
3471
by: rquintal | last post by:
I could not find a good method to pass a where clause or openargs to a report named in a call to stephen Lebans' fine reportToPDF utility.l. Do you have a good method to pass a PK to the report...
0
7216
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7303
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7018
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4699
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.