【问题标题】:listbox selected text with listbox text + custom text (richtextbox)列表框选定文本与列表框文本 + 自定义文本(富文本框)
【发布时间】:2015-04-09 02:48:03
【问题描述】:

我正在申请这个网站: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();


        }
    }
    }

此代码将仅显示从列表框到richtextbox 中的选定文本。 如何在下方添加自定义文本?

【问题讨论】:

  • 你是这个意思吗? richTextBox1.Text = listBox1.SelectedItem.ToString()+"自定义文本";
  • 哈哈我忘了 + " ";是的,正是我的意思,但我想为列表框中的每个选定文本添加自定义文本,因此每个选定的列表框文本上都不会出现相同的文本。
  • 自定义文本是什么?
  • 我想在从列表框中选择一个选项时添加不同的文本。我想将指定文本添加到选定的列表框文本。

标签: c# .net listbox


【解决方案1】:

按条件添加自定义文本

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";
}
...


    }

【讨论】:

  • 非常感谢!正是我想要的! :)
  • 我还有一个搜索文本框和搜索按钮。我希望它突出显示富文本框中的搜索文本。
猜你喜欢
  • 2011-12-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多