2014-04-14 50 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" }; 
     } 
    } 
} 
相關問題