试图使按钮切换虚拟键盘 [英] Trying to make a button toggle a virtual keyboard

查看:85
本文介绍了试图使按钮切换虚拟键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在尝试构建一个程序,以帮助我更有效地使用触摸屏计算机.我在这里的主要目标是从这个项目中学到尽可能多的知识,以便将来建立自己的项目.我遇到了两个问题.

1.我有一个虚拟键盘按钮.现在只是一个通用按钮.我想做的是,这样当我按下按钮时,它将打开键盘,再次按下它,则将其关闭键盘.听起来很简单吧?好吧,正如您可以告诉我的那样,我还很陌生,所以任何帮助都将不胜感激.

这是我的代码:

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




我在这里得到的代码在Google的帮助下得到了一些帮助.如果有人对执行项目的其他方式有任何建议,那么我将不胜枚举.
谢谢,
史蒂夫:laugh:




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:

推荐答案

您上面的代码将部分起作用.它可能会启动多个进程,也不会处理远程关闭的外部应用程序.

请参阅下面的代码,该代码可以满足您的要求,还可以满足在外部关闭远程进程的需求.

在此示例中,我使用的是Windows计算器.使用Windows窗体和该窗体上的按钮创建一个新项目,粘贴代码.

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.

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


因此效果很好.

当它说如果应用程序什么都不是"时,基本上是在说应用程序在做某事或处于打开状态时就将其关闭吗?

并且可以删除IsNot Nothing部分并将"calc.exe"更改为"Timer"(我在项目中创建的Windows窗体),以便每次单击按钮时都会创建"Timer"的新进程. >
感谢您的帮助,
史蒂夫:-D
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


这篇关于试图使按钮切换虚拟键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆