本文整理汇总了C#中System.Windows.Forms.ListBox.Focus方法的典型用法代码示例。如果您正苦于以下问题:C# ListBox.Focus方法的具体用法?C# ListBox.Focus怎么用?C# ListBox.Focus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.ListBox
的用法示例。
在下文中一共展示了ListBox.Focus方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsSelected
public bool IsSelected(ListBox listbox)
{
if (Convert.ToInt32(listbox.SelectedIndex) == -1)
{
MessageBox.Show("Du måste välja en låt i listan!");
listbox.Focus();
return false;
}
return true;
}
开发者ID:Zaitzewsky,项目名称:Informatik-B--Objektorienterad-programmering-med-C-,代码行数:10,代码来源:ValideringInData.cs
示例2: OnKeyPress
private void OnKeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == '.')
{
int position = _tbCode.SelectionStart;
string parameter = GetActiveParameter(_tbCode.Text.Substring(0, position));
var cb = new ListBox { Cursor = Cursors.Arrow };
var methods = new List<string>();
if (AutoCompletion.GetProperties(_scriptScope, parameter, methods))
{
methods.ForEach(m => cb.Items.Add(m));
var f = new Font("Microsoft Sans Serif", 9F);
cb.Width = 300;
_tbCode.Controls.Add(cb);
cb.Location = GetListBoxLocation();
cb.Focus();
cb.SelectedIndex = 0;
cb.Sorted = true;
cb.Height = 200;
cb.Font = f;
cb.DoubleClick += (o, i) =>
{
var s = cb.SelectedItem.ToString();
_tbCode.Text = _tbCode.Text.Insert(position + 1, s);
_tbCode.Controls.Remove(cb);
_tbCode.SelectionStart = position + 1 + s.Length;
_tbCode.SelectionLength = 0;
_tbCode.ScrollToCaret();
};
cb.KeyPress += (o, ev) =>
{
if (ev.KeyChar == (int)Keys.Enter)
{
var s = cb.SelectedItem.ToString();
_tbCode.Text = _tbCode.Text.Insert(position + 1, s);
_tbCode.Controls.Remove(cb);
_tbCode.SelectionStart = position + 1 + s.Length;
_tbCode.SelectionLength = 0;
_tbCode.ScrollToCaret();
}
};
}
}
}
示例3: MoveBoxItem
private void MoveBoxItem(ListBox src, ListBox dest)
{
if (src.SelectedItem == null) {
return;
}
if (((TableMapping)src.SelectedItem).Mode == MappingMode.Frozen) {
return;
}
var selIndex = src.SelectedIndex - 1;
var seletedItems = new List<object>();
foreach (var item in src.SelectedItems) {
seletedItems.Add(item);
}
dest.Items.AddRange(seletedItems.ToArray());
foreach (var item in seletedItems) {
src.Items.Remove(item);
}
if (src.Items.Count > 0) {
src.SelectedIndex = selIndex < 0 ? 0 : selIndex;
}
src.Focus();
}
示例4: AutoCompleteTextBox
public static void AutoCompleteTextBox(TextBox txtControl, ListBox lstControl,
List<string> lstAutoCompleteList, KeyEventArgs txtControlKEA)
{
Point cp;
GetCaretPos(out cp);
List<string> lstTemp = new List<string>();
//Positioning the Listbox on TextBox by Type Insertion Cursor position
lstControl.SetBounds(cp.X + txtControl.Location.X, cp.Y + txtControl.Location.Y + 20, 150, 50);
var TempFilteredList = lstAutoCompleteList.Where
(n => n.StartsWith(GetLastString(txtControl.Text))).Select(r => r);
lstTemp = TempFilteredList.ToList<string>();
if (lstTemp.Count != 0 && GetLastString(txtControl.Text) != "")
{
lstControl.DataSource = lstTemp;
lstControl.Show();
lstControl.BringToFront();
}
else
{
lstControl.Hide();
}
//Code for focusing ListBox Items While Pressing Down and UP Key.
if (txtControlKEA.KeyCode == Keys.Down)
{
lstControl.SelectedIndex = 0;
lstControl.Focus();
txtControlKEA.Handled = true;
}
else if (txtControlKEA.KeyCode == Keys.Up)
{
lstControl.SelectedIndex = lstControl.Items.Count - 1;
lstControl.Focus();
txtControlKEA.Handled = true;
}
//text box key press event
txtControl.KeyPress += (s, kpeArgs) =>
{
if (kpeArgs.KeyChar == (char)Keys.Enter)
{
if (lstControl.Visible)
{
lstControl.Focus();
}
kpeArgs.Handled = true;
}
else if (kpeArgs.KeyChar == (char)Keys.Escape)
{
lstControl.Visible = false;
kpeArgs.Handled = true;
}
else if (kpeArgs.KeyChar == (char)Keys.Tab)
{
txtControl.Text = ((ListBox)s).SelectedItem.ToString();
txtControl.Select(txtControl.Text.Length, 0);
txtControl.Focus();
lstControl.Hide();
}
};
txtControl.LostFocus += (s, eventArgs) =>
{
if (!lstControl.Focused)
lstControl.Hide();
};
//listbox keyup event
lstControl.KeyUp += (s, kueArgs) =>
{
if (kueArgs.KeyCode == Keys.Tab)
{
//string StrLS = GetLastString(txtControl.Text);
//int LIOLS = txtControl.Text.LastIndexOf(StrLS);
//string TempStr = txtControl.Text.Remove(LIOLS);
//txtControl.Text = TempStr + ((ListBox)s).SelectedItem.ToString();
txtControl.Text = ((ListBox)s).SelectedItem.ToString();
txtControl.Select(txtControl.Text.Length, 0);
txtControl.Focus();
lstControl.Hide();
}
else if (kueArgs.KeyCode == Keys.Escape)
{
lstControl.Hide();
txtControl.Focus();
}
};
}
示例5: chooseType
private void chooseType(int selectedIndex, ListBox sender)
{
changeCurrentTypeAndRefreshLists((TypeVisualUnit)sender.Items[selectedIndex]);
sender.Focus();
}