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

Having Next/Pervious Button in desktop application, windows application.

Hi everybody,

Can anyone help me ?
How do I move to the next Form and go back without having to open new Form in window application. I tried to use in Form1
Form2 f2 = new Form2();
f2.show();
but the problem is that technique opens new Form and if I went to go back to Form1 to modify some info and get back again to Form2, I will have new window of Form2. For example, lets say that I have questioneer application and a each question in a Form by itself and want to change the previous answers without opening new Forms, what is the best techniqe? .
I know that in web application the "Response.Redirect" is used.

So, is anyone can help me on how to have Next/Previous application?
May 6 '09 #1
11 10441
r035198x
13,262 8TB
Please read my reply #7 in this thread.
May 6 '09 #2
cloud255
427 Expert 256MB
Hi,

There are a couple of ways to approach this. You could look into creating a public static form array in your main application class (Program.cs by default) or you could create a wrapper class which each form inherits from, with the wrapper containing the array.

This way your application is extensible as you can easily add and remove forms without having to change the code. Below is how the Next button might function:

Expand|Select|Wrap|Line Numbers
  1. if (MyApplication.Program.frmArr[currentFrm+1] != null)
  2.             {
  3.                 MyApplication.Program.frmArr[currentFrm+1].Show();
  4.             }
  5.             else
  6.             {
  7.                 MyApplication.Program.frmArr[currentFrm+1] = new Form();
  8.                 MyApplication.Program.frmArr[currentFrm+1].Show();
  9.             }
With this approach you only instantiate a new form if the next or previous form is NULL, that way your changes will not be lost.

Hope this helps
May 6 '09 #3
r035198x
13,262 8TB
@cloud255
.. and the correct way depends on the program design if any. See my reply above.
May 6 '09 #4
balame2004
142 100+
You can not do it with forms. Instead you can use multiple panels in a form. Use each panel for each question and set the Dock property to be Fill(eg: Panel1.Dock=DockStyle.Fill;) for the panel that contains current question.

Do the following steps:
1.Add Windows Form.
2.Add a panel(say PanelControls) at the bottom of the form(Set Dock property of the panel to be Bottom) and add prev and next buttons in this panel.
3. Add panels that contain questions.
4.Initially set(Set Dock property of panel to be Fill) a panel that contains question 1.
5.Set appropriate panel(i.e. set Dock property of panel to be Fill) whenever you click prev and next buttons.

Hope it will help you!
May 6 '09 #5
cloud255
427 Expert 256MB
@r035198x
I agree with you that object design is largely neglected, I personally use MVP and do as little as possible on the forms themselves. But my experience is that many people don't bother to create any real design at all before development and this is a problem that should be addressed. But often we at the forum have no idea what the application as a whole should achieve so helping people to create proper designs is impossible.

With a detailed diagram of what objects you will be using and how they interact, most of the problems encountered at these forums could be avoided but most people here are devs and not architects, so I try to provide people with easy to implement work-arounds to the problems they face.

Maybe we should create an Analysis and Design section in Bytes, I really believe that alot of people would benefit from such a feature.

Regards
May 6 '09 #6
r035198x
13,262 8TB
@cloud255
Start a thread about it and let's see what others think of the idea.
May 6 '09 #7
Thanks for everyone who replied to me ....
May 10 '09 #8
Example:
Form1 has Next button which pops out Form2.
Form2 has Previous button which takes to Form1. (not instantiate. so data is persistent)
Form2 has Next button which may invoke Form3 and so on ...
Last form has Finish button which closes all forms.


Form1's next button click method:

private void btnNextform1_Click(object sender, EventArgs e)
{
this.Hide();

Form2 f2 = new Form2(this);
f2.ShowDialog();

}



Form2's default constructor:

public partial class Form2 : Form
{
Form tmpfrm = null;

public Form2(Form1 parent)
{
InitializeComponent();
tmpfrm = parent;

}


Form2's Previous button click method:

private void btnPreviousForm2_Click(object sender, EventArgs e)
{

tmpfrm.Visible = true;
tmpfrm.Show();

this.Close();

}


Assuming Form2 has a finish button, its method would be:

private void btnFinishForm2_Click(object sender, EventArgs e)
{
tmpfrm.Close();
this.Close();
}

-x-
Oct 3 '09 #9
Plater
7,872 Expert 4TB
I would have suggested using a tabControl and setting the tabs to hidden (75% certain you can do that) and then cycling through the tabs.
The only reason I say that over using a Panel collection, is that at design time, it is easier to cycle between the panels to add the widgets.
Oct 5 '09 #10
tlhintoq
3,525 Expert 2GB
You could do it with forms by taking control of the .Close() and having the form .Hide() instead. This way you make all your forms in advance and only .Show and .Hide as needed.

Though my preferences is to not have the content of the form be on a Form but instead in a user control. This way I can have one Form open, and drop in/out different User Controls

Other good suggestions have been made as well.

Its really just a matter of personal programming style preference.
Oct 5 '09 #11
Plater
7,872 Expert 4TB
As a side note, you can add a form to another form like you could a control, but its a little trickier then just using a usercontrol
Oct 5 '09 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Andre Grumbach | last post by:
Hi NG, I have a little Problem. I make a normal HTML page which does following: When I click the Button Submit, I send some fields to the Server back. Here the Stream that my Browser...
3
by: Elp | last post by:
Hi, I have developped a Windows applcation (in C#) that allows, among other things, users to view and control the desktop of a remote Windows XP Pro machine. I have actually simply embedded the...
9
by: Rajat Tandon | last post by:
Hello there, I am relatively new to the newsgroups and C#. I have never been disappointed with the groups and always got the prompt replies to my queries.This is yet another strange issue, I am...
2
by: AS | last post by:
Hi, I have a C# windows desktop application that will be used only by one user at a time. The database server (SQL Server 2000) also resides on that machine only. This application has three...
3
by: illegal.prime | last post by:
Hi all, I have a service that needs to start a regular windows application. I'm running the service as ServiceAccount.LocalSystem. But, when it starts the process (using Process.Start) the GUI...
3
by: C#Schroeder | last post by:
I am new to creating a windows application and have been asked to display an HTML page when a certain button is clicked. I have created the HTML page but don't know how to display it when the...
15
by: =?Utf-8?B?TVNU?= | last post by:
To demonstrate my problem, I have a very simple VB Windows application. It has a text box that is used to display a counter, a button to reset the counter, and a timer that increments the counter...
1
by: sarabrk | last post by:
Hi, I am having a problem when running a windows application. I see the "The thread 0x328 has exited with code 0 (0x0)." message in the output and the forms still open even after completing the...
1
by: Neil Roy Albert | last post by:
when i click on the next button i want the next record to be displayed.
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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.