C#中当前上下文不存在名称的问题
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Da...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Security.Policy;
using System.Text.RegularExpressions;
using Microsoft.Office.Core;
using powerpoint = Microsoft.Office.Interop.PowerPoint;
using graph = Microsoft.Office.Interop.Graph;
namespace 记事本
{
public partial class Form1 : Form
{
private void Form1_Load(object sender, EventArgs e)
{
richTextBox1.KeyDown += new KeyEventHandler(richTextBox1_KeyDown);
}
public static string getlastword(string str, int i)
{
string x = str;
Regex reg = new Regex(@"\s+[a-z]+\s*", RegexOptions.RightToLeft);
x = reg.Match(x).Value;
Regex reg2 = new Regex(@"\s");
x = reg.Replace(x, "");
return s;
}
void richTextBox1_KeyDown(object sender, KeyEventArgs e)
{
RichTextBox richtextbox1 = (RichTextBox)sender;
string s = getlastword(richtextbox1.Text, richtextbox1.SelectionStart);
if (allclass().IndexOf(s) > -1)
{
myselect(richtextbox1, richtextbox1.SelectionStart, s, Color.CadetBlue, true);
}
}
}
}
错误发生在getlastword里面那个return s;上,说当前上下文不存在名称"s",该怎么修改才能让程序正常? 展开
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Security.Policy;
using System.Text.RegularExpressions;
using Microsoft.Office.Core;
using powerpoint = Microsoft.Office.Interop.PowerPoint;
using graph = Microsoft.Office.Interop.Graph;
namespace 记事本
{
public partial class Form1 : Form
{
private void Form1_Load(object sender, EventArgs e)
{
richTextBox1.KeyDown += new KeyEventHandler(richTextBox1_KeyDown);
}
public static string getlastword(string str, int i)
{
string x = str;
Regex reg = new Regex(@"\s+[a-z]+\s*", RegexOptions.RightToLeft);
x = reg.Match(x).Value;
Regex reg2 = new Regex(@"\s");
x = reg.Replace(x, "");
return s;
}
void richTextBox1_KeyDown(object sender, KeyEventArgs e)
{
RichTextBox richtextbox1 = (RichTextBox)sender;
string s = getlastword(richtextbox1.Text, richtextbox1.SelectionStart);
if (allclass().IndexOf(s) > -1)
{
myselect(richtextbox1, richtextbox1.SelectionStart, s, Color.CadetBlue, true);
}
}
}
}
错误发生在getlastword里面那个return s;上,说当前上下文不存在名称"s",该怎么修改才能让程序正常? 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询