简体   繁体   English

列表框选中的文本与列表框文本+自定义文本(richtextbox)

[英]listbox selected text with listbox text + custom text (richtextbox)

I'm making an application for this website: http://incil.info What I'm trying to make is when a listbox text is selected, it will show it on the richTextBox with the selected text from listbox + custom text. 我正在为此网站制作一个应用程序: http : //incil.info我想做的是,当选择了列表框文本时,它将在richTextBox上显示它,其中包含从列表框+自定义文本中选择的文本。

I'm a bit stuck here.. 我有点卡在这里..

For now, here is my code: 现在,这是我的代码:

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();


        }
    }
    }

This code will only show the selected text from listbox to richtextbox. 此代码将仅显示从列表框到Richtextbox的选定文本。 How do I also add custom text below? 如何在下面添加自定义文本?

add custom text by conditions 按条件添加自定义文本

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


    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM