本文整理汇总了C#中System.Windows.Forms.ComboBox.Select方法的典型用法代码示例。如果您正苦于以下问题:C# ComboBox.Select方法的具体用法?C# ComboBox.Select怎么用?C# ComboBox.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.ComboBox
的用法示例。
在下文中一共展示了ComboBox.Select方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestNullSelectedText
[Test] // bug 660294
public void TestNullSelectedText ()
{
ComboBox comboBox = new ComboBox ();
string text = "abc";
comboBox.Items.Add (text);
comboBox.SelectedIndex = 0;
comboBox.Select (0, text.Length);
comboBox.SelectedText = null;
Assert.AreEqual (String.Empty, comboBox.SelectedText);
}
示例2: CreateManualFileEntryControl
private void CreateManualFileEntryControl(object sender, EventArgs e)
{
if (_fileCombo != null &&_fileCombo.Visible)
{
_fileCombo.Visible = false;
Controls.Remove(_fileCombo);
return;
}
string currentDirectory;
if (BreadCrumbTrail.Items.Count > 2)
currentDirectory = (string)BreadCrumbTrail.Items[BreadCrumbTrail.Items.Count - 1].Tag;
else if (_overflowStack.Any())
currentDirectory = (string) _overflowStack.Peek().Tag;
else
currentDirectory = string.Empty;
_fileCombo = new ComboBox
{
Text = currentDirectory,
Anchor =
AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right,
Width = BreadCrumbTrail.Width - BreadCrumbTrail.Items[0].Width + HistoryButton.Width-1,
Location = new Point(BreadCrumbTrail.Items[0].Width,0),
FlatStyle = FlatStyle.Flat,
AutoCompleteMode = AutoCompleteMode.SuggestAppend,
AutoCompleteSource = AutoCompleteSource.FileSystemDirectories
};
_fileCombo.Items.Add(currentDirectory);
var history = FolderHistoryInterface.GetRecentFolders();
foreach (var item in history.Where(item => !string.IsNullOrEmpty(item) && item != currentDirectory))
_fileCombo.Items.Add(item);
_fileCombo.KeyDown += (x, y) =>
{
if (y.KeyCode == Keys.Return)
{
y.Handled = true;
if (Directory.Exists(_fileCombo.Text))
{
_fileCombo.Visible = false;
Controls.Remove(_fileCombo);
Navigate(_fileCombo.Text.TrimEnd('\\'), null);
}
else
MessageBox.Show("Directory does not exist");
}
else if (y.KeyCode == Keys.Escape)
{
_fileCombo.Visible = false;
Controls.Remove(_fileCombo);
return;
}
};
Controls.Add(_fileCombo);
_fileCombo.Select();
_fileCombo.SelectionStart = _fileCombo.Text.Length;
if (sender == HistoryButton)
_fileCombo.DroppedDown = true;
_fileCombo.BringToFront();
}
示例3: AddMidpoint
private void AddMidpoint(SolarSystem systemToAdd)
{
//Get a count of all the ComboBox's in the panel
int controlCount = 0;
foreach (Control cont in pnlMidpoints.Controls)
if (cont.GetType() == typeof(ComboBox))
controlCount++;
//Configure the textbox to be similar to the start / end desto properties
ComboBox newTextBox = new ComboBox();
pnlMidpoints.Controls.Add(newTextBox);
newTextBox.ValueMember = "SolarSystemID";
newTextBox.DisplayMember = "SolarSystemName";
newTextBox.DropDownStyle = ComboBoxStyle.Simple;
newTextBox.Tag = controlCount + 1;
if (systemToAdd.SolarSystemName != null)
{
//If the system parsed is a legit system, set the combo box's text and selected item to the parsed system
newTextBox.Text = systemToAdd.SolarSystemName;
newTextBox.Items.Add(systemToAdd);
newTextBox.SelectedItem = systemToAdd;
}
//We dont store each individual solar system, so when they select an item from the dropdown, just close it backup.
newTextBox.SelectedIndexChanged += (object o, EventArgs e) =>
{
newTextBox.Size = new Size(newTextBox.Size.Width, 23);
};
//When the textbox text is updated, behave EXACTLY like the static start / desto boxes
newTextBox.TextUpdate += (object o, EventArgs e) =>
{
newTextBox.Items.Clear();
//Get the containers current sizes
Size contSize = newTextBox.Size;
string userText = newTextBox.Text;
//If the user has entered 3 or more chars, lets do a lookup. If its less... Ignore it, we dont want to search this vague
if (userText.Length >= 3)
{
//Get all systems that are similar to the entered values
IEnumerable<SolarSystem> systems = _dataRepository.GetSolarSystemsLikeName(userText);
if (systems.Count() > 0)
{
newTextBox.Items.AddRange(systems.ToArray());
//New items were added, so we want to display the drop down so they can select one. They MUST select one.
newTextBox.DropDownStyle = ComboBoxStyle.Simple;
//Height of the drop down is either 121 if the list height exceedes 121, with a height of 21 for each item. If less, the drop down is equal to minimum height for the items.
int height = ((systems.Count() * 21) > 100) ? 121 : ((systems.Count() * 21) + 21);
//Re-size the combo back to standard if less than 3 values entered. This is because they might exceed 3, then backspace.
newTextBox.Size = new Size(contSize.Width, height);
newTextBox.BringToFront();
}
else
//If there are no systems, hide the drop down (Even if its not shown)
newTextBox.Size = new Size(contSize.Width, 21);
}
else
{
//If there are no systems, hide the drop down (Even if its not shown)
newTextBox.Size = new Size(contSize.Width, 21);
}
//Highlight the whole combobox, and put the cursor at the end
newTextBox.Select(newTextBox.Text.Length, 0);
//Bring the dropdown to the front so nothing obstructs it.
newTextBox.BringToFront();
};
newTextBox.Size = new Size(140, 21);
//Calcualate the next logical position based on the existing controls. 10 padding
if (controlCount > 0)
newTextBox.Location = new Point(10, ((controlCount * 21) + controlCount * 9) + 9);
else
newTextBox.Location = new Point(10, 9);
}