473,569 Members | 2,698 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()
{
InitializeCompo nent();
MainForm = this;

--
rgds, Wilfried
http://www.mestdagh.biz
Nov 17 '05 #1
2 2246
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()
{
InitializeCompo nent();
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()
{
InitializeCompo nent();
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
2403
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 works without any problem in Acc97, 2000 and 2002, but now in Access 2003 there seem to be a problem with this. A user is working with my app, and...
1
2059
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 (Access 97 front end and Access 97 tables): A MainForm loads up correctly and then I enter a ReferenceNumber value in a MainForm field control. I then...
3
17901
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 of main form to all of them. Is thsi a preferred way of coding ? partial class Main: Form { static public Main MainForm;
4
4037
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 "step" id ( example - if some var(MyVariable) = 2, the code should get the 5 matrix attributes that have a parent <step id="2" >). My codea always...
5
1206
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 (in a seperate thread). I need to be able to (from this seperate thread) to call a method (DisplayNotification) on the MainForm and pass it a...
13
3708
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 !! And !! Not sure how to do so (should it be a query in Access or a macro) The connection would be ODBC.
10
1621
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 behind other forms in different Class Libraries? Best Rgds 22Pom
7
3480
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 so you can print a single record to an individual pdf?. I've got 2500 records to make into .pdfs, (project manager says it's what customer...
0
7697
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8120
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7672
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5219
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1212
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.