Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Maximized center screen Form1 after being minimized

Posted on 2011-09-22
9
Medium Priority
?
375 Views
Last Modified: 2012-05-12
Hello all

I would like to maximized in center screen a form that was only minimized.

When minimized:
  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Form2.Show()
        Me.WindowState = FormWindowState.Minimized
    End Sub

Open in new window



To maximize:
 
  Private Sub QuitterToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles QuitterToolStripMenuItem.Click
        Me.Close()
        Dim f As New Form1
        f.WindowState = FormWindowState.Maximized
        Dim boundWidth As Integer = Screen.PrimaryScreen.Bounds.Width
        Dim boundHeight As Integer = Screen.PrimaryScreen.Bounds.Height
        Dim x As Integer = boundWidth - f.Width
        Dim y As Integer = boundHeight - f.Height
        f.Location = New Point(x / 2, y / 2)
        f.Show()
    End Sub

Open in new window


I have tried this but i can make it work.

But there is no issue. It just open in the top left corner of the screen.

Thanks again for your help.
0
Comment
Question by:Wilder1626
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 17

Expert Comment

by:nepaluz
ID: 36582808
Simply set the start position property of the form to CentreScreen
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 2000 total points
ID: 36582844
A form that is Maximized takes up all the screen.

What you want to do is probably

f.WindowState = FormWindowState.Normal
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 36582849
Why bother with the bounds and the Location?

...just set it to Maximize and then let it do its thing:

        Dim f As New Form1
        f.WindowState = FormWindowState.Maximized
        f.Show()

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Author Comment

by:Wilder1626
ID: 36582853
Hello nepaluz

The start position was already at CenterScreen.

When i open it for the first time, it is always in center screen.

It's only when i minimize it with the code, then when i maximize it, it goes in top corner.

I also tried this but same result:
    Private Sub QuitterToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles QuitterToolStripMenuItem.Click
        Me.Close()
        Dim f As New Form1
        f.Left = (Screen.PrimaryScreen.Bounds.Width \ 2) - (f.Width \ 2)
        f.Top = (Screen.PrimaryScreen.Bounds.Height \ 2) - (f.Height \ 2)

        f.StartPosition = FormStartPosition.CenterScreen
        f.WindowState = FormWindowState.Maximized
        f.Show()
    End Sub

Open in new window


0
 
LVL 11

Author Closing Comment

by:Wilder1626
ID: 36582865
Hello all

This is perfect.

It's working great now.

Thanks


   Private Sub QuitterToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles QuitterToolStripMenuItem.Click
        Me.Close()
        Dim f As New Form1
        f.Left = (Screen.PrimaryScreen.Bounds.Width \ 2) - (f.Width \ 2)
        f.Top = (Screen.PrimaryScreen.Bounds.Height \ 2) - (f.Height \ 2)

        f.StartPosition = FormStartPosition.CenterScreen
        f.WindowState = FormWindowState.Normal
        f.Show()
    End Sub
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 36582868
"It's only when i minimize it with the code, then when i maximize it, it goes in top corner."

The instance of Form1 that you minimized is NOT the same instance that you are dealing with in QuitterToolStripMenuItem_Click().

Do you want the original instance to un-minimize when Form2 is closed?
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 36582942
Hello Idle_Mind

Yes it should be the original form that should unminimized.

hummmm, how do i get this topic to re open?????
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 36582981
Don't worry about it.

What I recommend you do is actually create an instance of Form2 and subscribe to its FormClosed() event:
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.WindowState = FormWindowState.Minimized
        Dim f2 As New Form2
        AddHandler f2.FormClosed, AddressOf f2_FormClosed
        f2.Show()
    End Sub

    Private Sub f2_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs)
        Me.WindowState = FormWindowState.Maximized
    End Sub

End Class

Open in new window


Now, in your Form2 QuitterToolStripMenuItem_Click() method, all you need to do is make it close itself:  
Private Sub QuitterToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles QuitterToolStripMenuItem.Click
        Me.Close()
    End Sub

Open in new window

0
 
LVL 40
ID: 36582985
Maximized is always in the top corner, because it covers all the screen. Do not mix Maximized and Normal, they mean 2 different things. As soon as a form does not cover all the screen, it is not Maximized.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question