Redisplaying modeless window.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • cr113@hotmail.com

    #1

    Redisplaying modeless window.


    Suppose you have Button1 on Form1. If the user clicks Button1, I want
    to show Form2 modelessly. If Form2 is already open I just want to
    redisplay it, not open a new window. Thru trial and error I came up
    with the following code. Is there a better way to do this?


    Public Class Form1
    Dim objForm As Form2

    Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
    System.EventArg s) Handles Button1.Click

    If (IsNothing(objF orm)) Then
    objForm = New Form2
    objForm.Show()
    Else
    If (objForm.Create d) Then
    objForm.BringTo Front()
    Else
    objForm = New Form2
    objForm.Show()
    End If
    End If

    End Sub

    End Class
  • =?Utf-8?B?VGVycnk=?=

    #2
    RE: Redisplaying modeless window.

    I guess it depends on what kind of 'state' the Form2 can be in. What you
    have here won't work if the form was hidden or minimized. Have a minimize
    button on Form2? Have any other button that causes a Me.Hide?
    --
    Terry


    "cr113@hotmail. com" wrote:
    >
    Suppose you have Button1 on Form1. If the user clicks Button1, I want
    to show Form2 modelessly. If Form2 is already open I just want to
    redisplay it, not open a new window. Thru trial and error I came up
    with the following code. Is there a better way to do this?
    >
    >
    Public Class Form1
    Dim objForm As Form2
    >
    Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
    System.EventArg s) Handles Button1.Click
    >
    If (IsNothing(objF orm)) Then
    objForm = New Form2
    objForm.Show()
    Else
    If (objForm.Create d) Then
    objForm.BringTo Front()
    Else
    objForm = New Form2
    objForm.Show()
    End If
    End If
    >
    End Sub
    >
    End Class
    >

    Comment

    • cr113@hotmail.com

      #3
      Re: Redisplaying modeless window.

      On Dec 4, 7:01 pm, Terry <Ter...@nospam. nospamwrote:
      I guess it depends on what kind of 'state' the Form2 can be in. What you
      have here won't work if the form was hidden or minimized. Have a minimize
      button on Form2? Have any other button that causes a Me.Hide?
      Good point. I replaced the BringToFront method with a Dispose and New
      Form and it seems to work. Thanks!

      Public Class Form1
      Dim objForm As Form2

      Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
      System.EventArg s) Handles Button1.Click

      If (IsNothing(objF orm)) Then
      objForm = New Form2
      objForm.Show()
      Else
      If (objForm.Create d) Then
      objForm.Dispose 'changed from BringToFront
      objForm = New Form2
      objForm.Show()
      Else
      objForm = New Form2
      objForm.Show()
      End If
      End If

      End Sub

      End Class

      Comment

      Working...