Pergunta

I am attempting to create a form using VB.Net that checks if the IExplorer process is running and then display a RichTextBox (which advises the user to close IE) is the process = 1 and a Button to proceed to the next form if the process = 0.

That's the easy part, the hard part is that if the process was = 0 when the form was loaded then the user opens IE, I want to remove the button and show the RichTextBox (which advises the user to close IE) and once again if they close IE the Button reappears.

I have the button and RichTextBox in the form_load with an If statement that shows depending on IE being open or not, but i cannot get them to swap over if IE is closed or opened, any help will be greatly appreciated.

Here is the code I have in the Form_load for the RTB and Button

aProc = Process.GetProcessesByName("iexplore")

If aProc.Length = 0 Then
    Dim b1 As New Button
    b1.Location = New System.Drawing.Point(274, 244)
    b1.Name = "btnOK"
    b1.Size = New System.Drawing.Size(75, 29)
    b1.TabIndex = 5
    b1.Text = "OK"
    b1.UseVisualStyleBackColor = False
    Me.Controls.Add(b1)
    AddHandler b1.Click, AddressOf btn_OK

Else
    Dim t1 As New RichTextBox
    t1.Location = New System.Drawing.Point(170, 233)
    t1.Name = "rtbMessage2"
    t1.ReadOnly = True
    t1.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    t1.Size = New System.Drawing.Size(293, 40)
    t1.TabIndex = 5
    t1.Text = ("Internet Explorer is Running - Please Close Internet Explorer to Continue")
    Me.Controls.Add(t1)
    AddHandler t1.Click, AddressOf btn_OK
End If
Foi útil?

Solução

Two changes I would make:

  • Add a timer that continually calls the logic (show/hide the Button/RichTextBox)
  • Make the Button and RichTextBox always there, but initially invisible.

To do this, I would (on load) create the Button and RichTextBox with .Visible = false. Then create a timer that runs every 500 milliseconds (+/-). That timer would call a function that contains the logic you have above. However, instead of creating the controls (with that logic) just reference them and set their visibility.

In essence, create the controls once, run the logic multiple times.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top