473,657 Members | 2,300 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 2250
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
2406
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 he uses an Access 2002 MDE in an Access 2003 environment.
1
2068
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 click on the first field of a SubForm, the ReferenceNumber then shows at the top of the SubForm and...
3
17903
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
4043
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 returning the 5 matrix attributes only from step id="1", and does not mather that i change the MyVariable...
5
1214
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 parameter (or two). I just can't seem to do this. I am however able (with delegates) to do this with...
13
3724
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
1627
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 wants) and I've put the report2pdf call inside a loop. It works, but ignores any filter clause I try to...
0
8411
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8323
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8838
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8613
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7351
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2740
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1732
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.