Jump to content

Switching between forms

- - - - -

  • Please log in to reply
9 replies to this topic

#1
Nixon

Nixon

    Newbie

  • Members
  • Pip
  • 8 posts
Hi!
private void button1_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2(this);
this.Hide();
f2.Show(this);
}

This code replaces Form1 with Form2. But f2 shifts diagonally every time (
SetBounds(x,y,w,h) does not solve the problem.

If there anything like MasterPage in Web? Or how can I organize this, so while swithing between windows they remembered position (size).

Thanx!

#2
sam_coder

sam_coder

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 372 posts
not sitting on my workstation, so I'll say this and sound like a dumbass more than likely =)

but have you tried the

f2.Top = X;

ft.Left=Y;

or for some reason f2.Location is nagging me.

anyways, thats all I got from memory...

#3
Nixon

Nixon

    Newbie

  • Members
  • Pip
  • 8 posts
shifting calls after X,Y definition.

And it is not the point. I would like to know, if anyone can tell how to work with many forms. How to make one template for them all.
new,show,close,setlocation,close,GC,show - is not the best way to do this I think.

Would be very thankful for some example or literature link.

#4
sam_coder

sam_coder

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 372 posts
I'm not sure if you're asking about inheritance, or if you're wanting to retain reference to many forms, and then management externally.

eg inheritance



class BaseForm : Form {


public void commonMethodA() {

}


public void commonMethodB() {

}


}


//Both of these form types inherit methods commonMethodA and commonMethodB


class SubFormTypeA : BaseForm {

}


class SuFormTypeB : BaseForm {

}



or if you mean just managing a collection of forms



List<Form> forms = new List<Form>();

forms.Add(new Form());

forms.Add(new Form());

forms.Add(new Form());

forms.Add(new Form());

forms.Add(new Form());



//then

void showAll() {

   foreach (Form frm in forms) {

     frm.Show();

   }

}


void closeAll() {

   foreach (Form frm in forms) {

      frm.Close();

   }

}



I think you're asking about more the second. There are plenty of ways of doing this, and my specific way is more than likely not what you want to do. Just using it for the purposes of explanation.


What's throwing me off is your use of the MasterPage question I think. So it might be just a simple inheritance thing. In which case, just make your base form as you normally would. save and build the project.

then add a new inherited form, and select your base form as the base type. it has full designer support.

#5
gregwarner

gregwarner

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 853 posts
  • Location:Arkansas
When you say "MasterPage" and "many forms", are you by any chance talking about Multiple Document Interface child forms?
How to: Create MDI Child Forms
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.

– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid


#6
sam_coder

sam_coder

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 372 posts
I was thinking about that too greg, but a masterpage in ASP.NET is more of a template right?

So I was thinking perhaps he meant to style the form in a particular way, and each of the many forms would inherit those traits. I dunno... =)


Another thing that comes to mind, that I've seen (more in line with Greg's MDI suggestion than inheritance, but gives you the feel of an SDI) is to design the main form, with a big panel in the middle.

And then instead of creating forms, create user controls. You can then (just from memory, likely have something named wrong)


Control myControl = new MyUserControl();

panel.Controls.Add(myControl);

myControl.DockStyle = DockStyle.Fill; 


This kinda gives you the feel of outlook. As you switch between mail and calendar for example.

the idea being that you would create an instance of each of the user controls, and then you can just :

panel.Controls.Remove(firstControl);

panel.Controls.Add(secondControl);

secondControl.DockStyle = DockStyle.Fill;


Course, My opinion on this is that the end product can look pretty, but it's likely way too much effort to give you the pay-off. =) but who knows, you might be feeling adventerious


Also note, you can in fact stick forms in a panel just like this, but I find it looks silly.

#7
Nixon

Nixon

    Newbie

  • Members
  • Pip
  • 8 posts
I'm relatively novice developer. Multiform aplication organized by itself like this:
I've appointed first appeard form the Main Form, it'll live till the end of aplivation. All other forms are called by new, show() while the Main Form is hidden.
In fact there is no Main Form, all forms are equal. And it should be easy to navegate through them.

I thought the should be more proper way for this.

Inheritance and forms collection is a good advice and example. Thanks for push in right way. Adding and removing the controlls is a little bit hardcoding way, I prefer drag and drop :) But that is also by the topic. Work with control containers can be comfortable.
All told is good, thankee

#8
sam_coder

sam_coder

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 372 posts
are you talking about a sort of wizard?

Something very similar to like an installer?

like you have a back and next button at the bottom or something?

#9
Nixon

Nixon

    Newbie

  • Members
  • Pip
  • 8 posts
Program is look like many forms, where each form have a link to any other form.
Naturally form that opens should be the same size and position, like the one that had been closed.
Just like in games or any other program - if you resized the window before load the game, it'll stay resized when loaded) That is what I meant.

Do I need MDI Child Forms?

Maybe I'll just call forms without borders, that will dock to the Main Form (And Main Form will be empty)

#10
sam_coder

sam_coder

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 372 posts
I'm on my way out to the beach. SO I cant do anything about this right now. But I'll throw a few samples together, and upload the solution here.

Maybe you could take a look for some ideas, or maybe just add onto one of them. I'm sure we could figure it out. =)




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users