Creating multiple screens within one form C#

Making a "Wizard"-like application

Page 1 of 1

10 Replies - 40967 Views - Last Post: 01 July 2010 - 10:07 AM Rate Topic: -----

#1 Guest_Monoxcide*


Reputation:

Creating multiple screens within one form C#

Posted 29 June 2010 - 09:54 AM

I am working on a project in C# and want to have one main form with buttons to link out to other windows. But when you go to other sections/Forms of the program, I don't want to bring up another separate form(or at least not to look like it) I want it to look like the whole program is running in one instance and that just the items within the form change from page to page, Kind of like a "wizard" type application, except the pages are linked like a web, and not a line.

since I want to footer-type section etc. to stay the same between all the forms and only the content to change(kinda like the next and back buttons in a setup wizard, they are always in the same position in all the forms), I tried to copy and paste the template form(.cs) so later I could change the content, but ran into all these errors "ambiguous" wise...(probably because I have text boxes, timers, etc. on the template) I'm sorry if it is hard to understand. Any help would be great.

I have attached a shot of my main template running on my desktop, Hopefully this will help you get an idea of what I want. I just want the footer with the Current Time etc. to stay the same on all of the pages...

Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0

Replies To: Creating multiple screens within one form C#

#2 FlashM  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 382
  • View blog
  • Posts: 1,195
  • Joined: 03-December 09

Re: Creating multiple screens within one form C#

Posted 29 June 2010 - 10:05 AM

Is this just a mock-up of your form or is this a functional form?
If I were you, I'd create one main form and then several different UserControls. Then just create an instance of your user control and dock it inside this main form. I believe I have written some post a while ago how to do it properly...
Was This Post Helpful? 1
  • +
  • -

#3 Guest_Monoxcide*


Reputation:

Re: Creating multiple screens within one form C#

Posted 29 June 2010 - 10:13 AM

This is real running version of it. I will look into that post you wrote, that actually sounds pretty easy. Thanks
Was This Post Helpful? 0

#4 FlashM  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 382
  • View blog
  • Posts: 1,195
  • Joined: 03-December 09

Re: Creating multiple screens within one form C#

Posted 29 June 2010 - 10:24 AM

Here's the topic I was talking about:
http://www.dreaminco..._1&#entry869739


If you need any further assistance, just drop a line...
Was This Post Helpful? 1
  • +
  • -

#5 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1526
  • View blog
  • Posts: 5,961
  • Joined: 21-March 08

Re: Creating multiple screens within one form C#

Posted 29 June 2010 - 10:46 AM

You may want to look into a MDI application.

http://www.dreaminco...ng-mdi-in-c%23/
Was This Post Helpful? 0
  • +
  • -

#6 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5674
  • View blog
  • Posts: 12,190
  • Joined: 02-June 10

Re: Creating multiple screens within one form C#

Posted 29 June 2010 - 10:56 AM

If you want the footer to stay the same in all forms... then put the footer in a statusbar of the main form. That way you always only every have one of them.

As suggested, make everything else a UserControl that you place in your main form.
The UserControls should raise events that the main form subscribes to. So when a UserControl raises a 'feedback' event, you post that on the statusbar. When a UserControl raises a 'done' event, your main form reacts to that. And so on.

Hope these help.

Bulding an application - Part 1
Building an application - Part 2
Was This Post Helpful? 1
  • +
  • -

#7 FlashM  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 382
  • View blog
  • Posts: 1,195
  • Joined: 03-December 09

Re: Creating multiple screens within one form C#

Posted 30 June 2010 - 12:26 AM

Also take a look at inherited UserControls.
Was This Post Helpful? 0
  • +
  • -

#8 Guest_Monoxcide*


Reputation:

Re: Creating multiple screens within one form C#

Posted 30 June 2010 - 08:22 AM

Thank you all for the replies. I think I like the User Controls idea, and have started building the application based on that, but I am running into all sorts of problems. The main one is that I can't have a strong connection between the user controls and the main form. Like when a user clicks a button, I want it to change the status of the the system, or change the name of the page they are on. I tried using get and set to make the properties public, but it isn't working. I am also having trouble changing the user controls from page to page. I extracted pieces of FlashM's posted code in the other topic, IE:

I want to go back to main page when the user clicks in the bottom right on the current page, so I put

Main: My main user control with all the buttons that go out to other pages

      Main main = new Main();
      main.Parent = this;
      main.Dock = DockStyle.Fill;
      main.BringToFront();
      main.Show();



but when I click on the button, it brings up the main user control, but makes the dock at the bottom disappear.

I am also trying to get the page name at the bottom right to change when I switch to different user controls....

Here is my code for the main form (fclsAquaCut):
        public string ChangePage
        {
            get {return this.lblCurrentPage.Text; }
            set {this.lblCurrentPage.Text = value;  }
        }



Here is the code inside of my Main User Control:
btnSetTimes: The button in my main form that links out to the set times page

        private void btnSetTimes_Click(object sender, EventArgs e)
        {
            Console.WriteLine("clicked");
            SetTimes settimes = new SetTimes();
            settimes.Parent = this;
            settimes.Dock = DockStyle.Fill;
            settimes.BringToFront();
            settimes.Show();
            fclsAquaCut aquacut = new fclsAquaCut();
            aquacut.ChangePage = "Times";
        }



I don't know why this isn't working, I posted a screen shot again showing my Set Times page(Sorry if the words are hard to read) Any help or suggestions would be great.

Attached image(s)

  • Attached Image

Was This Post Helpful? 0

#9 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5674
  • View blog
  • Posts: 12,190
  • Joined: 02-June 10

Re: Creating multiple screens within one form C#

Posted 01 July 2010 - 08:26 AM

Quote

The main one is that I can't have a strong connection between the user controls and the main form. Like when a user clicks a button, I want it to change the status of the the system, or change the name of the page they are on.


When you click a button on the user control it should *NOT* be trying to directly affect labels or other controls on the main form. The only thing it should do is raise an even that basically says "this button was clicked". From there it is the responsibility of the other forms that have subscribed to that event to know how they are supposed to react.

Picture a bingo parlor. You have 50 players and 1 guy calling out numbers.
The guy calling out numbers doesn't say
  • "Player one: pick up a chip, move your hand, set the chip down on square N-4"
  • "Player two: pick up a chip, move your hand, set the chip down on square N-4"
The caller just yells "N-4" and each player reacts as they are programmed to. The caller would yell the same thing, the same way if there was one player or 1,000.

That is the basic principal of OOP and events. Your user controls just yell out, and your subscribers react. In the bingo example you would have an event of "BallSelected" with an event argument of "N4"
Was This Post Helpful? 1
  • +
  • -

#10 Curtis Rutland  Icon User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4576
  • View blog
  • Posts: 8,018
  • Joined: 08-June 10

Re: Creating multiple screens within one form C#

Posted 01 July 2010 - 09:19 AM

View PosttlhIn, on 01 July 2010 - 07:26 AM, said:

Picture a bingo parlor. You have 50 players and 1 guy calling out numbers.
The guy calling out numbers doesn't say
  • "Player one: pick up a chip, move your hand, set the chip down on square N-4"
  • "Player two: pick up a chip, move your hand, set the chip down on square N-4"
The caller just yells "N-4" and each player reacts as they are programmed to. The caller would yell the same thing, the same way if there was one player or 1,000.


I am totally borrowing that. Best explanation of why objects should use events that I have seen.
Was This Post Helpful? 0
  • +
  • -

#11 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5674
  • View blog
  • Posts: 12,190
  • Joined: 02-June 10

Re: Creating multiple screens within one form C#

Posted 01 July 2010 - 10:07 AM

View PostinsertAlias, on 01 July 2010 - 08:19 AM, said:

View PosttlhIn, on 01 July 2010 - 07:26 AM, said:

Picture a bingo parlor. You have 50 players and 1 guy calling out numbers.
The guy calling out numbers doesn't say
  • "Player one: pick up a chip, move your hand, set the chip down on square N-4"
  • "Player two: pick up a chip, move your hand, set the chip down on square N-4"
The caller just yells "N-4" and each player reacts as they are programmed to. The caller would yell the same thing, the same way if there was one player or 1,000.


I am totally borrowing that. Best explanation of why objects should use events that I have seen.


That one just came to me. I guess it's good to be back home. My other common one was this:

Picture a blind man in a park with a bullhorn. He doesn't know if there is one or 1,000 people listening to him... or none.
He gets a phone call that something has happened. Then he yells out on the bullhorn... "There is a cat stuck in a tree at 4th and main." (CatStuckEvent, LocationArgs "4th and main")
In the crowd, the fireman grabs his ladder and goes to the seen... while at same time the veterinarian gets an examination room ready... and the representative from the ASPCA readies a report of pet endangerment.

One event, three subscribers... all reacting at the same time, with custom behaviors to their specific needs... yet the object raising the event has no idea of who, what, where, and is not responsible for sequentially telling each subscriber what to do.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1