c# 中的多行文本框是否可以隐藏一些文本元素并在您单击文本框时显示,请参阅示例?
Can a Multi line text box in c# hide some text elements and show when you click on a text box please see example?
以上是单击复选框时显示的详细信息以及未选中时隐藏的详细信息。我不知道如何做到这一点,我相信它很简单。但任何帮助将不胜感激,因为我对此很陌生。谢谢
假设您使用的是 RichTextBox,您将所有行保存到一个字符串数组类型的变量中,并将包含“Deposit”的行保存到另一个相同类型的变量中。
public partial class Form1 : Form
{
string[] LinesWithDetails;
string[] LinesWithOutDetails;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
LinesWithDetails = richTextBox1.Lines;
LinesWithOutDetails = richTextBox1.Lines.Where(l => l.Contains("Deposit")).ToArray();
HideDetails();
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked)
ShowDetails();
else
HideDetails();
}
private void ShowDetails()
{
richTextBox1.Lines = LinesWithDetails;
}
private void HideDetails()
{
richTextBox1.Lines = LinesWithOutDetails;
}
}
假设您使用的是 RichTextBox,您将所有行保存到一个字符串数组类型的变量中,并将包含“Deposit”的行保存到另一个相同类型的变量中。
public partial class Form1 : Form
{
string[] LinesWithDetails;
string[] LinesWithOutDetails;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
LinesWithDetails = richTextBox1.Lines;
LinesWithOutDetails = richTextBox1.Lines.Where(l => l.Contains("Deposit")).ToArray();
HideDetails();
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked)
ShowDetails();
else
HideDetails();
}
private void ShowDetails()
{
richTextBox1.Lines = LinesWithDetails;
}
private void HideDetails()
{
richTextBox1.Lines = LinesWithOutDetails;
}
}