列表框选择文本与列表框文本+自定义文本(richtextbox)
listbox selected text with listbox text + custom text (richtextbox)
我正在为这个网站申请:http://incil.info
我想要做的是当一个列表框文本被选中时,它将显示在 richTextBox 上,其中包含来自列表框的选定文本 + 自定义文本。
我有点卡在这里..
现在,这是我的代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Kutsal_Kitap
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged);
}
private void btnAra_Click(object sender, EventArgs e)
{
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
richTextBox1.Text = listBox1.SelectedItem.ToString();
}
}
}
此代码只会显示从列表框到富文本框的选定文本。
如何在下方添加自定义文本?
按条件添加自定义文本
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
var str =listBox1.SelectedItem.ToString();
if(str=="aaa")
{
richTextBox1.Text = str + "custom text 1";
}
else if(str=="bbb")
{
richTextBox1.Text = str + "custom text 2";
}
...
}
我正在为这个网站申请:http://incil.info 我想要做的是当一个列表框文本被选中时,它将显示在 richTextBox 上,其中包含来自列表框的选定文本 + 自定义文本。
我有点卡在这里..
现在,这是我的代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Kutsal_Kitap
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged);
}
private void btnAra_Click(object sender, EventArgs e)
{
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
richTextBox1.Text = listBox1.SelectedItem.ToString();
}
}
}
此代码只会显示从列表框到富文本框的选定文本。 如何在下方添加自定义文本?
按条件添加自定义文本
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
var str =listBox1.SelectedItem.ToString();
if(str=="aaa")
{
richTextBox1.Text = str + "custom text 1";
}
else if(str=="bbb")
{
richTextBox1.Text = str + "custom text 2";
}
...
}