2014-09-13 2 views
1

저는 C#에 매우 익숙해졌습니다. 그래서 이것은 매우 쉬운 문제이지만, 모든 독서 후에도 Visual Studio 2010에서 필요로하는 정의를 추가 할 방법이 없습니다. using 문과 각 참조에 대한 MSDN 문서 페이지의 참조가 추가되었습니다.참조가 추가 된 후에 정의가 포함되지 않음

내 오류 :

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); 
      } 
     } 
    } 
} 
} 
+0

'.Split' 또한 문자열에 기본 구조체'string'을 사용합니다. – Sam

+0

'using System.Windows.Forms; '를 제거해보십시오.'rtb'는'System.Windows.Controls.RichTextBox'가 아닌'System'이어야합니다. Windows.Forms.RichTextBox' –

+0

@YuliamChandra, 내가 제안한 것을 시도했지만 문제가 해결되지 않았습니다. .Forms를 제거하면 pulic 부분 클래스로 오류가 발생합니다. 전체 클래스를 포함하도록 코드를 업데이트합니다. – Rilcon42

답변

0

여기 윈폼 RichTextBox 컨트롤에 데이터를 표시하기위한 하나의 방법을 나타내는 (오히려 이상) 샘플이다. (미안하지만, 내가 프로그래밍에서 찾을 수있는 유일한 샘플입니다. 왜냐하면 저는 보통 .Net 익스프레스가 아닌 Developer Express WinForms 컨트롤을 사용하기 때문입니다.)

하지만 먼저 WinForms을 혼합하지 않도록하십시오. 및 WPF, 프로젝트를 만들 때 WinForms를 프로젝트 템플릿 유형 (WPF 아님)으로 선택해야합니다. RichTextBox 컨트롤을 Visual Studio 도구 상자에서 양식으로 끌어다 놓을 때 WPF가 아닌 WinForms RichTextBox인지 확인하십시오.

.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"다른없는 것을 말한다 것.

확인, 여기에 글자 맞추기 사기꾼 프로그램의 결과를 표시합니다 내 이상한 예입니다 :

/// <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에만 쓰고, 읽지는 않지만, 그렇게하는 것은 상당히 사소한 일입니다.

희망이 도움이됩니다.

+0

내 문제의 해결책은 다음과 같습니다. string dataFromBox = rtb.Text; – Rilcon42

관련 문제