Showing a form

mike55

Contributor
Joined
Mar 26, 2004
Messages
727
Location
Ireland
Hi all

Have a windows form that i can minimise but have set the maximies propertie to false. Am using a Context menu to reshow the window but keep crashing the programme when I select that option. Can anyone tell me what is the command to show up the window?

Mike55
 
PlausiblyDamp said:
Could you post the code you are using?
You should be able to redisplay the form either by doing .Show or by setting .WindowState= FormWindowState.Normal

Ok have tried a number of different thinks but they all give the same result, the following error:
An unhandled exception of type 'System.NullReferenceException' occurred in FileWatch.exe

Additional information: Object reference not set to an instance of an object.

Here is the code i have tried
frmWatch.ActiveForm.visible = true

frmWatch.ActiveForm.Show()

frmWatch.ActiveForm.WindowState= FormWindowState.Normal

Here is the method that is doing the calling:
Code:
Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ctxShowWindow.Click

        MessageBox.Show("Not Operational yet!")
        frmWatch.ActiveForm.WindowState = FormWindowState.Normal

    End Sub

Mike55
 
Last edited:
It looks as though when you are minimizing the form it is no longer the active form - hence the Nullreference exception.

Rather than rely on the active form could you not create a variable to store a reference to the form and use that to redisplay the form?
 
What, do the following
Code:
dim x as new myWinform

and the go

Code:
x.show()
of whatever function cause the form the appear.

Mike55
 
x.showdialog

will make the new form the focused form and will block any others being used.

x.show on its own would allow the user to swap to another form and this might mess up your control.
 
Here is how I finally did it...
Code:
If Me.WindowState = FormWindowState.Minimized Then
            Me.WindowState() = FormWindowState.Normal
            Me.Activate()
        End If

Mike55
 
Are you keeping all you forms alive for the duration of the application and Minimizing/Mazimizing as needed. Have you considered what might happen if the user does an Alt-Tab and switches to a different one of your forms. It will totally mess up the control flow of your app.
 
donnacha said:
Are you keeping all you forms alive for the duration of the application and Minimizing/Mazimizing as needed. Have you considered what might happen if the user does an Alt-Tab and switches to a different one of your forms. It will totally mess up the control flow of your app.

I see where you are comming from, however its ok for this applications as it only has one form.

Mike55
 
Back
Top