本文整理汇总了C#中System.Windows.Forms.Control.Select方法的典型用法代码示例。如果您正苦于以下问题:C# Control.Select方法的具体用法?C# Control.Select怎么用?C# Control.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.Control
的用法示例。
在下文中一共展示了Control.Select方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ActivateControl
public bool ActivateControl(Control ctrl)
{
if (Controls.Contains(ctrl))
{
ctrl.Select();
activeControl = ctrl;
return true;
}
return false;
}
示例2: AfterAllClear
public static void AfterAllClear(Control rate, Control pokemonNames)
{
if (Settings.Default.NoInputRate) {
pokemonNames.BeginInvoke((MethodInvoker)(() => {
pokemonNames.Select();
}));
} else {
rate.BeginInvoke((MethodInvoker)(() => {
rate.Select();
}));
}
}
示例3: IsCommand
internal static bool IsCommand(Control tb) {
if (tb.Text.Trim().Length != 0)
return true;
tb.Select();
return false;
}
示例4: FileExists
internal static bool FileExists(Control tb) {
if (File.Exists(tb.Text))
return true;
tb.Select();
return false;
}
示例5: SelectNextControl
public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
Control c;
#if DebugFocus
Console.WriteLine("{0}", this.FindForm());
printTree(this, "\t");
#endif
if (!this.Contains(ctl) || (!nested && (ctl.parent != this))) {
ctl = null;
}
c = ctl;
do {
c = GetNextControl(c, forward);
if (c == null) {
if (wrap) {
wrap = false;
continue;
}
break;
}
#if DebugFocus
Console.WriteLine("{0} {1}", c, c.CanSelect);
#endif
if (c.CanSelect && ((c.parent == this) || nested) && (c.tab_stop || !tabStopOnly)) {
c.Select (true, true);
return true;
}
} while (c != ctl); // If we wrap back to ourselves we stop
return false;
}
示例6: SelectNextActiveControl
private static void SelectNextActiveControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap)
{
ContainerControl control = ctl as ContainerControl;
if (control != null)
{
bool flag = true;
if (control.ParentInternal != null)
{
IContainerControl containerControlInternal = control.ParentInternal.GetContainerControlInternal();
if (containerControlInternal != null)
{
containerControlInternal.ActiveControl = control;
flag = containerControlInternal.ActiveControl == control;
}
}
if (flag)
{
ctl.SelectNextControl(null, forward, tabStopOnly, nested, wrap);
}
}
else
{
ctl.Select();
}
}
示例7: EnterLeaveFocusEventTest
public void EnterLeaveFocusEventTest ()
{
if (TestHelper.RunningOnUnix) {
Assert.Ignore ("Relies on form.Show() synchronously generating WM_ACTIVATE");
}
Form f = new Form();
f.ShowInTaskbar = false;
f.Name = "Form1";
ContainerControl cc0 = new ContainerControl();
cc0.Name = "ContainerControl 0";
ContainerControl cc1 = new ContainerControl();
cc1.Name = "ContainerControl 1";
ContainerControl cc2 = new ContainerControl();
cc2.Name = "ContainerControl 2";
Control c1 = new Control();
c1.Name = "Control 1";
Control c2 = new Control();
c2.Name = "Control 2";
connect(f);
connect(cc0);
connect(cc1);
connect(cc2);
connect(c1);
connect(c2);
cc0.Controls.Add(cc1);
cc0.Controls.Add(cc2);
cc1.Controls.Add(c1);
cc2.Controls.Add(c2);
f.Controls.Add(cc0);
sb = new StringBuilder ();
f.Show ();
c1.Select();
Assert.AreEqual (@"OnEnter: ContainerControl 0 System.Windows.Forms.ContainerControl
OnEnter: ContainerControl 1 System.Windows.Forms.ContainerControl
OnEnter: Control 1 System.Windows.Forms.Control
OnGotFocus: Control 1 System.Windows.Forms.Control
",
sb.ToString (), "1");
sb.Length = 0;
c2.Select();
Assert.AreEqual (@"OnLeave: Control 1 System.Windows.Forms.Control
OnLeave: ContainerControl 1 System.Windows.Forms.ContainerControl
OnValidating: Control 1 System.Windows.Forms.Control
OnValidated: Control 1 System.Windows.Forms.Control
OnValidating: ContainerControl 1 System.Windows.Forms.ContainerControl
OnValidated: ContainerControl 1 System.Windows.Forms.ContainerControl
OnEnter: ContainerControl 2 System.Windows.Forms.ContainerControl
OnEnter: Control 2 System.Windows.Forms.Control
OnLostFocus: Control 1 System.Windows.Forms.Control
OnGotFocus: Control 2 System.Windows.Forms.Control
",
sb.ToString (), "2");
sb.Length = 0;
cc1.Select();
Assert.AreEqual (@"OnLeave: Control 2 System.Windows.Forms.Control
OnLeave: ContainerControl 2 System.Windows.Forms.ContainerControl
OnValidating: Control 2 System.Windows.Forms.Control
OnValidated: Control 2 System.Windows.Forms.Control
OnValidating: ContainerControl 2 System.Windows.Forms.ContainerControl
OnValidated: ContainerControl 2 System.Windows.Forms.ContainerControl
OnEnter: ContainerControl 1 System.Windows.Forms.ContainerControl
OnLostFocus: Control 2 System.Windows.Forms.Control
OnGotFocus: ContainerControl 1 System.Windows.Forms.ContainerControl
",
sb.ToString (), "3");
sb.Length = 0;
cc2.Select();
Assert.AreEqual (@"OnLeave: ContainerControl 1 System.Windows.Forms.ContainerControl
OnValidating: ContainerControl 1 System.Windows.Forms.ContainerControl
OnValidated: ContainerControl 1 System.Windows.Forms.ContainerControl
OnEnter: ContainerControl 2 System.Windows.Forms.ContainerControl
OnLostFocus: ContainerControl 1 System.Windows.Forms.ContainerControl
OnGotFocus: ContainerControl 2 System.Windows.Forms.ContainerControl
",
sb.ToString (), "4");
Assert.IsNull (cc2.ActiveControl, "5");
sb.Length = 0;
c2.Select();
Assert.AreEqual (@"OnEnter: Control 2 System.Windows.Forms.Control
OnLostFocus: ContainerControl 2 System.Windows.Forms.ContainerControl
OnGotFocus: Control 2 System.Windows.Forms.Control
",
sb.ToString (), "6");
sb.Length = 0;
cc1.Select();
Assert.AreEqual (@"OnLeave: Control 2 System.Windows.Forms.Control
OnLeave: ContainerControl 2 System.Windows.Forms.ContainerControl
//.........这里部分代码省略.........
示例8: ChangeContentObjectIfPossible
/// <summary>
/// Create and install an object to fill the content area of the window, after asking the current
/// content object if it is willing to go away.
/// </summary>
protected void ChangeContentObjectIfPossible(string contentAssemblyPath, string contentClass, XmlNode contentClassNode)
{
// This message often gets sent twice with the same values during startup. We save a LOT of time if
// we don't throw one copy away and make another.
if (m_mainContentControl != null && contentAssemblyPath == m_lastContentAssemblyPath
&& contentClass == m_lastContentClass && contentClassNode == m_lastContentClassNode)
{
return;
}
if (m_mainContentControl != null)
{
// First, see if the existing content object is ready to go away.
if (!MainContentControlAsIxCoreContentControl.PrepareToGoAway())
return;
PropertyTable.SetProperty("currentContentControlObject", null, false);
PropertyTable.SetPropertyPersistence("currentContentControlObject", false);
m_mediator.RemoveColleague(MainContentControlAsIxCoreColleague);
foreach (IxCoreColleague icc in MainContentControlAsIxCoreColleague.GetMessageTargets())
m_mediator.RemoveColleague(icc);
// Dispose the current content object.
//m_mainContentControl.Hide();
//m_secondarySplitContainer.SecondControl = m_mainContentPlaceholderPanel;
// Hide the first pane for sure so that MultiPane's internal splitter will be set
// correctly. See LT-6515.
m_mediator.PropertyTable.SetProperty("ShowRecordList", false, false);
m_secondarySplitContainer.Panel1Collapsed = true;
m_mainContentControl.Dispose(); // before we create the new one, it inactivates the Clerk, which the new one may want active.
m_mainContentControl = null;
}
m_lastContentAssemblyPath = contentAssemblyPath;
m_lastContentClass = contentClass;
m_lastContentClassNode = contentClassNode;
if (contentAssemblyPath != null)
{
// create the new content object
try
{
m_secondarySplitContainer.Panel2.SuspendLayout();
Control mainControl = (Control)DynamicLoader.CreateObject(contentAssemblyPath, contentClass);
if (!(mainControl is IxCoreContentControl))
{
m_mainSplitContainer.SecondControl = m_mainContentPlaceholderPanel;
throw new ApplicationException("XCore can only handle main controls which implement IxCoreContentControl. " + contentClass + " does not.");
}
mainControl.SuspendLayout();
m_mainContentControl = mainControl;
m_mainContentControl.Dock = System.Windows.Forms.DockStyle.Fill;
m_mainContentControl.AccessibleDescription = "XXXXXXXXXXXX";
m_mainContentControl.AccessibleName = contentClass;
m_mainContentControl.TabStop = true;
m_mainContentControl.TabIndex = 1;
XmlNode parameters = null;
if (contentClassNode != null)
parameters = contentClassNode.SelectSingleNode("parameters");
m_secondarySplitContainer.SetSecondCollapseZone(parameters);
MainContentControlAsIxCoreColleague.Init(m_mediator, parameters);
// We don't want it or any part of it drawn until we're done laying out.
// Also, layout tends not to actually happen until we make it visible, which further helps avoid duplication,
// and makes sure the user doesn't see any intermediate state.
m_mainContentControl.Visible = false;
m_secondarySplitContainer.SecondControl = m_mainContentControl;
mainControl.ResumeLayout(false);
var mainContentAsPostInit = m_mainContentControl as IPostLayoutInit;
//this was added because the user may switch to a control through some UI vector that does not
//first set the appropriate area. Doing this will lead to the appropriate area button being highlighted, and also
//help other things which depend on the accuracy of this "areaChoice" property.
PropertyTable.SetProperty("currentContentControlObject", m_mainContentControl);
PropertyTable.SetPropertyPersistence("currentContentControlObject", false);
PropertyTable.SetProperty("areaChoice", MainContentControlAsIxCoreContentControl.AreaName);
if (contentClassNode != null && contentClassNode.ParentNode != null)
SetToolDefaultProperties(contentClassNode.ParentNode.SelectSingleNode("defaultProperties"));
m_mainContentControl.BringToFront();
m_secondarySplitContainer.Panel2.ResumeLayout();
if (mainContentAsPostInit != null)
mainContentAsPostInit.PostLayoutInit();
m_mainContentControl.Visible = true;
m_mainContentControl.Select();
}
catch (Exception error)
{
m_mainContentControl = null;
m_secondarySplitContainer.SecondControl = m_mainContentPlaceholderPanel;
m_secondarySplitContainer.Panel2.ResumeLayout();
string s = "Something went wrong trying to create a " + contentClass + ".";
ErrorReporter.ReportException(new ApplicationException(s, error),
ApplicationRegistryKey, m_mediator.FeedbackInfoProvider.SupportEmailAddress);
//.........这里部分代码省略.........
示例9: IsValidData
/// <summary>
/// Validates user input
/// </summary>
/// <param name="control">The control to be validated</param>
/// <returns>Returns true or false is the input is valid</returns>
public bool IsValidData(Control control)
{
#region Input Validation
if (control == null)
{
throw new ArgumentNullException("Control");
}
#endregion //Input Validation
// Prevents the 'Invalid data' warning from showing up if the user selects 'No' to saving the record
if (mainForm == null || mainForm.FormClosed)
{
return true;
}
ControlFactory factory = ControlFactory.Instance;
Field field = factory.GetAssociatedField(control);
bool isValid = true;
if (field is NumberField)
{
((MaskedTextBox)control).TextMaskFormat = MaskFormat.IncludeLiterals;
string decimalSeparator = System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;
if (!String.IsNullOrEmpty(control.Text) && !control.Text.Trim().Equals(decimalSeparator))
{
if (field is IPatternable)
{
string pattern = ((IPatternable)field).Pattern;
if (control.Text.Length > 39 && pattern == "None")
{
MsgBox.ShowWarning(SharedStrings.MAX_NONE_MASK_DIGITS_EXCEEDED);
control.Select();
isValid = false;
}
else
{
try
{
// Test what is in the box. If we catch a format exception then the
// user entered something bad, like -- or just a decimal point. They
// may also have entered some text if the field doesn't have a pattern. // doesn't have a pattern.
string TestNumber = control.Text.Replace(" ", "");
//!float.TryParse(TestNumber, out temp)
float temp;
if (float.TryParse(TestNumber, out temp))
{
temp = float.Parse(TestNumber, System.Globalization.NumberStyles.Any);
((MaskedTextBox)control).Text = FormatNumberInput(TestNumber, ((MaskedTextBox)control).Mask);
((MaskedTextBox)control).TextMaskFormat = MaskFormat.IncludeLiterals;
string format = AppData.Instance.DataPatternsDataTable.GetExpressionByMask(((MaskedTextBox)(control)).Mask.ToString(), ((IPatternable)field).Pattern);
bool result;
double doubleNumber;
result = Double.TryParse(((MaskedTextBox)control).Text, out doubleNumber);
if (result)
{
NumberField checkedField = (NumberField)field;
if (!string.IsNullOrEmpty(checkedField.Lower) && !string.IsNullOrEmpty(checkedField.Upper))
{
if ((double.Parse(checkedField.Lower) > doubleNumber) || (doubleNumber > double.Parse(checkedField.Upper)))
{
//FIX for DEFECT 1080
MsgBox.ShowWarning(String.Format(SharedStrings.VALUE_NOT_IN_RANGE, checkedField.Lower, checkedField.Upper));
control.Select();
isValid = false;
}
}
}
}
else
{
MsgBox.ShowInformation(SharedStrings.ENTER_VALID_NUMBER);
control.Select();
isValid = false;
}
}
catch (FormatException)
{
MsgBox.ShowWarning(SharedStrings.ENTER_VALID_NUMBER);
control.Text = string.Empty;
control.Select();
isValid = false;
}
}
}
}
}
else if (field is DateField)
{
DateTime dateTime;
bool canParse = DateTime.TryParse(control.Text, out dateTime);
//.........这里部分代码省略.........
示例10: setFocusOnError
private void setFocusOnError(Control controlInError)
{
// 1. Ensure the proper page is shown
Control parentTabPage = controlInError.Parent;
while (parentTabPage != null && parentTabPage.GetType() != typeof(TabPage))
{
parentTabPage = parentTabPage.Parent;
}
if (parentTabPage != null && parentTabPage.GetType() == typeof(TabPage))
{
m_gui.getTabControl().SelectedTab = (TabPage)parentTabPage;
}
// 2. Put the keyboard focus within the control in error
controlInError.Select();
}
示例11: ListViewEditable_MouseUp
void ListViewEditable_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
ListViewItem lvi = this.GetItemAt(1, e.Y);
if (lvi == null) return;
// Find which column.
mSubItemColumn = 0;
int sum = 0;
if (this.Columns.Count > 1)
{
for (int i = 0; i < Columns.Count; i++)
{
sum += Columns[i].Width;
if (e.X < sum) { mSubItemColumn = i; break; }
}
}
editingSubItem = lvi.SubItems[mSubItemColumn];
editingItem = lvi;
bool change = (editingSubItem == previousItem);
previousItem = editingSubItem;
lvi.Selected = true;
if (change)
{
mEditor = GetControlAtIndex(mSubItemColumn,editingItem.Index);
if (mEditor != null)
{
Rectangle bounds = editingSubItem.Bounds;
//if (this.CheckBoxes && mSubItemColumn == 0)
// bounds.Offset(new Point(22, 0));
mEditor.Bounds = bounds;
mEditor.Text = editingSubItem.Text;
mEditor.Visible = true;
mEditor.BringToFront();
//mEditor.Focus();
mEditor.Select();
}
}
}
}
示例12: GetNextControl
// Select the next control.
public bool SelectNextControl
(Control ctl, bool forward, bool tabStopOnly,
bool nested, bool wrap)
{
if (!Contains(ctl) || !nested && ctl.parent != this)
ctl = null;
Control control = ctl;
// Look for the next control we can select.
do
{
ctl = GetNextControl(ctl, forward);
if (ctl == null)
{
if (!wrap)
break;
continue;
}
if (ctl.CanSelect && (ctl.TabStop || !tabStopOnly) && (nested || ctl.parent == this))
{
// Found a control.
ctl.Select(true, forward);
return true;
}
}
while (ctl != control);
// Did not find a control.
return false;
}
示例13: EditItem
private void EditItem(int index, ListViewItem.ListViewSubItem sb)
{
if (this.SelectedItems.Count <= 0)
{
return;
}
int currentSelectColumnIndex = _mCtrls.IndexOfKey(index);
if (currentSelectColumnIndex == -1)
{
return;
}
_currentCtrl = (System.Windows.Forms.Control)_mCtrls.Values[currentSelectColumnIndex];
ListViewItem item = this.SelectedItems[0];
Rectangle rect = sb.Bounds;
Rectangle _rect = new Rectangle(rect.Right - this.Columns[index].Width, rect.Top, this.Columns[index].Width, rect.Height);
_currentCtrl.Bounds = _rect;
_currentCtrl.BringToFront();
_currentCtrl.Text = item.SubItems[index].Text;
_currentCtrl.TextChanged += CtrTextChanged;
_currentCtrl.Leave += CtrLeave;
_currentCtrl.Visible = true;
_currentCtrl.Tag = item;
_currentCtrl.Select();
}
示例14: Show
public static string Show(Control owner)
{
if (owner == null)
throw new Exception("owner is null!");
Self._owner = owner;
int xPos = owner.RectangleToScreen(Rectangle.Empty).X;
int yPos = owner.RectangleToScreen(Rectangle.Empty).Y + Self._owner.Height + 5;
Self.TopMost = true;
if (!Self.Visible)
Self.Show();
Self.Location = new Point(xPos, yPos);
owner.Select();
return string.Empty;
}
示例15: ForceShowAndSelect
/// <summary>
/// Force un contrôle et tous ses conteneurs à être visibles, puis sélectionne le contrôle.
/// </summary>
/// <remarks>
/// Cette méthode prend en charge tous les classeurs à onglets qui sont les conteneurs
/// directs ou indirects du contrôle de manière à forcer la sélection de la page concernée
/// au sein de chaque classeur à onglets.
/// </remarks>
/// <param name="control">contrôle à rendre effectivement visible et sélectionné</param>
public static void ForceShowAndSelect( Control control ) {
// contrôle de l'argument : ignorer si null
if ( control == null ) return;
// remontée récursive frontale jusqu'au conteneur top-level
Control parent = control.Parent;
if ( parent != null ) ForceShowAndSelect( parent );
// descente de la récursion : traiter le cas des pages des classeurs à onglets
TabPage controlAsTabPage = control as TabPage;
TabControl parentAsTabControl = parent as TabControl;
// le contrôle n'est pas une page, ou n'est pas hébergé par un classeur à onglets
if ( controlAsTabPage == null || parentAsTabControl == null ) {
control.Show();
control.Select();
return;
}
// le contrôle est une page hébergée par un classeur à onglets : sélectionner la page
parentAsTabControl.SelectedTab = controlAsTabPage;
control.Select();
}