2014-04-14 49 views
0

有没有人知道如何制作这样的下拉菜单?有没有办法让这样的下拉菜单?

http://puu.sh/88oLL.png

我会把它放进这个如果是我:

private void richTextBox1_TextChanged(object sender, EventArgs e) 
{ 
    //in here 
} 
+0

当然这是可能的,但这很丑陋,我不会把它称为自己的下拉菜单,尽管它在技术上讲非常接近“下拉菜单”。你在哪里以及如何把它放在你的公司,而不是我们的。 –

回答

1

是的,你可以使用ListBox控制。

OR

您可以通过DropDownStyle属性设置为Simple使用ComboBox控制。

编辑:

如果你想搜索从Control字符串和选择项目,如果它与它匹配

You need to have a TextBox to receive the Serach String as input. 

enter image description here

您需要处理的文本框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++; 
      } 
     } 
    } 
+0

谢谢!你知道内部的文字如何匹配你输入的单词吗? – user3527883

+0

你的意思是在'Combobox'中? –

+0

没有列表框。这真的是我需要:) – user3527883

0

看起来像你需要从WPFToolkit AutoCompleteBox。 您可以从的NuGet使用以下命令将其设置:

PM> Install-Package WPFToolkit 

下面是使用该控件的代码片段:

XAML:

<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> 

C#:

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" }; 
     } 
    } 
} 
相关问题