我是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);
}
}
}
}
}
它是'.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