如何获取文本块的内容并多次显示?
How to get the content of a textblock and show it multiple times?
我正在尝试制作一个程序来帮助我检查 arma 3 服务器上哪些行有错误。目前看起来像这样:
我有一些问题。每次我标记 "bug" 并按下显示按钮时,它都会出现:
如何获取文本框的内容?这是我的代码:
public partial class MainWindow : Window
{
public double output = 0;
public string test1 = "";
public MainWindow()
{
InitializeComponent();
textOutput.Text = output.ToString();
textBugs.Text = test1;
}
private void buttonDecrease_Click(object sender, RoutedEventArgs e)
{
output--;
textOutput.Text = output.ToString();
}
private void buttonIncrease_Click(object sender, RoutedEventArgs e)
{
output++;
textOutput.Text = output.ToString();
}
private void buttonReset_Click(object sender, RoutedEventArgs e)
{
output = 0;
test1 = "N/A";
textOutput.Text = output.ToString();
textBugs.Text = test1;
}
private void buttonBug_Click(object sender, RoutedEventArgs e)
{
test1 += textBugs.ContentStart.ToString();
}
private void buttonShow_Click(object sender, RoutedEventArgs e)
{
textBugs.Text = test1;
}
}
有几件事需要解决。导致行为错误的输出函数中有什么?另一个是考虑更改文本框以分配一个 int。这样您就可以将变量仅增加一个,然后将其分配给文本框。无论如何,labelName.Text =
是更改 windows 表单中显示的正确方法。
这一行就是问题所在。
test1 += textBugs.ContentStart.ToString();
ContentStart
是 RichTextBox
上的 属性,类型为 TextPointer
。您只是将此类型的字符串表示形式分配给字符串 test1
.
要从 RTB 获取纯文本:
test1 += textBugs.Text;
我正在尝试制作一个程序来帮助我检查 arma 3 服务器上哪些行有错误。目前看起来像这样:
我有一些问题。每次我标记 "bug" 并按下显示按钮时,它都会出现:
如何获取文本框的内容?这是我的代码:
public partial class MainWindow : Window
{
public double output = 0;
public string test1 = "";
public MainWindow()
{
InitializeComponent();
textOutput.Text = output.ToString();
textBugs.Text = test1;
}
private void buttonDecrease_Click(object sender, RoutedEventArgs e)
{
output--;
textOutput.Text = output.ToString();
}
private void buttonIncrease_Click(object sender, RoutedEventArgs e)
{
output++;
textOutput.Text = output.ToString();
}
private void buttonReset_Click(object sender, RoutedEventArgs e)
{
output = 0;
test1 = "N/A";
textOutput.Text = output.ToString();
textBugs.Text = test1;
}
private void buttonBug_Click(object sender, RoutedEventArgs e)
{
test1 += textBugs.ContentStart.ToString();
}
private void buttonShow_Click(object sender, RoutedEventArgs e)
{
textBugs.Text = test1;
}
}
有几件事需要解决。导致行为错误的输出函数中有什么?另一个是考虑更改文本框以分配一个 int。这样您就可以将变量仅增加一个,然后将其分配给文本框。无论如何,labelName.Text =
是更改 windows 表单中显示的正确方法。
这一行就是问题所在。
test1 += textBugs.ContentStart.ToString();
ContentStart
是 RichTextBox
上的 属性,类型为 TextPointer
。您只是将此类型的字符串表示形式分配给字符串 test1
.
要从 RTB 获取纯文本:
test1 += textBugs.Text;