本文整理汇总了C#中System.Windows.Forms.ComboBox.FindString方法的典型用法代码示例。如果您正苦于以下问题:C# ComboBox.FindString方法的具体用法?C# ComboBox.FindString怎么用?C# ComboBox.FindString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.ComboBox
的用法示例。
在下文中一共展示了ComboBox.FindString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetCamListCombobox
//GetCamList
public static void GetCamListCombobox(ComboBox c)
{
WebCamList = c;
try
{
VideoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
WebCamList.Items.Clear();
foreach (FilterInfo device in VideoDevices)
{
WebCamList.Items.Add(device.Name);
}
if (Properties.Settings.Default.WebCamDevice == null)
{
WebCamList.SelectedIndex = 0; //First cam found is default
}
else
{
WebCamList.SelectedIndex = WebCamList.FindString(Properties.Settings.Default.WebCamDevice);
}
}
catch (ApplicationException)
{
//DeviceExist = false;
WebCamList.Items.Add("No capture device on your system");
}
}
示例2: GetCamSettingsCombobox
//GetCamSettings
public static void GetCamSettingsCombobox(ComboBox c)
{
WebCamSettings = c;
try
{
videoSource = new VideoCaptureDevice(VideoDevices[WebCamList.SelectedIndex].MonikerString);
WebCamSettings.Items.Clear();
//DeviceExist = true;
foreach (var capability in videoSource.VideoCapabilities)
{
WebCamSettings.Items.Add(capability.FrameSize.Width.ToString() + " x " + capability.FrameSize.Height.ToString() + " " + capability.AverageFrameRate.ToString() + " fps");
}
if (Properties.Settings.Default.WebCamResolution == null || Properties.Settings.Default.WebCamDevice != Convert.ToString(WebCamList.SelectedItem))
{
WebCamSettings.SelectedIndex = 0;
}
else
{
WebCamSettings.SelectedIndex = WebCamSettings.FindString(Properties.Settings.Default.WebCamResolution);
}
}
catch (ArgumentOutOfRangeException)
{
//DeviceExist = false;
WebCamSettings.Items.Add("No capture device on your system");
}
}
示例3: AutoComplete_KeyUp
private void AutoComplete_KeyUp(ComboBox comboBox2, KeyEventArgs e)
{
string sTypedText = null;
int iFoundIndex = 0;
object oFoundItem = null;
string sFoundText = null;
string sAppendText = null;
//Allow select keys without Autocompleting
switch (e.KeyCode)
{
case Keys.Back:
case Keys.Left:
case Keys.Right:
case Keys.Up:
case Keys.Delete:
case Keys.Down:
case Keys.ShiftKey:
case Keys.Shift:
case Keys.RShiftKey:
case Keys.LShiftKey:
case Keys.Oem1:
case Keys.Oem102:
case Keys.Oem2:
case Keys.Oem3:
case Keys.Oem4:
case Keys.Oem5:
case Keys.Oem6:
case Keys.Oem7:
case Keys.Oem8:
return;
}
//Get the Typed Text and Find it in the list
sTypedText = comboBox2.Text;
iFoundIndex = comboBox2.FindString(sTypedText);
//If we found the Typed Text in the list then Autocomplete
if (iFoundIndex >= 0)
{
//Get the Item from the list (Return Type depends if Datasource was bound or List Created)
oFoundItem = comboBox2.Items[iFoundIndex];
//Use the ListControl.GetItemText to resolve the Name in case the Combo was Data bound
sFoundText = comboBox2.GetItemText(oFoundItem);
//Append then found text to the typed text to preserve case
sAppendText = sFoundText.Substring(sTypedText.Length);
comboBox2.Text = sTypedText + sAppendText;
//Select the Appended Text
comboBox2.SelectionStart = sTypedText.Length;
comboBox2.SelectionLength = sAppendText.Length;
label10.Text = ((Person)oFoundItem).Name;
label11.Text = ((Person)oFoundItem).Email;
label12.Text = ((Person)oFoundItem).SSN;
}
}
示例4: fillCountry
public static void fillCountry(ComboBox objCmbCountry,String CountryCode)
{
//DataTable objDT = new DataTable("Country");
//DataRow objRow;
//DataColumn objcol =new DataColumn("ContryName",typeof(System.String));
//objDT.Columns.Add(objcol);
//objcol =new DataColumn("ContryId",typeof(System.String));
//objDT.Columns.Add(objcol);
XmlNodeReader objXmlReader;
DataSet ds = new DataSet();
XmlDocument objOutXml = new XmlDocument();
String strInput = "<MS_LISTCOUNTRY_OUTPUT><COUNTRY COUNTRY_CODE='0' COUNTRY_NAME='Select one'/><COUNTRY COUNTRY_CODE='BD' COUNTRY_NAME='Bangladesh'/><COUNTRY COUNTRY_CODE='IN' COUNTRY_NAME='India' /><COUNTRY COUNTRY_CODE='NP' COUNTRY_NAME='Nepal' /> <COUNTRY COUNTRY_CODE='LK' COUNTRY_NAME='Srilanka' /><COUNTRY COUNTRY_CODE='BT' COUNTRY_NAME='Bhutan' /><COUNTRY COUNTRY_CODE='ML' COUNTRY_NAME='Maldives' /><COUNTRY COUNTRY_CODE='TB' COUNTRY_NAME='TBA' /> <Errors Status='False'><Error Code='' Description='' /></Errors></MS_LISTCOUNTRY_OUTPUT>";
objOutXml.LoadXml(strInput);
objXmlReader = new XmlNodeReader(objOutXml);
ds.ReadXml(objXmlReader);
objCmbCountry.DataSource = ds.Tables["COUNTRY"];
objCmbCountry.DisplayMember = "COUNTRY_NAME";
objCmbCountry.ValueMember = "COUNTRY_CODE";
objCmbCountry.SelectedIndex = 0;
if (CountryCode !="")
{
objCmbCountry.SelectedIndex = objCmbCountry.FindString("India");
}
}
示例5: FormShow
public void FormShow(ref ComboBox cb, ref RichTextBox rt1, ref RichTextBox rt2, ref TextBox rt3, ref RichTextBox rt4, ref ComboBox rt5, ref TextBox rt6, ref ComboBox rt7, ref ComboBox rt8, ref ComboBox rt9, ref ComboBox rt10, ref ComboBox rt11, ref ComboBox rt12)
{
cb.Text = EntData[0];
rt3.Text = EntData[1].Substring(EntData[1].IndexOf("-") + 1);
rt1.Text = EntData[4];
rt2.Text = EntData[5];
rt4.Text = EntData[6];
rt5.Text = EntData[8];
rt6.Text = EntData[9];
rt7.SelectedIndex = rt7.FindString(CommonMethods.ConvertToHours(Bh));
rt8.SelectedIndex = rt8.FindString(CommonMethods.ConvertToHours(Ubh));
rt9.Text = ProjectType;
rt10.Text = HaveWork;
if (UserStory.Equals(" "))
{
rt11.SelectedIndex = 0;
}
else
{
rt11.Text = UserStory;
}
if (ShiftTimings.Equals(" "))
{
rt12.SelectedIndex = 0;
}
else
{
rt12.Text = ShiftTimings;
}
}
示例6: RefreshCurveEqComboBox
public void RefreshCurveEqComboBox(ComboBox cb, INCCAnalysisParams.CurveEquationVals v)
{
cb.Items.Clear();
foreach (INCCAnalysisParams.CurveEquation cs in System.Enum.GetValues(typeof(INCCAnalysisParams.CurveEquation)))
{
//Per Martyn, use equation string, not named value. 7/17/2014 HN
cb.Items.Add(cs.ToDisplayString());
}
cb.Refresh();
cb.SelectedIndex = cb.FindString (v.cal_curve_equation.ToDisplayString());
}
示例7: AutoComplete
public void AutoComplete(ComboBox cb, System.Windows.Forms.KeyPressEventArgs e, bool limitToList)
{
string strFindStr = "";
if (e.KeyChar == (char)8)
{
if (cb.SelectionStart <= 1)
{
cb.Text = "";
return;
}
if (cb.SelectionLength == 0)
strFindStr = cb.Text.Substring(0, cb.Text.Length - 1);
else
strFindStr = cb.Text.Substring(0, cb.SelectionStart - 1);
}
else
{
if (cb.SelectionLength == 0)
strFindStr = cb.Text + e.KeyChar;
else
strFindStr = cb.Text.Substring(0, cb.SelectionStart) + e.KeyChar;
}
int intIdx = -1;
// 在combox中搜索字符串
intIdx = cb.FindString(strFindStr);
if (intIdx != -1)
{
cb.SelectedText = "";
cb.SelectedIndex = intIdx;
cb.SelectionStart = strFindStr.Length;
cb.SelectionLength = cb.Text.Length;
e.Handled = true;
}
else
{
e.Handled = limitToList;
}
}
示例8: FindString_StartIndex_ItemCount
public void FindString_StartIndex_ItemCount ()
{
Thread.CurrentThread.CurrentCulture = new CultureInfo ("tr-TR");
ComboBox cmbbox = new ComboBox ();
cmbbox.Items.AddRange (new object [] { "BA", "BB" });
Assert.AreEqual (0, cmbbox.FindString ("b", 1));
}
示例9: UpdateSelection
private static void UpdateSelection(ComboBox cb, string s)
{
var i = cb.FindString(s);
if (i != -1)
{
cb.SelectedText = "";
cb.SelectedIndex = i;
cb.SelectionStart = s.Length;
cb.SelectionLength = cb.Text.Length;
}
}
示例10: WordPadFormat
public WordPadFormat(WordPad wordpad) {
FontFamily[] fontFamilies;
this.wordpad = wordpad;
Height = 21;
fonts = new ComboBox();
sizes = new ComboBox();
fonts.DropDownStyle = ComboBoxStyle.DropDownList;
fontFamilies = FontFamily.Families;
fonts.BeginUpdate( );
foreach ( FontFamily ff in fontFamilies ) {
fonts.Items.Add( ff.Name );
}
fonts.EndUpdate();
fonts.Location = new Point(0, 0);
fonts.Width = 150;
fonts.SelectedIndex = fonts.FindString("Arial");
fonts.SelectedIndexChanged += new EventHandler(fonts_SelectedIndexChanged);
sizes.DropDownStyle = ComboBoxStyle.DropDownList;
sizes.Location = new Point(160, 0);
sizes.Width = 50;
sizes.Items.AddRange(new string[] {"8", "9", "10", "11", "12", "14", "16", "18", "20", "22", "24", "26", "28", "36", "48", "72"});
Console.WriteLine ("font height: {0}", wordpad.edit.Font.Height.ToString ());
sizes.SelectedItem = wordpad.edit.Font.Height.ToString ();
sizes.SelectedIndexChanged += new EventHandler(sizes_SelectedIndexChanged);
this.Controls.Add(fonts);
this.Controls.Add(sizes);
}
示例11: FindStringExact_StartIndex_ItemCount
public void FindStringExact_StartIndex_ItemCount ()
{
Thread.CurrentThread.CurrentCulture = new CultureInfo ("tr-TR");
ComboBox cmbbox = new ComboBox ();
cmbbox.Items.AddRange (new object [] { "AB", "BA", "AB", "BA" });
#if NET_2_0
Assert.AreEqual (1, cmbbox.FindStringExact ("BA", 3));
#else
try {
cmbbox.FindString ("BA", 3);
Assert.Fail ("#1");
} catch (ArgumentOutOfRangeException ex) {
Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
Assert.IsNotNull (ex.ParamName, "#5");
Assert.AreEqual ("startIndex", ex.ParamName, "#6");
}
#endif
}
示例12: SelectCurrentRadius
/// <summary>
/// Sets the radius drop down selected item to the one that is set in fsx.cfg
/// </summary>
public void SelectCurrentRadius(ComboBox comboBox, [Optional]string radius)
{
// Method variables
string formattedRadius;
using (IniFile iniFile = new IniFile())
{
/// <switch>fsx.cfg</switch>
iniFile.IniPath = Application.StartupPath + @"\locations.ini";
iniFile.IniPath = iniFile.ReadValue("LOCATIONS", "cfg") + @"\fsx.cfg";
if (radius != null)
{
// Format the radius
using (Format format = new Format())
formattedRadius = format.Compact(radius);
// Set the current selected item
comboBox.SelectedIndex = comboBox.FindString(formattedRadius, -1);
// Set the index to the first
if (comboBox.SelectedIndex == -1)
comboBox.SelectedIndex = 0;
}
else
{
using (Format format = new Format())
{
// Set the radius to the current one in fsx.cfg
comboBox.SelectedIndex = comboBox.FindString(format.Compact(iniFile.ReadValue("TERRAIN", "LOD_RADIUS")), -1);
// Set the index to the first
if (comboBox.SelectedIndex == -1)
comboBox.SelectedIndex = 0;
}
}
}
}
示例13: SelectCurrentResolution
/// <summary>
/// Sets the resolution drop down selected item to the one that is set in fsx.cfg
/// </summary>
public void SelectCurrentResolution(ComboBox comboBox, [Optional]string resolution)
{
using (IniFile iniFile = new IniFile())
{
iniFile.IniPath = Application.StartupPath + @"\locations.ini";
iniFile.IniPath = iniFile.ReadValue("LOCATIONS", "cfg") + @"\fsx.cfg";
if (resolution != null)
{
comboBox.SelectedIndex = comboBox.FindString(resolution, -1);
if (comboBox.SelectedIndex == -1)
comboBox.SelectedIndex = 0;
}
else
{
comboBox.SelectedIndex = comboBox.FindString(iniFile.ReadValue("GRAPHICS", "TEXTURE_MAX_LOAD"), -1);
if (comboBox.SelectedIndex == -1)
comboBox.SelectedIndex = 0;
}
}
}
示例14: FindString
public void FindString ()
{
Thread.CurrentThread.CurrentCulture = new CultureInfo ("tr-TR");
ComboBox cmbbox = new ComboBox ();
Assert.AreEqual (-1, cmbbox.FindString ("Hello"), "#A1");
Assert.AreEqual (-1, cmbbox.FindString (string.Empty), "#A2");
Assert.AreEqual (-1, cmbbox.FindString (null), "#A3");
Assert.AreEqual (-1, cmbbox.FindString ("Hola", -5), "#A4");
Assert.AreEqual (-1, cmbbox.FindString ("Hola", 40), "#A5");
cmbbox.Items.AddRange (new object [] { "in", "BADTest", "IN", "BAD", "Bad", "In" });
Assert.AreEqual (2, cmbbox.FindString ("I"), "#B1");
Assert.AreEqual (0, cmbbox.FindString ("in"), "#B2");
Assert.AreEqual (1, cmbbox.FindString ("BAD"), "#B3");
Assert.AreEqual (1, cmbbox.FindString ("Bad"), "#B4");
Assert.AreEqual (1, cmbbox.FindString ("b"), "#B5");
Assert.AreEqual (0, cmbbox.FindString (string.Empty), "#B6");
Assert.AreEqual (-1, cmbbox.FindString (null), "#B7");
Assert.AreEqual (3, cmbbox.FindString ("b", 2), "#C1");
Assert.AreEqual (5, cmbbox.FindString ("I", 3), "#C2");
Assert.AreEqual (4, cmbbox.FindString ("B", 3), "#C3");
Assert.AreEqual (1, cmbbox.FindString ("B", 4), "#C4");
Assert.AreEqual (5, cmbbox.FindString ("I", 4), "#C5");
Assert.AreEqual (4, cmbbox.FindString ("BA", 3), "#C6");
Assert.AreEqual (0, cmbbox.FindString ("i", -1), "#C7");
Assert.AreEqual (3, cmbbox.FindString (string.Empty, 2), "#C8");
Assert.AreEqual (-1, cmbbox.FindString (null, 1), "#C9");
cmbbox.Items.Add (string.Empty);
Assert.AreEqual (0, cmbbox.FindString (string.Empty), "#D1");
Assert.AreEqual (-1, cmbbox.FindString (null), "#D2");
Assert.AreEqual (4, cmbbox.FindString (string.Empty, 3), "#E1");
Assert.AreEqual (-1, cmbbox.FindString (null, 99), "#E2");
Assert.AreEqual (-1, cmbbox.FindString (null, -5), "#E3");
}
示例15: AutoCompleteOnKeyPress
/// <summary>
/// Autocomplete a combobox on keypress
/// </summary>
/// <param name="comboBox"></param>
/// <param name="e"></param>
public static void AutoCompleteOnKeyPress(ComboBox comboBox, KeyPressEventArgs e)
{
if (Char.IsControl(e.KeyChar))
return;
string stringToFind = comboBox.Text.Substring(0, comboBox.SelectionStart) + e.KeyChar;
int index = comboBox.FindStringExact(stringToFind);
if (index == -1)
index = comboBox.FindString(stringToFind);
if (index == -1)
return;
comboBox.SelectedIndex = index;
comboBox.SelectionStart = stringToFind.Length;
comboBox.SelectionLength = comboBox.Text.Length - comboBox.SelectionStart;
e.Handled = true;
}