添加引用后不包含定义
我是C#的新手,因此可能这是一个非常简单的问题,但即使在我阅读完所有内容后,我仍无法找到添加Visual Studio 2010所需定义的方法,尽管在每个表达式的MSDN文档页面上添加using语句和引用。添加引用后不包含定义
我的错误:
System.windows.forms does not contain a definition for document
我加入基于什么我读了微软网站上的参考“presentationframework”。感谢下面的一些评论,我发现我显然混合了两种不同的方式从文本框中获取文本。我需要做的就是将内容粘贴到文本框中,并在按下按钮时获取框的内容。有人可以告诉我(或更好地显示)我如何做到这一点,而不是混合策略?
Form1.cs中:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Documents;
using System.Windows.Controls.RichTextBox;
using System.Windows.Forms;
using System.Windows.Controls;
using System.Collections;
namespace WindowsFormsApplication1
{
public partial class HackController : Form
{
ArrayList ipList = new ArrayList();
ArrayList acctList = new ArrayList();
int myAcct = 0;
string myIp = "";
public HackController()
{
InitializeComponent();
}
public void sync_Click(object sender, EventArgs e)
{
string data = new TextRange(rtb.Document.ContentStart, rtb.Document.ContentEnd).Text;// ERROR HERE
string[] lines = Regex.Split(data, "\n");
Regex ipMatch = new Regex(@"\d+.\d+.\d+.\d+");
Regex acctMatch = new Regex(@"#\d+");
foreach(string line in lines)
{
foreach(Match m in ipMatch.Matches(line))
{
ipList.Add(m);
}
foreach(Match m in acctMatch.Matches(line))
{
acctList.Add(m);
}
}
}
}
}
下面是示出显示在一个WinForms RichTextBox控件数据的一种方法一(比较奇怪)样品。 (对不起,但这是我在编程中唯一可以找到的示例,因为我通常使用Developer Express WinForms控件而不是基本的.Net。)
但首先,要确保100%不混合WinForms和WPF,请确保在创建项目时选择WinForms作为项目模板类型(而不是WPF)。当您将RichTextBox控件从Visual Studio工具箱拖放到窗体上时,请确保它是WinForms RichTextBox,而不是WPF。
您可以通过查看.Designer.cs文件来查看,并查找由Visual Studio设计器创建的RTB控件的定义。它应该是这个样子:
this.rtbResults = new System.Windows.Forms.RichTextBox();
...
...
//
// rtbResults
//
this.rtbResults.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.rtbResults.Location = new System.Drawing.Point(12, 52);
this.rtbResults.Name = "rtbResults";
this.rtbResults.Size = new System.Drawing.Size(640, 133);
this.rtbResults.TabIndex = 17;
this.rtbResults.Text = "";
...
...
private System.Windows.Forms.RichTextBox rtbResults;
重要的是,它说“System.Windows.Forms.RichTextBox”,而不是别的东西。
OK,这是我奇怪的例子,它显示一个拼字游戏作弊程序的结果:
/// <summary>
/// Method to display the results in the RichTextBox, prefixed with "Results: " and with the
/// letters J, Q, X and Z underlined.
/// </summary>
private void DisplayResults(string resultString)
{
resultString = UnderlineSubString(resultString, "J");
resultString = UnderlineSubString(resultString, "Q");
resultString = UnderlineSubString(resultString, "X");
resultString = UnderlineSubString(resultString, "Z");
rtbResults.Rtf = @"{\rtf1\ansi " + "Results: " + resultString + "}";
}
/// <summary>
/// Method to apply RTF-style formatting to make all occurrences of a substring in a string
/// underlined.
/// </summary>
private static string UnderlineSubString(string theString, string subString)
{
return theString.Replace(subString, @"\ul " + subString + @"\ul0 ");
}
这将使用微软独有的丰富文本格式,但RichTextBox中也可以使用连胜文。而这个演示只写入RTB,它不会读取它,尽管这样做相当微不足道。
希望这会有所帮助。
我的问题的解决方案是:字符串dataFromBox = rtb.Text; – Rilcon42 2014-09-14 04:14:49
它是'.Split'还使用本地结构'字符串'作为字符串 – Sam 2014-09-13 18:13:04
尝试删除'using System.Windows.Forms;','rtb'应该是'System.Windows.Controls.RichTextBox'而不是'System。 Windows.Forms.RichTextBox' – 2014-09-13 18:27:52
@YuliamChandra,我试着做你的建议,但它没有解决我的问题。如果我删除.Forms我碰到我的pulic部分类错误....我会更新我的代码,以包括整个班级 – Rilcon42 2014-09-13 18:43:30