Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.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
Winforms 导致问题的复杂字符串的串联_Winforms_C# 4.0 - Fatal编程技术网

Winforms 导致问题的复杂字符串的串联

Winforms 导致问题的复杂字符串的串联,winforms,c#-4.0,Winforms,C# 4.0,我已将一段代码以适当的格式分配给字符串。检查它是否工作正常。现在,我希望通过单击按钮将此代码的副本连接到旧代码。字符串中还有一些变量,它们从文本框中获取值。但不知何故,这些变量(数组)无法存储最后的值。我想在将所有变量放置在适当位置的同时生成代码 public string oldCode; public int counter=0; string[] AffUrl = new string[100]; string[] ImgUrl = new string[100

我已将一段代码以适当的格式分配给字符串。检查它是否工作正常。现在,我希望通过单击按钮将此代码的副本连接到旧代码。字符串中还有一些变量,它们从文本框中获取值。但不知何故,这些变量(数组)无法存储最后的值。我想在将所有变量放置在适当位置的同时生成代码

  public string oldCode;
    public int counter=0;
    string[] AffUrl = new string[100];
    string[] ImgUrl = new string[100];
    private void button1_Click(object sender, EventArgs e)
    {

        AffUrl[counter] =textBox1.Text;
        ImgUrl[counter] = textBox2.Text;


        string code = @"<div style=""float:left;padding-right:30px;padding-bottom:30px;"">
<div>
  <img src=""" + ImgUrl[counter] + @""" height=""200px"" width=""200px"" />
</div>
<div>
  <button onclick=""myFunction()"">Try it</button>
  <script type=""text/javascript"">
    function myFunction" + counter + @"() {
      var btn = document.createElement(""BUTTON"");
      window.open(""" + AffUrl[counter] + @""", ""_self"")
    }
  </script>
</div>
  </div>";
       oldCode = code;
       oldCode = string.Concat(code,oldCode);
       counter++;

       richTextBox1.Text =oldCode; 
    }
公共字符串oldCode;
公共整数计数器=0;
字符串[]affull=新字符串[100];
字符串[]ImgUrl=新字符串[100];
私有无效按钮1\u单击(对象发送者,事件参数e)
{
affull[counter]=textBox1.Text;
ImgUrl[counter]=textBox2.Text;
字符串代码=@“
试试看
函数myFunction“+计数器+@”(){
var btn=document.createElement(“按钮”);
窗口。打开(“+AffUrl[计数器]+@”“,”\u self“)
}
";
oldCode=代码;
oldCode=string.Concat(代码,oldCode);
计数器++;
richTextBox1.Text=旧代码;
}

如前所述,您总是将新值连接到自身。删除
oldCode=code
分配。

”;
  </div>";
   oldCode = code; <= here you reset the cache - are you sure that's intended?
   oldCode = string.Concat(code,oldCode);
好的,我明白了! 您可以在“oldCode=code

    public string oldCode;
    public int counter = 0;
    string[] AffUrl = new string[100];
    string[] ImgUrl = new string[100];
    private void button1_Click(object sender, EventArgs e)
    {

        AffUrl[counter] = textBox1.Text;
        ImgUrl[counter] = textBox2.Text;

        string code = @"<div style=""float:left;padding-right:30px;padding-bottom:30px;"">
<div>
  <img src=""" + ImgUrl[counter] + @""" height=""200px"" width=""200px"" />
</div>
<div>
  <button onclick=""myFunction()"">Try it</button>
  <script type=""text/javascript"">
    function myFunction" + counter + @"() {
      var btn = document.createElement(""BUTTON"");
      window.open(""" + AffUrl[counter] + @""", ""_self"")
    }
  </script>
</div>
 </div>";
        if (counter == 0)
        {
            oldCode = code;
        }
        oldCode = string.Concat(code, oldCode);
        counter++;

        richTextBox1.Text = oldCode;
    }
}
公共字符串oldCode;
公共整数计数器=0;
字符串[]affull=新字符串[100];
字符串[]ImgUrl=新字符串[100];
私有无效按钮1\u单击(对象发送者,事件参数e)
{
affull[counter]=textBox1.Text;
ImgUrl[counter]=textBox2.Text;
字符串代码=@“
试试看
函数myFunction“+计数器+@”(){
var btn=document.createElement(“按钮”);
窗口。打开(“+AffUrl[计数器]+@”“,”\u self“)
}
";
如果(计数器==0)
{
oldCode=代码;
}
oldCode=string.Concat(代码,oldCode);
计数器++;
richTextBox1.Text=旧代码;
}
}

}

什么是不起作用的?你是说连接没有给出正确的结果,还是数组中的值不正确?兄弟,我解决了这个问题,你可以参考下面的代码。“oldCode=code;”用于在每次单击按钮时重置“oldCode”。所以我给它加了个条件。很高兴你明白了。