Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 添加引用后不包含定义_C#_Visual Studio - Fatal编程技术网

C# 添加引用后不包含定义

C# 添加引用后不包含定义,c#,visual-studio,C#,Visual Studio,我对C非常陌生,所以这可能是一个非常简单的问题,但即使在我阅读了所有内容之后,我也找不到添加Visual Studio 2010想要的定义的方法,尽管在MSDN文档页面上为每个表达式添加了using语句和引用 我的错误: System.windows.forms does not contain a definition for document 我添加了参考presentationframework,这是基于我在Microsoft网站上阅读的内容。多亏了下面的一些评论,我发现我显然混合了两种

我对C非常陌生,所以这可能是一个非常简单的问题,但即使在我阅读了所有内容之后,我也找不到添加Visual Studio 2010想要的定义的方法,尽管在MSDN文档页面上为每个表达式添加了using语句和引用

我的错误:

System.windows.forms does not contain a definition for document
我添加了参考presentationframework,这是基于我在Microsoft网站上阅读的内容。多亏了下面的一些评论,我发现我显然混合了两种不同的方式来从框中获取文本。我所需要做的就是将内容粘贴到文本框中,并在按下按钮时获取框中的内容。有人能告诉我或者更好地告诉我如何在不混合策略的情况下做到这一点吗

表格1.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控件从VisualStudio工具箱拖放到表单上时,请确保它是WinForms RichTextBox,而不是WPF

您可以通过查看.Designer.cs文件来检查这一点,并找到由Visual Studio Designer创建的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写入数据,不从RTB读取数据,尽管这样做相当简单


希望这能有所帮助。

它是.Split,也可以为stringsTry使用本机结构字符串,删除使用System.Windows.Forms;,rtb应该是System.Windows.Controls.RichTextBox,而不是System.Windows.Forms。RichTextBox@YuliamChandra,我试着按照你的建议去做,但没有解决我的问题。如果我删除.Forms,我的pulic分部类就会出错。。。。我将更新我的代码以包含整个类。我的观点是没有文档属性。。。除非您使用的是you's right,否则第一次没有包含所有代码是我的错;