有没有人知道如何制作这样的下拉菜单?有没有办法让这样的下拉菜单?
我会把它放进这个如果是我:
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
//in here
}
有没有人知道如何制作这样的下拉菜单?有没有办法让这样的下拉菜单?
我会把它放进这个如果是我:
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
//in here
}
是的,你可以使用ListBox
控制。
OR
您可以通过DropDownStyle
属性设置为Simple
使用ComboBox
控制。
编辑:
如果你想搜索从Control字符串和选择项目,如果它与它匹配
You need to have a TextBox to receive the Serach String as input.
您需要处理的文本框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 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" };
}
}
}
当然这是可能的,但这很丑陋,我不会把它称为自己的下拉菜单,尽管它在技术上讲非常接近“下拉菜单”。你在哪里以及如何把它放在你的公司,而不是我们的。 –