System.Windows.Forms.ListBox.FindStringExact C# (CSharp) Method

FindStringExact() public method

public FindStringExact ( string s, int startIndex ) : int
s string
startIndex int
return int
		public int FindStringExact (string s,  int startIndex)
		{
			if (Items.Count == 0)
				return -1; // No exception throwing if empty

			if (startIndex < -1 || startIndex >= Items.Count)
				throw new ArgumentOutOfRangeException ("Index of out range");

			startIndex = (startIndex + 1 == Items.Count) ? 0 : startIndex + 1;

			int i = startIndex;
			while (true) {
				if (String.Compare (GetItemText (Items[i]), s, true) == 0)
					return i;

				i = (i + 1 == Items.Count) ? 0 : i + 1;
				if (i == startIndex)
					break;
			}

			return NoMatches;
		}

Same methods

ListBox::FindStringExact ( string s ) : int

Usage Example

Example #1
0
        public void SetFont(bool cleartype, Font ascii, Font japanese)
        {
            _ignoreEvent               = true;
            _asciiFont                 = ascii;
            _japaneseFont              = japanese;
            _checkClearType.Checked    = cleartype;
            _lASCIISample.ClearType    = cleartype;
            _lJapaneseSample.ClearType = cleartype;
            int s = (int)ascii.Size;

            _fontSizeList.SelectedIndex     = _fontSizeList.FindStringExact(s.ToString());
            _asciiFontList.SelectedIndex    = _asciiFontList.FindStringExact(ascii.Name);
            _japaneseFontList.SelectedIndex = _japaneseFontList.FindStringExact(japanese.Name);

            if (_asciiFontList.SelectedIndex == -1)
            {
                _asciiFontList.SelectedIndex = _asciiFontList.FindStringExact("Courier New");
            }
            if (_japaneseFontList.SelectedIndex == -1)
            {
                _japaneseFontList.SelectedIndex = _japaneseFontList.FindStringExact("MS ゴシック");
            }

            _lASCIISample.Font    = ascii;
            _lJapaneseSample.Font = japanese;
            _ignoreEvent          = false;
        }
All Usage Examples Of System.Windows.Forms.ListBox::FindStringExact