本文整理汇总了C#中System.Windows.Forms.Control.Focus方法的典型用法代码示例。如果您正苦于以下问题:C# Control.Focus方法的具体用法?C# Control.Focus怎么用?C# Control.Focus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.Control
的用法示例。
在下文中一共展示了Control.Focus方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckControlInput
public static bool CheckControlInput(Control ctrl, string strCaption, int iLength, bool blnNumber)
{
try
{
if (ctrl.GetType().ToString() == "System.Windows.Forms.TextBox")
{
if (ctrl.Text.Trim() == "")
{
MsgBoxExclamation(strCaption + "不能为空,请输入" + strCaption);
ctrl.Focus();
((TextBox)ctrl).SelectAll();
return false;
}
else if (iLength > 0 && ctrl.Text.Length != iLength)
{
MsgBoxExclamation("请输入" + iLength.ToString() + "位" + strCaption);
ctrl.Focus();
((TextBox)ctrl).SelectAll();
return false;
}
if (blnNumber && !IsNumeric(ctrl.Text))
{
MsgBoxExclamation(strCaption + "必须为数字,请重新输入");
ctrl.Focus();
((TextBox)ctrl).SelectAll();
return false;
}
}
else if (ctrl.GetType().ToString() == "System.Windows.Forms.ComboBox")
{
if (ctrl.Text.Trim() == "")
{
MsgBoxExclamation(strCaption + "不能为空,请选择" + strCaption);
ctrl.Focus();
return false;
}
}
else
{
if (ctrl.Text.Trim() == "")
{
MsgBoxExclamation(strCaption + "不能为空,请输入" + strCaption);
ctrl.Focus();
return false;
}
}
return true;
}
catch (System.Exception e)
{
MsgBoxException(e.Message, "GlobalFunction.CheckControlInput");
return false;
}
}
示例2: PopupEditorHost
public PopupEditorHost(Control control,
int left, int top, int width, int height,
Func<Control, object> getControlValue,
Action<object> onValueUpdated)
: this()
{
this.getControlValue = getControlValue;
this.onValueUpdated = onValueUpdated;
Content = control;
Margin = Padding.Empty;
Padding = Padding.Empty;
//AutoSize = true;
Width = width;
Height = height;
Left = left;
Top = top;
Content.Dock = DockStyle.Fill;
BindContentHandlers();
var host = new ToolStripControlHost(Content)
{
Margin = Padding.Empty,
Padding = Padding.Empty,
AutoSize = false,
Width = width,
Height = height
};
Items.Add(host);
Opened += (sender, e) => Content.Focus();
}
示例3: ActivateNextControl
private void ActivateNextControl()
{
if ( CurrentControl == null )
{
CurrentControl = ControlOrder[0];
CurrentControl.Focus();
CurrentControl.BackColor = Color.Yellow;
return;
}
var currentIndex = ControlOrder.IndexOf( CurrentControl );
CurrentControl.BackColor = Color.Gray;
if ( ControlOrder.Count > currentIndex + 1 )
{
CurrentControl = ControlOrder[currentIndex + 1];
CurrentControl.Focus();
CurrentControl.BackColor = Color.Yellow;
}
else
{
kbd_SaveAndReboot.Visible = true;
kbd_SaveAndReboot.Enabled = true;
}
}
示例4: ShowError
/// <summary>
/// ȱʡ����ControlValueNullException��ʽ
/// </summary>
/// <param name="ex"></param>
public void ShowError(object invalidControl, string msg)
{
if (invalidControl == null)
{
throw new ArgumentNullException("invalidControl");
}
IWindowControl windowControl = invalidControl as IWindowControl;
if (windowControl != null)
{
//ClearError();
if (m_firstInvalidControl == null)
{
m_firstInvalidControl = windowControl.Control;
//if (ex.InvalidDataControl is Feng.Windows.Forms.DataControlWrapper)
//{
// m_invalidControl = ex.InvalidDataControl as Control;
//}
m_firstInvalidControl.Focus();
}
ShowErrorIcon(windowControl.Control, msg);
}
else
{
ServiceProvider.GetService<IMessageBox>().ShowWarning(msg);
}
}
示例5: btnGuardar_Click
private void btnGuardar_Click(object sender, EventArgs e)
{
//Esta forma de validar, valida de a uno los errores. Como errores particulares
//en este formulario tengo este por ahora. No lo veo mal. Habría que ver cómo se lleva
//con los errores propios de los controles (validar campo obligatorio de user control texto y demás)
primerControlInvalido = null;
this.ValidateChildren();
if (primerControlInvalido != null) primerControlInvalido.Focus();
else
{
Dictionary<String, gdDataBase.ValorTipo> camposValores = new Dictionary<string, gdDataBase.ValorTipo>();
Dictionary<int, String> errorMensaje = new Dictionary<int, string>();
camposValores.Add("fecha_salida", new gdDataBase.ValorTipo(dateTimePickerSalida.Value.ToString("yyyy-MM-dd HH:mm:ss.000"), SqlDbType.DateTime));
camposValores.Add("fecha_llegada_estimada", new gdDataBase.ValorTipo(dateTimePickerEstimada.Value.ToString("yyyy-MM-dd HH:mm:ss.000"), SqlDbType.DateTime));
camposValores.Add("hoy", new gdDataBase.ValorTipo(Config.fecha.ToString(), SqlDbType.DateTime));
camposValores.Add("matricula", new gdDataBase.ValorTipo(textBoxMatricula.Text, SqlDbType.VarChar));
camposValores.Add("id_ruta", new gdDataBase.ValorTipo(idRuta.ToString(), SqlDbType.VarChar));
errorMensaje.Add(60007, "La matricula ingresada no pertenece a ninguna Aeronave");
errorMensaje.Add(600012, "La ruta ingresada no existe");
errorMensaje.Add(600015, "El servicio brindado por la aeronave no coincide con el de la ruta");
errorMensaje.Add(600016, "La aeronave ya posee un viaje en esas fechas");
var ejecucion = new SPPureExec("ÑUFLO.GenerarViaje", camposValores, errorMensaje, "Viaje registrado correctamente");
ejecucion.Exec();
if (!ejecucion.huboError())
limpiar();
}
}
示例6: Show
void Show(string title, string text, Control control, ICON icon = 0, double timeOut = 0, bool allowMulti = false, bool focus = false, short x = 0, short y = 0)
{
if (!allowMulti)
CloseAll();
if (x == 0 && y == 0)
{
x = (short)(control.RectangleToScreen(control.ClientRectangle).Left + control.Width / 2);
y = (short)(control.RectangleToScreen(control.ClientRectangle).Top + control.Height / 2);
}
TOOLINFO toolInfo = new TOOLINFO();
toolInfo.cbSize = (uint)Marshal.SizeOf(toolInfo);
toolInfo.uFlags = 0x20; // TTF_TRACK
toolInfo.lpszText = text;
IntPtr pToolInfo = Marshal.AllocCoTaskMem(Marshal.SizeOf(toolInfo));
Marshal.StructureToPtr(toolInfo, pToolInfo, false);
byte[] buffer = Encoding.UTF8.GetBytes(title);
buffer = buffer.Concat(new byte[] { 0 }).ToArray();
IntPtr pszTitle = Marshal.AllocCoTaskMem(buffer.Length);
Marshal.Copy(buffer, 0, pszTitle, buffer.Length);
hWnd = User32.CreateWindowEx(0x8, "tooltips_class32", "", 0xC3, 0, 0, 0, 0, control.Parent.Handle, (IntPtr)0, (IntPtr)0, (IntPtr)0);
User32.SendMessage(hWnd, 1028, (IntPtr)0, pToolInfo); // TTM_ADDTOOL
User32.SendMessage(hWnd, 1042, (IntPtr)0, (IntPtr)((ushort)x | ((ushort)y << 16))); // TTM_TRACKPOSITION
//User32.SendMessage(hWnd, 1043, (IntPtr)0, (IntPtr)0); // TTM_SETTIPBKCOLOR
//User32.SendMessage(hWnd, 1044, (IntPtr)0xffff, (IntPtr)0); // TTM_SETTIPTEXTCOLOR
User32.SendMessage(hWnd, 1056, (IntPtr)icon, pszTitle); // TTM_SETTITLE 0:None, 1:Info, 2:Warning, 3:Error, >3:assumed to be an hIcon. ; 1057 for Unicode
User32.SendMessage(hWnd, 1048, (IntPtr)0, (IntPtr)500); // TTM_SETMAXTIPWIDTH
User32.SendMessage(hWnd, 0x40c, (IntPtr)0, pToolInfo); // TTM_UPDATETIPTEXT; 0x439 for Unicode
User32.SendMessage(hWnd, 1041, (IntPtr)1, pToolInfo); // TTM_TRACKACTIVATE
Marshal.FreeCoTaskMem(pszTitle);
Marshal.DestroyStructure(pToolInfo, typeof(TOOLINFO));
Marshal.FreeCoTaskMem(pToolInfo);
if (focus)
control.Focus();
control.Enter += control_Event;
control.Leave += control_Event;
control.TextChanged += control_Event;
control.KeyPress += control_Event;
control.Click += control_Event;
control.LocationChanged += control_Event;
control.SizeChanged += control_Event;
control.VisibleChanged += control_Event;
if (control is DataGridView)
((DataGridView)control).CellBeginEdit += control_Event;
Control parent = control.Parent;
while(parent != null)
{
parent.VisibleChanged += control_Event;
parent = parent.Parent;
}
control.TopLevelControl.LocationChanged += control_Event;
((Form)control.TopLevelControl).Deactivate += control_Event;
timer.AutoReset = false;
timer.Elapsed += timer_Elapsed;
if (timeOut > 0)
{
timer.Interval = timeOut;
timer.Start();
}
}
示例7: ModelCamera
public ModelCamera(Control focusControl, ControlRender dev)
{
mControl = focusControl;
focusControl.MouseClick += (obj, e) => focusControl.Focus();
mDevice = dev.Device;
mInput = dev.InputManager;
mDevice.SetTransform(TransformState.View, Matrix.LookAtLH(mPosition, Vector3.Zero, Vector3.UnitZ));
}
示例8: EmptyPrivateKeyField
private void EmptyPrivateKeyField(Control focusControl)
{
PrivateKey.PasswordChar = (char)0;
PrivateKey.Text = _enterPhrase;
PrivateKey.TextAlign = HorizontalAlignment.Center;
PrivateKey.ForeColor = Color.LightGray;
focusControl.Focus();
}
示例9: TryFocusInvalidInput
public static bool TryFocusInvalidInput(ErrorProvider errorProvider, Control control)
{
if (!string.IsNullOrEmpty(errorProvider.GetError(control)))
{
control.Focus();
return true;
}
return false;
}
示例10: LoadProcessInControl
public static void LoadProcessInControl(string _Process, Control _Control)
{
System.Diagnostics.Process p = System.Diagnostics.Process.Start(_Process);
p.WaitForInputIdle();
_Control.Focus();
Native.SetParent(p.MainWindowHandle, _Control.Handle);
ShowWindow(p, SW_SHOWMAXIMIZED);
}
示例11: Validate
/// <summary>
/// 验证所有的控件,如果失败弹出信息并重定位焦点
/// </summary>
/// <param name="ctr">被验证控件</param>
/// <param name="message">验证失败弹出的消息</param>
/// <returns>失败返回false,成功返回true</returns>
public static bool Validate(Control ctr, string message)
{
bool result = Validate(ctr);
if (!result)
{
MessageBoxHelper.Show(message);
ctr.Focus();
}
return result;
}
示例12: Focus
//# __________ PROTOCOL :: PRIVATE __________ #//
public void Focus(Control c)
{
c.Focus();
if( c is TextBox ) ((TextBox)c).SelectAll();
if( c is Button )
{
ButtonGotFocusType ev = _buttonFocusMap[(Button)c];
if( ev != null ) ev();
}
}
示例13: AlertMessage
private bool AlertMessage(string msg, Control txtObj)
{
if (!string.IsNullOrEmpty(msg))
{
pnlLoading.Controls.Add(LoadingCtrl.LoadModel(MessageType.Error, msg));
txtObj.Focus();
return false;
}
return true;
}
示例14: ShowView
public void ShowView(IView view) {
if (_View != null) {
Controls.Remove(_View);
_View = null;
}
_View = view as Control;
Controls.Add(_View);
_View.Dock = DockStyle.Fill;
_View.Focus();
}
示例15: ErreurSaisie
public static void ErreurSaisie(Control txtSaisie, string message)
{
// affichage des messages d'erreur avec mise en évidence de l'erreur
MessageBox.Show(message);
if (txtSaisie is TextBox)
{
((TextBox)txtSaisie).SelectionStart = 0;
((TextBox)txtSaisie).SelectionLength = txtSaisie.Text.Length;
}
txtSaisie.Focus();
}