Click here to Skip to main content
15,914,165 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all,

I'm trying to build a program that will help me use my touch screen computer more efficiently. My main goal here is just to learn as much as I can with this project so I can build my future projects. I'm running into a couple of issues.

1. I have a virtual keyboard button. Just a generic button right now. I'm trying to make is so that when I hit the button, it opens the keyboard, hit it again, it closes the keyboard. Sounds simple enough right? Well, as you can tell I'm pretty new to this so any help would be appreciated.

Here is my code:
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
    Dim p As New System.Diagnostics.Process
    p.StartInfo.FileName = "C:\Documents and Settings\sklemp\My Documents\Downloads\freevk.exe"
    If p.Start = True Then
        p.Close()
    Else
        p.Start()
    End If
End Sub



The code that I have here I got with a little help from google. If anyone has any suggestions on a different way to execute the project, I'm all ears (or eyes in this case).

Thanks,
Steve :laugh:
Posted

The code you had above would partially work. It would probably start multiple processes, and also not handle the external app being closed remotely.

See the code below which does what you want, but also caters for the remote process being closed externally.

In this example I am using the windows calculator. Create a new project with a windows form and a button on that form, paste in the code.

VB.NET
Public Class Form1

    Private theApp As System.Diagnostics.Process

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim theAppStartInfo As New ProcessStartInfo("calc.exe")

        If theApp IsNot Nothing Then
            theApp.CloseMainWindow()
        Else

            theApp = New Process()
            theApp.StartInfo = theAppStartInfo
            theApp.Start()

            AddHandler theApp.Exited, AddressOf theApp_Exited

            theApp.EnableRaisingEvents = True

            theApp.SynchronizingObject = Me.Button1

        End If

    End Sub

    Private Sub theApp_Exited(ByVal sender As Object, ByVal e As System.EventArgs)

        MsgBox("The process has exited, ExitCode: " + theApp.ExitCode.ToString)
        theApp = Nothing

    End Sub
End Class
 
Share this answer
 
So that worked perfectly.

When it says "If theApp IsNot Nothing Then" basically is that just saying that anytime the app is doing something or is open then close it?

And could I remove the IsNot Nothing section and change the "calc.exe" to "Timer" (a windows form that I created in the project) so that anytime i click the button it creates a new process of "Timer"

Thanks for your help,
Steve :-D
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900