473,395 Members | 1,412 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,395 software developers and data experts.

Switching views

Hello,

We developed a C# application.
How do you changes views within the same
application window?

With VC++ you changes views within the
same window with the SwitchView method.

TIA,
Jacques
Nov 15 '05 #1
5 1516

Hi Jacques,

Thanks for posting in this group.
Can you show me more detailed what exactly you want to do?
In .Net, there are no concept of view, C#, VB.net all use .Net Framework
library to work.
If you want to switch between 2 windows, I think you can create 2 forms,
and switch between them.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: "Jacques Cooper" <jc*****@jcsoftware.net>
| Subject: Switching views
| Date: Tue, 18 Nov 2003 20:23:56 -0800
| Lines: 13
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <eG**************@TK2MSFTNGP12.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: omega.jcsoftware.net 66.15.15.165
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP12.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:200402
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Hello,
|
| We developed a C# application.
| How do you changes views within the same
| application window?
|
| With VC++ you changes views within the
| same window with the SwitchView method.
|
| TIA,
| Jacques
|
|
|

Nov 15 '05 #2
Hi Jeffrey,

Thank you for responding to my posting.
If you want to switch between 2 windows, I think you can
create 2 forms, and switch between them.

OK, is there a sample application that demonstrates
how to switch between multiple forms?

TIA,
Jacques
Nov 15 '05 #3

Hi Jacques,

In VS.net, it is easy to do this. You can first add some new forms to your
project(File|Add New Item, then select "Windows Form").
Each form is a new class that inherited from System.Windows.Forms.Form.
Your original form is has a main method, so it will be first be ran.
Then when you want to swith forms, you can create an instance of other form
and show it out.
Below is how I do in Form1's button_click event:

private void button1_Click(object sender, System.EventArgs e)
{
Form2 f2=new Form2();
this.Hide();
f2.Show();
}

Hope this helps,
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #4
Hi Jeffrey,

Thanks again for responding to my posting.
I have a few questions from your response:

//add this code to form1
private void button1_Click(object sender, System.EventArgs e)
{
Form2 f2=new Form2();
this.Hide();
f2.Show();
}


OK, how do I switch back to form1 from form2?
Do I create another instance of form1 in form2?

//add this code to form2
private void button1_Click(object sender, System.EventArgs e)
{
Form1 f1=new Form1();
this.Hide();
f1.Show();
}

When do these forms get destroyed?
Aren't all these forms created on the stack?
Won't the stack eventually overrun?

TIA,
Jacques
Nov 15 '05 #5

Hi Jacques,

Thanks for your feedback.
In my code, the form1 was just hide not destroyed.
I think you should create an overloaded constructor of Form2, which take
form1's reference as parameter.
Then in class form2 you have got a reference of form1.
In form2, you can do whatever program logic you like, if you want to reshow
the form1, you can show it out while no need to create a new instance.
So I think in one form, you should store an instance of another form. Then
you can manipulate another form freely.
Do like this:
Class Form1:
private System.Windows.Forms.Form f;
private void button1_Click(object sender, System.EventArgs e)
{
if(this.f==null)
{
Form2 f2=new Form2(this);
this.f =f2;
}
this.Hide();
f.Show();
}

Class Form2:
private System.Windows.Forms.Form f;
public Form2(Form1 f1)
{
this.f=f1;
InitializeComponent();
}

private void button1_Click(object sender, System.EventArgs e)
{
this.f.Show();
this.Hide();
}

Then, you can swith between these 2 forms. But you must design your
application model well, for example, when closing the one of the forms, you
should either show or close another form, or the application will not
end(Because another "hide" form is still exist).

For your stack overrun problem:
First, in .Net all the class that inherited from System.Object will be
created on heap, and the class's instance is reference to this class object.
Second, you should not hide one form and then pay no attention to it. Then
it will hide and not die, tie up the system resource. You should manage
these forms well. This is why I suggest each form class manage an instance
of other forms.

Hope this helps,
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #6

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

Similar topics

0
by: Dan Perl | last post by:
I have posted this problem also on the wxpython-users list, but maybe someone here can also help. I want to keep 2 different views for the same object, both views using SplitterWindow. So I am...
7
by: Neil Ginsberg | last post by:
I have a strange situation where one or more landscape reports that I created in A2000 sometimes come up in portrait mode when opened on an A2002 machine. This phenomenon is intermittent, and most...
1
by: Matthew Wells | last post by:
I have a a parent form with a subform. The parent form has two command buttons to change the subform view to single form view and datasheet view respectively. I can't seem to get this to work. ...
1
by: Andy Bates | last post by:
Hi - I'm writing a C# windows form application and have hit a hurdle. The application has several panels that need to be displayed at various times depending on what the user is doing. They all...
0
by: vani | last post by:
I am working on an SDI application. It has 3 views(With corresponding buttons to open them).When i switched from 2nd to 3rd view...I can see the 2nd view between the gaps of controls on 3rd...
4
by: steph | last post by:
Hi, A question regarding Access 2002: I've got a form which should be displayed in Form View and in Datasheet View. But I want to use a different record source for each view. That means, when...
15
by: rod.weir | last post by:
Fellow database developers, I would like to draw on your experience with views. I have a database that includes many views. Sometimes, views contains other views, and those views in turn may...
7
by: Niall | last post by:
I have converted a vs 2003 solution to 2005 and when I try to switch to design mode for a user control I get: Cannot switch views: Validation (Internet Explorer 6): Element 'Style' cannot be...
1
by: SamSpide | last post by:
Hi all, I have a moderate-side 'Windows Form Application' (C++) project, with several forms. For some reason switching between code & designer views (right-click ;view code' or 'view...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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...
0
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...

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.