按下Enter键会将选定的项目从列表框添加到RichTextBox [英] Pressing Enter Key will Add the Selected Item From ListBox to RichTextBox

查看:105
本文介绍了按下Enter键会将选定的项目从列表框添加到RichTextBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

: 在RichTextBox中键入单词时,会出现隐藏的ListBox

im正在使用代码编辑器工作,我只想知道是否可以使用enterkey将列表框中的项目添加到文本框中.

im working on a code editor and i just want to know if how can I add items from listbox to textbox using enterkey .

更多关于我的字符串:

public String[] ab = { "abstract" };
public String[] am = { "AmbientProperties", "AmbientValueAttribute" };

样本:

在richtextbox(rtb)中,我键入Ab,然后hiddenlistbox将使用以下代码显示抽象"文本(已经这样做):

in richtextbox (rtb) , i type Ab, then hiddenlistbox will appear with "abstract" text on it (already do that) using this code:

if (token == "letterA" || token.StartsWith("Ab") || token.StartsWith("ab"))
{
    int length = line.Length - (index - start);
    string commentText = rtb.Text.Substring(index, length);
    rtb.SelectionStart = index;
    rtb.SelectionLength = length;
    lb.Visible = true;

    KeyWord keywordsHint = new KeyWord();

    foreach (string str in keywordsHint.ab)
    {
        lb.Items.Add(str);
    }
    break;
}

然后在我按Enter键之后,我想将列表框中的摘要添加到Richtextbox中.

then after that after i press enterkey i want to add the abstract from listbox to the richtextbox .

RichTextBox声明为rtb,ListBox声明为lb

RichTextBox declared as rtb and ListBox declared as lb

我该怎么办?谢谢.

推荐答案

在按键事件中按下某些控件时,某些控件无法识别它们. 例如,ListBox无法识别按下的键是否为Enter键.

Certain controls do not recognize some keys when they are pressed in key down event. For eg ListBox do not recognize if key pressed is Enter Key.

请参阅以下链接中的备注部分- http://msdn.microsoft.com/zh-CN/library/system.windows.forms.control.keydown(v=vs.110).aspx

Please see remarks section in following link - http://msdn.microsoft.com/en-us/library/system.windows.forms.control.keydown(v=vs.110).aspx

解决问题的方法之一可以是 http://msdn.microsoft.com/zh-CN/library/system.windows.forms.control.previewkeydown(v=vs.110).aspx

one of the solution for your problem can be http://msdn.microsoft.com/en-us/library/system.windows.forms.control.previewkeydown(v=vs.110).aspx

列表框的实现PreviewKeyDown事件,以便列表框识别您的操作.

implement PreviewKeyDown Event for your listbox for listbox to recognize your actions.

这是示例代码段-

    private void listBox1_KeyDown(object sender, KeyEventArgs e)
    {

        if (e.KeyCode == Keys.Enter)
        {
            //Do your task here :)
        }
    }

    private void listBox1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
    {
        switch (e.KeyCode)
        {
            case Keys.Enter:
                e.IsInputKey = true;
                break;
        }
    }

这篇关于按下Enter键会将选定的项目从列表框添加到RichTextBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆