2 Replies - 259 Views - Last Post: 01 October 2012 - 12:46 PM Rate Topic: -----

#1 risky14  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 12-September 12

is there an easier/better way of doing multiple forms?

Posted 01 October 2012 - 12:34 PM

I've got a map of a city with buttons ontop of each town. I've got 32 towns so that's 32 buttons. I want form 2 to hold different message boxes for each town so that when the user clicks on Town A then on form 2 when the user clicks "info" Town A's messagebox pops up. Town B would have the Town B messagebox popup and so on.

I tried if and switch statements but these aren't working for me because I need form2 to show up as it has a textbox and two buttons (one of them is info). So now I've decided to do a form for each button but would this application have to hold so much memory that the computer could crash? Am I allowed to do as many forms as I want or is this a silly way of coding the app?

heres the button codes on form 1

private void lr_Click(object sender, EventArgs e)
            {
                LR thirdForm = new LR();

                thirdForm.Show();
            }

            private void btnCa_Click(object sender, EventArgs e)
            {
                Form2 secondForm = new Form2();

                secondForm.Show();

                
            }

            private void mdp_Click(object sender, EventArgs e)
            {
                MdP forthForm = new MdP();

                forthForm.Show();
            }

            private void leds_Click(object sender, EventArgs e)
            {
                LEDS fifthForm = new LEDS();

                fifthForm.Show();
            }


it goes on to thirtysecondForm. I'd really appreciate any help I can get

Thanks

This post has been edited by tlhIn`toq: 01 October 2012 - 12:38 PM
Reason for edit:: [code] your code goes here [/code] tags addes


Is This A Good Question/Topic? 0
  • +

Replies To: is there an easier/better way of doing multiple forms?

#2 Ryano121  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1292
  • Posts: 2,863
  • Joined: 30-January 11

Re: is there an easier/better way of doing multiple forms?

Posted 01 October 2012 - 12:37 PM

Yeah this is a pretty verbose way of doing things.

Why not instead just create one base Form class and then when you click on a Town you create an instance of this one Form and pass in the info about the town they just clicked on.
Was This Post Helpful? 2
  • +
  • -

#3 tlhIn`toq  Icon User is offline

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

Reputation: 5316
  • View blog
  • Posts: 11,373
  • Joined: 02-June 10

Re: is there an easier/better way of doing multiple forms?

Posted 01 October 2012 - 12:46 PM

32 buttons on top of the map. Can you even see the map?
Have you ever used a mapping program that looked/worked like that?
Maybe your first step should be to step back... Re-examine your underlying concept for this program and see if there is a better, better looking, more conventional way it should be done.

For example... You had to layout all the buttons to precisely match the map anyway... So why not just use a click event on the map, check the x,y coordinates of the mouse, look up city at that location... Then as already suggested pass the city information (name, Latitude/longitude, etc) as an argument to a new form.
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1