我正在为我的程序添加语音控制功能。我的代码有错误,我似乎无法摆脱。语音控制将允许用户无需使用鼠标或键盘即可控制程序的各个方面。
目前,我的代码包括:
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开关表达式或大小写标签必须是bool,char,string,integral,enum或相应的可空类型
答案 0 :(得分:3)
ToUpper
应该是方法ToUpper()
,您缺少括号