473,397 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

this may very well be a stupid question

Hi,

I'm writing a Windows Form app, using c# (and believe me when I say I'm a
newbie). The program needs two forms to functionate and I have to be able to
write code that switches between the forms (i.e. the have to be co-existent
and I need to change the Active Form). I launch the second form from the
menu bar in the frst form.
How can I make this second form "known" throughout the entire code, so that
I can access (i.e. render active) it anywhere I like from within the code of
form1.
And how do I actually change the active form? I've tried using Form.Activate
() but unless I'm doing something wrong (which undoubtedly is the case), it
doesn't do what I want.

Sample code would be greatly appreciated,

Thanks,

Bart.
Nov 15 '05 #1
2 1554
Greetings.

This is a subject that is very dear to my heart, something that I hope I'll
never forget, as long as I program C# -- I spent about a week trying to
figure this out.

It is really simple. Like this:

Here is the form that you want to access:

using System.Forms;

namespace My_Program
{
public class Form1 : System.Windows.Forms.Form
{
public static Form1 self = null; // this is the variable that we
will be accessing later - very import line. Static means that anywhere can
access and change it. Also the variable that you want to access MUST be
public.
public string text; // remember the public parameter

public Form1()
{
self = this; //this is where we assign what self is.
text = "Hello World!";
}
... rest of code

Here is an example of how to access Form1 from Form2;

public void AccessForm1 ()
{
MessageBox.Show(Form1.self.text);
}

Best,

J_Max
"dawn" <da******@hotmail.com> wrote in message
news:Dz*********************@phobos.telenet-ops.be...
Hi,

I'm writing a Windows Form app, using c# (and believe me when I say I'm a
newbie). The program needs two forms to functionate and I have to be able to write code that switches between the forms (i.e. the have to be co-existent and I need to change the Active Form). I launch the second form from the
menu bar in the frst form.
How can I make this second form "known" throughout the entire code, so that I can access (i.e. render active) it anywhere I like from within the code of form1.
And how do I actually change the active form? I've tried using Form.Activate () but unless I'm doing something wrong (which undoubtedly is the case), it doesn't do what I want.

Sample code would be greatly appreciated,

Thanks,

Bart.

Nov 15 '05 #2
"dawn" <da******@hotmail.com> wrote in
news:Dz*********************@phobos.telenet-ops.be:
Hi,

I'm writing a Windows Form app, using c# (and believe me when I say
I'm a newbie). The program needs two forms to functionate and I have
to be able to write code that switches between the forms (i.e. the
have to be co-existent and I need to change the Active Form). I launch
the second form from the menu bar in the frst form.
How can I make this second form "known" throughout the entire code, so
that I can access (i.e. render active) it anywhere I like from within
the code of form1.
And how do I actually change the active form? I've tried using
Form.Activate () but unless I'm doing something wrong (which
undoubtedly is the case), it doesn't do what I want.

Sample code would be greatly appreciated,

Thanks,

Bart.

Seems like what you really need is an MDI Application.

Have a look at the following article @msdn:

http://msdn.microsoft.com/library/en...plications.asp

--
best regards

Peter Koen
-----------------------------------
MCAD, CAI/R, CAI/S, CASE/RS, CAT/RS
http://www.kema.at
Nov 15 '05 #3

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

Similar topics

119
by: rhat | last post by:
I heard that beta 2 now makes ASP.NET xhtml compliant. Can anyone shed some light on what this will change and it will break stuff as converting HTML to XHTML pages DO break things. see,...
90
by: Bret Pehrson | last post by:
This message isn't spam or an advertisement or trolling. I'm considering farming some of my application development to offshore shops (I'm in the US). I have absolutely *no* experience w/ this,...
3
by: Alejandro Penate-Diaz | last post by:
Hi. I have posted this question three times in this newsgroup as well as microsoft.public.scripting.jscript and have get no answer yet. Now I dont know if my question is too stupid or too weird,...
3
by: rroman | last post by:
I have a very simple form, takes information from the user, updates a SQL database, now I just want to redirect to a "Thank You For Your Time" web page within the same bowser. ASP. NET VB
6
by: Adam Smith | last post by:
I have posted this and similar questions repeatedly and can't even raise a single response. I am being led to believe that this then 'Must be a stupid question' although people say that there is no...
6
by: Dave Vandervies | last post by:
I'm writing an abstraction layer over an OS's ability to do non-blocking reads and writes on various things. The basic idea is that the caller will be able to let the I/O happen in the background,...
31
by: anonymouse127 | last post by:
This is now such a nasty place to visit so I'm quitting coming here. Newbies are regularly attacked in a vicious way about top-posting - which is a completely normal thing to do outside of this...
2
by: Lynx101 | last post by:
Hi, Is this a stupid question? Senario: Two tables linked together with an ID number. Question: When using a combo box, which refences another table by indexed autonumber, is there a way to...
112
by: istillshine | last post by:
When I control if I print messages, I usually use a global variable "int silent". When I set "-silent" flag in my command line parameters, I set silent = 1 in my main.c. I have many functions...
27
by: Dave | last post by:
I'm having a hard time tying to build gcc 4.3.1 on Solaris using the GNU compilers. I then decided to try to use Sun's compiler. The Sun Studio 12 compiler reports the following code, which is in...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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,...
0
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...

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.