Issues resizing my main form/application when minimized [C#]

Shaitan00

Junior Contributor
Joined
Aug 11, 2003
Messages
358
Location
Hell
... odd problem ... when my form/application is minimized (to the systray using a NotifyIcon) and I try to resize it to screen (when I click on it), sometimes it just appears on my taskbar but it is minimized and I can't restore it, only way to fix the problem is to kill the application.
When the user clicks on the NotifyIcon the application should resize of screen - worst case scenario if ever it is minimized and I click on it (when it is in the taskbar) it should restore the application - which currently it doesn't.

This is the code I am using when the user clicks on the NotifyIcon:

Code:
private void pNotifyIcon_Click(object sender, System.EventArgs e)
{	// make window visible
	WindowState = FormWindowState.Normal;
	BringToFront();
	Focus(); 
}

So I am thinking I am missing something here to ensure that the application APPEARS on my screen and doesn't remain minimized or some manual code to ensure that it resizes correctly.
Something like form.size = (608,307) or something so that I can be 100% sure that the programs appears on screen with the right size and doesn't stay minimized thus putting me in a terrible state.

Can't you programatically ensure that:
a) the form is NOT minimized (and if it is ensure it is maximized so the user can see it)
b) the form is of the correct size? (which is a locked size and never varies - the user is not permitted to resize the application)

Thanks,
 
The code you posted does not necessarily do what you're stating in the comment. Isn't the form hidden when you go to the NotifyIcon? The following works fine for me (VB.NET code):

Visual Basic:
    Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize

        If Me.WindowState = FormWindowState.Minimized Then
            Me.Hide()
            NotifyIcon1.Visible = True
        End If

    End Sub

    Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click
        Me.Visible = True
        Me.WindowState = FormWindowState.Normal
        NotifyIcon1.Visible = False
    End Sub
 
Back
Top