4 Replies - 400 Views - Last Post: 07 October 2012 - 02:59 PM Rate Topic: -----

#1 NewK  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 07-October 12

How to call a 2nd Form with the same size than the previous one?

Posted 07 October 2012 - 01:53 PM

So here's my problem: I have a main form and I have a button on that form that will open a 2nd form and will close/hide the main one. I wanted that the 2nd form would be on the same location in the screen as the main form and have same size as the main form, but somehow it's not working, I can't get it to be the same size as the main form nor on the same screen location. If anyone can tell me what I did wrong I would be appreciated, here's my code:

This is the code of the button
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
        Dim RedesWindow2 As New Form2
        Me.Hide() 'Here, I hide/close the main form'
        Form2.DesktopLocation = Me.DesktopLocation 'Here I say that the 2nd form(form2) should be on the same screen location as the main form, which didn't work'
        Form2.Size = Me.Size 'Here I say that the size of the 2nd form(form2) should be the same as the size of the main form, which didn't work'
        RedesWindow2.ShowDialog() 'And here I show the 2nd form, but it's not the same size as the main form, nor on the same screen location'
    End Sub


PS: I'm a newbie, I just started learning VB.NET a few days ago so please go easy on me. Thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: How to call a 2nd Form with the same size than the previous one?

#2 _HAWK_  Icon User is online

  • Master(Of Foo)
  • member icon

Reputation: 1057
  • View blog
  • Posts: 4,099
  • Joined: 02-July 08

Re: How to call a 2nd Form with the same size than the previous one?

Posted 07 October 2012 - 02:31 PM

Your setting the default instance(Form2) rather than the Redeswindow which is the new shiny form you are showing.
Was This Post Helpful? 1
  • +
  • -

#3 NewK  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 07-October 12

Re: How to call a 2nd Form with the same size than the previous one?

Posted 07 October 2012 - 02:48 PM

Ohh I see, thanks, that worked for the size but unfortunately it didn't work for the screen location. Now, when I click the button, the 2nd form has the same size as the main form like I wanted to but it's still not on the same screen location. Do you have any idea what I could be doing wrong?

Here's the code after I updated it
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
        Dim RedesWindow2 As New Form2
        Me.Hide() 
        RedesWindow2.DesktopLocation = Me.DesktopLocation 'This somehow doesn't seem to be working'
        RedesWindow2.Size = Me.Size 
        RedesWindow2.ShowDialog() 
    End Sub

Was This Post Helpful? 0
  • +
  • -

#4 _HAWK_  Icon User is online

  • Master(Of Foo)
  • member icon

Reputation: 1057
  • View blog
  • Posts: 4,099
  • Joined: 02-July 08

Re: How to call a 2nd Form with the same size than the previous one?

Posted 07 October 2012 - 02:54 PM

Try setting the StartPosition to manual first.
Was This Post Helpful? 2
  • +
  • -

#5 NewK  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 07-October 12

Re: How to call a 2nd Form with the same size than the previous one?

Posted 07 October 2012 - 02:59 PM

Thanks, that worked perfectly.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1