本文整理汇总了C#中System.Windows.Forms.Control.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Control.GetType方法的具体用法?C# Control.GetType怎么用?C# Control.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.Control
的用法示例。
在下文中一共展示了Control.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LocalizeControl
public static void LocalizeControl(Control control, ResourceManager resourceManager)
{
if ((resourceManager == null) || (control == null))
return;
string text = null;
//Text of Control proper
try
{
text = resourceManager.GetString(control.GetType().Namespace.Replace(".", "_") + "_" + control.GetType().Name + "_Text");
if (!string.IsNullOrEmpty(text))
control.Text = text;
}
catch (System.Resources.MissingManifestResourceException)
{
//just ignore
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("Error when localizing: " + control.Name + ":\r\n" + ex.ToString());
}
//the Controls owned by this control
FieldInfo[] fis = control.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
foreach (FieldInfo fi in fis)
{
LocalizeField(control, resourceManager, fi, "Text");
LocalizeField(control, resourceManager, fi, "Caption");
}
}
示例2: IsPresent
public static bool IsPresent(Control control)
{
if (control.GetType().ToString() == "System.Windows.Forms.TextBox")
{
TextBox textBox = (TextBox)control;
if (textBox.Text == "")
{
MessageBox.Show(textBox.Tag.ToString() + " is a required field.", Title);
textBox.Focus();
return false;
}
else
{
return true;
}
}
else if (control.GetType().ToString() == "System.Windows.Forms.ComboBox")
{
ComboBox comboBox = (ComboBox)control;
if (comboBox.SelectedIndex == -1)
{
MessageBox.Show(comboBox.Tag.ToString() + " is a required field.", Title);
comboBox.Focus();
return false;
}
else
{
return true;
}
}
return true;
}
示例3: InsertControl
public void InsertControl(Control control)
{
if (control != null)
{
CCWin.SkinControl.ILockBytes bytes;
CCWin.SkinControl.IStorage storage;
CCWin.SkinControl.IOleClientSite site;
Guid guid = Marshal.GenerateGuidForType(control.GetType());
CCWin.Win32.NativeMethods.CreateILockBytesOnHGlobal(IntPtr.Zero, true, out bytes);
CCWin.Win32.NativeMethods.StgCreateDocfileOnILockBytes(bytes, 0x1012, 0, out storage);
this.IRichEditOle.GetClientSite(out site);
REOBJECT lpreobject = new REOBJECT();
lpreobject.cp = this._richEdit.TextLength;
lpreobject.clsid = guid;
lpreobject.pstg = storage;
lpreobject.poleobj = Marshal.GetIUnknownForObject(control);
lpreobject.polesite = site;
lpreobject.dvAspect = 1;
lpreobject.dwFlags = 2;
lpreobject.dwUser = 1;
this.IRichEditOle.InsertObject(lpreobject);
Marshal.ReleaseComObject(bytes);
Marshal.ReleaseComObject(site);
Marshal.ReleaseComObject(storage);
}
}
示例4: SetControlPropertyThreadSafe
public static void SetControlPropertyThreadSafe(Control control, string propertyName, object propertyValue)
{
if (control == null)
{
throw new ArgumentNullException("control");
}
if (control.InvokeRequired)
{
if (control.IsHandleCreated)
{
try
{
control.Invoke(new SetControlPropertyThreadSafeDelegate(SetControlPropertyThreadSafe), new object[] { control, propertyName, propertyValue });
}
catch { }
}
}
else
{
if (!control.IsDisposed)
{
try
{
control.GetType().InvokeMember(propertyName, BindingFlags.SetProperty, null, control, new object[] { propertyValue });
}
catch { }
}
}
}
示例5: SetValue
public static void SetValue(Control control, string value)
{
if (control.GetType() == typeof(CheckBox))
((CheckBox)control).Checked = Convert.ToBoolean(value);
else
throw new Exception(_ExceptionControlNotRecognised);
}
示例6: SetClickEventHandler
public void SetClickEventHandler(Control control)
{
foreach (Control childControl in control.Controls)
SetClickEventHandler(childControl);
if (control.GetType() != typeof(DevExpress.XtraEditors.TextBoxMaskBox) && control.GetType() != typeof(DevExpress.XtraEditors.TextEdit) && control.GetType() != typeof(DevExpress.XtraEditors.MemoEdit) && control.GetType() != typeof(DevExpress.XtraEditors.ComboBoxEdit) && control.GetType() != typeof(DevExpress.XtraEditors.LookUpEdit) && control.GetType() != typeof(DevExpress.XtraEditors.DateEdit) && control.GetType() != typeof(DevExpress.XtraEditors.CheckedListBoxControl) && control.GetType() != typeof(DevExpress.XtraEditors.SpinEdit) && control.GetType() != typeof(DevExpress.XtraEditors.CheckEdit) && control.GetType() != typeof(DevExpress.XtraEditors.TimeEdit))
control.Click += new EventHandler(ControlClick);
}
示例7: IsLockableControl
protected override bool IsLockableControl(Control c)
{
return base.IsLockableControl(c)
|| c.GetType().FullName == dens + "TextEdit"
|| c.GetType().FullName == dens + "CheckEdit"
|| false;
}
示例8: LocalizeField
private static void LocalizeField(Control control, ResourceManager resourceManager, FieldInfo fi, string propertyName)
{
MemberInfo[] mia = fi.FieldType.GetMember(propertyName);
if (mia.GetLength(0) > 0)
{
try
{
string resourceName = control.GetType().Namespace.Replace(".", "_") + "_" + control.GetType().Name + "_" + fi.Name + "_" + propertyName;
string localizedText = resourceManager.GetString(resourceName);
if (localizedText == null)
{
}
else if (!string.IsNullOrEmpty(localizedText))
{
Object o = fi.GetValue(control);
if (o != null)
{
PropertyInfo pi = o.GetType().GetProperty(propertyName);
if (pi != null)
{
pi.SetValue(o, localizedText, null);
}
}
}
}
catch (System.Resources.MissingManifestResourceException)
{
//just ignore
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("Error when localizing: " + fi.Name + ":\r\n" + ex.ToString());
}
}
}
示例9: ColorUIWrapper
/// <summary>
/// Creates a new instance.
/// </summary>
/// <param name="colorEditor">The editor this instance belongs to.</param>
public ColorUIWrapper(XNAColorUITypeEditor colorEditor)
{
Type colorUiType = typeof(ColorEditor).GetNestedType("ColorUI", BindingFlags.CreateInstance | BindingFlags.NonPublic);
ConstructorInfo constructorInfo = colorUiType.GetConstructor(new Type[] { typeof(ColorEditor) });
_control = (Control)constructorInfo.Invoke(new object[] { colorEditor });
_control.BackColor = System.Drawing.SystemColors.Control;
Panel alphaPanel = new Panel();
alphaPanel.BackColor = System.Drawing.SystemColors.Control;
alphaPanel.Dock = DockStyle.Right;
alphaPanel.Width = 28;
_control.Controls.Add(alphaPanel);
_tbAlpha = new TrackBar();
_tbAlpha.Orientation = Orientation.Vertical;
_tbAlpha.Dock = DockStyle.Fill;
_tbAlpha.TickStyle = TickStyle.None;
_tbAlpha.Maximum = byte.MaxValue;
_tbAlpha.Minimum = byte.MinValue;
_tbAlpha.ValueChanged += new EventHandler(OnTrackBarAlphaValueChanged);
alphaPanel.Controls.Add(_tbAlpha);
_lblAlpha = new Label();
_lblAlpha.Text = "0";
_lblAlpha.Dock = DockStyle.Bottom;
_lblAlpha.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
alphaPanel.Controls.Add(_lblAlpha);
_startMethodInfo = _control.GetType().GetMethod("Start");
_endMethodInfo = _control.GetType().GetMethod("End");
_valuePropertyInfo = _control.GetType().GetProperty("Value");
_control.SizeChanged += new EventHandler(OnControlSizeChanged);
}
示例10: IsPresent
public static bool IsPresent(Control ctlControl, string strName)
{
bool blnResult = false;
if (ctlControl.GetType().ToString() == "System.Windows.Forms.TextBox")
{
TextBox txtTextBox = (TextBox)ctlControl;
if (txtTextBox.Text.Length == 0)
{
ShowError(strName + " is a required field.");
txtTextBox.Focus();
}
else
{
blnResult = true;
}
}
else if (ctlControl.GetType().ToString() == "System.Windows.Forms.ComboBox")
{
ComboBox cboComboBox = (ComboBox)ctlControl;
if (cboComboBox.SelectedIndex == -1)
{
ShowError(strName + " is a required field.");
cboComboBox.Focus();
}
else
{
blnResult = true;
}
}
return blnResult;
}
示例11: EmulateEdit
static void EmulateEdit( Control grid, object cell, string text )
{
EmulateActivate( grid , cell);
grid.GetType().GetMethod( "BeginEdit" ).Invoke( grid, new object[] { false } );
var control = (Control)grid.GetType().GetMethod( "get_EditingControl" ).Invoke( grid, new object[0] );
control.Text = text;
grid.GetType().GetMethod( "EndEdit", new Type[0] ).Invoke( grid, new object[0] );
}
示例12: GetImageIndex
private int GetImageIndex(Control aControl) {
string _Key = aControl.GetType().Name;
if (fHashtable.Contains(_Key)) {
return (int) fHashtable[_Key];
} else {
return AddImage(_Key, ToolboxBitmapAttribute.Default.GetImage(aControl.GetType()));
}
}
示例13: GetImageIndex
// *********************************************************************
// Public
// *********************************************************************
/// <summary>
/// Gets image index.
/// </summary>
/// <param name="control">Control</param>
/// <returns>Index.</returns>
public int GetImageIndex(Control control) {
int _Index = base.GetImageIndex(control.GetType().Name);
if (_Index < 0) {
return AddImage(control.GetType().Name, ToolboxBitmapAttribute.Default.GetImage(control.GetType()));
} else {
return _Index;
}
}
示例14: 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;
}
}
示例15: IsPresent
public static bool IsPresent(Control control)
{
if (control.GetType().ToString() == "System.Windows.Forms.TextBox")
{
TextBox textBox = (TextBox)control;
if (textBox.Text == "")
{
// MessageBox.Show(textBox.Tag + @" is a required field.", Title);
errProvider.SetError(textBox, textBox.Tag + @" is a required field.");
textBox.Focus();
textBox.SelectAll();
return false;
}
else
{
errProvider.SetError(textBox, "");
return true;
}
}
else if(control.GetType().ToString() == "System.Windows.Forms.ComboBox")
{
ComboBox comboBox = (ComboBox)control;
if (comboBox.Text == "")
{
//MessageBox.Show(comboBox.Tag.ToString() + " is a required field.", Title);
errProvider.SetError(comboBox, comboBox.Tag + @" is a required field.");
comboBox.Focus();
comboBox.SelectAll();
return false;
}
else
{
errProvider.SetError(comboBox, "");
return true;
}
}
else if (control.GetType().ToString() == "System.Windows.Forms.MaskedTextBox")
{
MaskedTextBox makBox = (MaskedTextBox) control;
if (makBox.Text == "")
{
errProvider.SetError(makBox, makBox.Tag + @" is a required field ");
makBox.Focus();
makBox.SelectAll();
}
else
{
errProvider.SetError(makBox, "");
return true;
}
}
return true;
}