0

我正在为我的程序添加语音控制功能。我的代码有错误,我似乎无法摆脱。语音控制将允许用户在不使用鼠标或键盘的情况下控制程序的各个方面。

目前,我的代码包括:

using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Text;
using System.Drawing.Printing;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using FontCombo;
using System.Speech.Recognition;
using System.Speech.Recognition.SrgsGrammar;
using Microsoft.VisualBasic;

if (voctrl.Checked == true)
        {
            vcstat.Text = "Voice Control Enabled";
            recognizer = new SpeechRecognizer();
            recognizer.SpeechDetected += recognizer_SpeechDetected;
            recognizer.SpeechRecognitionRejected += recognizer_SpeechRecognitionRejected;
            recognizer.SpeechRecognized += recognizer_SpeechRecognized;
            GrammarBuilder grammar = new GrammarBuilder();
            grammar.Append(new Choices("Cut", "Copy", "Paste", "Select All", "Print", "Deselect All", "Delete", "Save", "Save As", "Open", "New", "Close"));
            recognizer.LoadGrammar(new Grammar(grammar));
        }
        else
        {
            vcstat.Text = "Voice Control Disabled";
        }

private void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
    {
        if (voctrl.Checked == true)
        {
            switch (e.Result.Text.ToUpper) //This is the error according to Visual Studio
            {
                case
                "Cut":
                    Clipboard.SetText(richTextBoxPrintCtrl1.SelectedRtf, TextDataFormat.Rtf);
                    richTextBoxPrintCtrl1.SelectedRtf = "";
                    break; // etc.

我曾尝试在互联网上搜索解决方案,但似乎找不到与此代码一起使用的解决方案。我究竟做错了什么?如果我很愚蠢,我很抱歉,但我是 C# 和一般编程的新手。

错误如下: 错误4 switch表达式或case标签必须是bool、char、string、integral、enum或对应的可空类型

4

1 回答 1

3

ToUpper应该是一个方法ToUpper(),你缺少括号

于 2013-04-25T17:10:09.510 回答