Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 有没有办法制作这样的下拉菜单?_C#_Drop Down Menu_Menu - Fatal编程技术网

C# 有没有办法制作这样的下拉菜单?

C# 有没有办法制作这样的下拉菜单?,c#,drop-down-menu,menu,C#,Drop Down Menu,Menu,有人知道如何制作这样的下拉菜单吗 如果是我,我会把它放在这里: private void richTextBox1_TextChanged(object sender, EventArgs e) { //in here } 是的,您可以使用列表框控件 或 通过将DropDownStyle属性设置为Simple,可以使用ComboBox控件 编辑: 如果要从列表框中搜索字符串,并选择与之匹配的项目 You need to have a TextBox to receive the S

有人知道如何制作这样的下拉菜单吗

如果是我,我会把它放在这里:

private void richTextBox1_TextChanged(object sender, EventArgs e)
{
    //in here
}
是的,您可以使用列表框控件

通过将DropDownStyle属性设置为Simple,可以使用ComboBox控件

编辑:

如果要从列表框中搜索字符串,并选择与之匹配的项目

You need to have a TextBox to receive the Serach String as input.
您需要处理TextBox Key_Down事件处理程序才能开始搜索

注意:在下面的代码中,当用户在输入搜索字符串后输入ENTER键时,我已开始搜索

试试这个:

private void textBox1_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.Enter)
        {
            var itemSearched = textBox1.Text;
            int itemCount = 0;
            foreach (var item in listBox1.Items)
            {
                if (item.ToString().IndexOf(itemSearched,StringComparison.InvariantCultureIgnoreCase)!=-1)
                {
                    listBox1.SelectedIndex = itemCount;
                    break;
                }

                itemCount++;
            }
        }
    }

看起来您需要WPFToolkit中的自动完成框。 您可以使用以下命令从NuGet进行设置:

PM> Install-Package WPFToolkit
以下是使用此控件的代码段:

XAML:

C:


当然这是可能的,但它很难看,我自己也不会称之为下拉列表,尽管从技术上讲,它非常接近下拉列表。你把它放在哪里和怎么放是你的事,不是我们的事。谢谢!你知道里面的文字和你键入的字是如何匹配的吗?你是说在组合框中?不,在列表框中。这才是我真正需要的:谢谢你做了一些工作:标记为awnser:剩下的我自己可以做
<Window x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:toolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <toolkit:AutoCompleteBox x:Name="InputBox" Margin="0,77,0,159"/>
</Grid>
using System.Collections.Generic;
namespace WpfApplication1
{
    public partial class MainWindow
    {
        public MainWindow()
        {
            InitializeComponent();
            InputBox.ItemsSource = new List<string>
            { "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten" };
        }
    }
}