当前位置: 首页>>代码示例>>C#>>正文


C# Control.GetType方法代码示例

本文整理汇总了C#中System.Windows.Controls.Control.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Control.GetType方法的具体用法?C# Control.GetType怎么用?C# Control.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Controls.Control的用法示例。


在下文中一共展示了Control.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: IsPresent

            public static bool IsPresent(Control control)
            {
                if (control.GetType().ToString() == "System.Windows.Forms.TextBox")
                {
                    TextBox textBox = (TextBox)control;
                    if (textBox.Text == "")
                    {

                        //textBox.Focus();
                        return false;
                    }
                    else
                    {
                        return true;
                    }
                }
                else if (control.GetType().ToString() == "System.Windows.Forms.ComboBox")
                {
                    ComboBox comboBox = (ComboBox)control;
                    if (comboBox.SelectedIndex == -1)
                    {

                        // comboBox.Focus();
                        return false;
                    }
                    else
                    {
                        return true;
                    }
                }
                return true;
            }
开发者ID:ohnoitsfraa,项目名称:2TIN_dotNetAdvanced,代码行数:32,代码来源:Validator.cs

示例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;
        }
开发者ID:ohnoitsfraa,项目名称:2TIN_dotNetAdvanced,代码行数:32,代码来源:Validator.cs

示例3: OKCancelControlContainer

        public OKCancelControlContainer(Control control, string caption)
            : this()
        {
            Name = control.Name;

            if (string.IsNullOrEmpty(Name))
            {
                var type = control.GetType();
                //если контрол собственный, а Name не задан - то подставл¤ем им¤ типа
                Name = type.Namespace.StartsWith("System.")?null:type.Name;
            }

            if (string.IsNullOrEmpty(Name))
                throw new ArgumentException(Properties.Resources.ControlNameCanNotBeEmpty);
            Title = caption;

            double initialViewWidth = control.Width;
            double initialViewHeight = control.Height;

            Width = initialViewWidth + 22;
            Height = initialViewHeight + 77;

            if (control.MinWidth != 0)
                MinWidth = control.MinWidth + 22;

            if (control.MinHeight != 0)
                MinHeight = control.MinHeight + 77;

            //			if (control.MaxWidth != 0)
            //				MaxWidth = control.MaxWidth + 22;
            //
            //			if (control.MaxHeight != 0)
            //				MaxHeight = control.MaxHeight + 77;

            control.Width = Double.NaN;
            control.Height = Double.NaN;

            Control = control;

            //если контрол может сам посылать сообщение о закрытии - то подключаем соответствующий обработчик
            if (control is IClosable)
                ((IClosable)control).CloseFired += ClosableControl_CloseFired;

            control.Focus();
        }
开发者ID:vansickle,项目名称:dbexplorer,代码行数:45,代码来源:OKCancelControlContainer.xaml.cs

示例4: Add

        /// <summary>
        /// Adds an element to the navigation stack. It deletes
        /// any forwarding element if the control type is different from 
        /// the forwarding element of current view
        /// </summary>
        /// <param name="control"></param>
        public void Add(Control control)
        {
            if (NavigationStack.Count > 0 && _current > 0)
            {
                int curr = _current;
                for (int i = 0; i < curr; i++)
                {
                    NavigationStack.Pop();
                }
                _current = 0;
            }
            if (NavigationStack.Count == 0 || (NavigationStack.Count > 0 &&
                control.GetType() != NavigationStack.Peek().GetType()))
            {

                NavigationStack.Push(control);
                _current = 0;
            }
            RaisePropertyChanged("Current");
            RaisePropertyChanged("CurrentIndex");
        }
开发者ID:diegoRodriguezAguila,项目名称:SGAM.Elfec.Admin,代码行数:27,代码来源:NavigationService.cs

示例5: RefreshBinding

        public static void RefreshBinding(Control elementToUpdate)
        {
            object safelyCastedElement = elementToUpdate as TextBox;

            // For textbox.
            if (safelyCastedElement != null)
            {
                BindingExpression bindingExpression = elementToUpdate.GetBindingExpression(TextBox.TextProperty);
                RefreshBindingExpression(bindingExpression);
                return;
            }

            safelyCastedElement = elementToUpdate as ContentControl;

            // For content controls.
            if (safelyCastedElement != null)
            {
                BindingExpression bindingExpression = elementToUpdate.GetBindingExpression(ContentControl.ContentProperty);
                RefreshBindingExpression(bindingExpression);
                return;
            }

            Console.WriteLine("Log-Warning : " + string.Format("Binding update for type {0} is not supported.", elementToUpdate.GetType()));
        }
开发者ID:salfab,项目名称:Open-Todo,代码行数:24,代码来源:BindingUpdateHelper.cs

示例6: TogglePadding

 private static void TogglePadding(Control control)
 {
     control.Padding = control.Padding.Left == 0 ? new Thickness(10) : new Thickness(0);
     Output.Write(control.GetType().Name);
     Output.Write("Padding: " + control.Padding);
     Output.Break();
 }
开发者ID:philcockfield,项目名称:Open.TestHarness.SL,代码行数:7,代码来源:VisualButton.ViewTest.cs

示例7: CreateCommandBehavior

        private static CommandBehaviorBase<Control> CreateCommandBehavior(Control control, String eventName)
        {
            var type = control.GetType();
            var behavior = new CommandBehaviorBinder<Control>(control);
            var info = type.GetEvent(eventName);

            if (info != null)
            {
                var methodInfo = behavior.GetType().GetMethod("Execute");
                var handler = Delegate.CreateDelegate(info.EventHandlerType, behavior, methodInfo, true);
                info.AddEventHandler(control, handler);
            }
            else
            {
                throw new ArgumentException(String.Format("Target object '{0}' doesn't have the event '{1}'.", type.Name, eventName));
            }

            return behavior;
        }
开发者ID:brentedwards,项目名称:Movies,代码行数:19,代码来源:Commander.cs

示例8: CheckSpelling

        /// <summary>
        /// Checks the spelling of the specified control.
        /// </summary>
        /// <param name="control">
        /// The control.
        /// </param>
        /// <returns>
        /// The spell checking task.
        /// </returns>
        public async Task<SpellCheckingResult> CheckSpelling(Control control)
        {
            if (control == null)
                throw new ArgumentNullException("control");

            var culture = GetCulture(control);
            SpellCheck.SetCulture(control, culture);

            var getUserDictionaryTask = GetUserDictionaryAsync();
            var getDictionaryTask = GetDictionaryAsync(culture);
            var getIgnoredWordsTask = GetIgnoredWordsAsync();

            await TaskEx.WhenAll(getUserDictionaryTask, getDictionaryTask, getIgnoredWordsTask);

            var userDictionary = getUserDictionaryTask.Result;
            var dictionary = getDictionaryTask.Result;
            var ignoredWords = getIgnoredWordsTask.Result;

            var richTextBox = control as RadRichTextBox;
            if (richTextBox != null)
            {
                var dialog = new CustomSpellCheckingDialog();
                var spellChecker = (DocumentSpellChecker)richTextBox.SpellChecker;
                spellChecker.AddDictionary(dictionary, culture);
                spellChecker.RemoveCustomDictionary(culture);
                spellChecker.RemoveCustomDictionary(CultureInfo.InvariantCulture);
                spellChecker.AddCustomDictionary(userDictionary, CultureInfo.InvariantCulture);
                richTextBox.IgnoredWords = ignoredWords;

                spellChecker.SpellCheckingCulture = culture;
                return await dialog.ShowDialog(new SpellCheckingUIManager(richTextBox), richTextBox);
            }
            else
            {
                var controlSpellChecker = ControlSpellCheckersManager.GetControlSpellChecker(control.GetType());
                if (controlSpellChecker == null)
                    throw new NotImplementedException("No spellcheck for this type of control.");

                var spellChecker = (DocumentSpellChecker)controlSpellChecker.SpellChecker;
                spellChecker.AddDictionary(dictionary, culture);
                spellChecker.RemoveCustomDictionary(culture);
                spellChecker.RemoveCustomDictionary(CultureInfo.InvariantCulture);
                spellChecker.AddCustomDictionary(userDictionary, CultureInfo.InvariantCulture);
                controlSpellChecker.IgnoredWords = ignoredWords;

                spellChecker.SpellCheckingCulture = culture;

                controlSpellChecker.CurrentControl = control;

                var checkAllAtOnceWindow = new SpellCheckAllAtOnceWindow();

                return await checkAllAtOnceWindow.ShowDialog(controlSpellChecker);
            }
        }
开发者ID:mparsin,项目名称:Elements,代码行数:63,代码来源:SpellCheckingService.cs

示例9: PropertyIsEmpty

        /// <summary>
        /// Verifies if the property sent as parameter has its default value.
        /// </summary>
        /// <param name="tb">The control.</param>
        /// <param name="stringProperty">The string property.</param>
        /// <returns>True if the property has the default value; false otherwise</returns>
        private static bool PropertyIsEmpty(Control tb, string stringProperty)
        {
            var propertyIsEmpty = false;
            var propertyInfo = tb.GetType().GetProperty(stringProperty);
            if (propertyInfo != null)
            {
                var propertyType = propertyInfo.DeclaringType;
                var defaultValue = propertyType != null && (propertyType.IsValueType && !(propertyType == typeof(void)))
                                       ? Activator.CreateInstance(propertyType)
                                       : null;
                if (propertyInfo.GetValue(tb, null) == defaultValue)
                {
                    propertyIsEmpty = true;
                }
            }

            return propertyIsEmpty;
        }
开发者ID:skilldrill,项目名称:AttachedBehaviours,代码行数:24,代码来源:WatermarkBehaviour.cs

示例10: ControlToControlName

 /// <summary>
 /// Convert full name of the control to name that will be used for 
 /// creation of bookmakrs
 /// </summary>
 /// <param name="control">
 /// User Control or Control object that can be used
 /// by navigator as a target.
 /// </param>
 /// <returns>Short name of control used for bookmarks</returns>
 public string ControlToControlName(Control control)
 {
   return control.GetType().AssemblyQualifiedName;
 }
开发者ID:BiYiTuan,项目名称:csla,代码行数:13,代码来源:ControlNameFactory.cs

示例11: SaveControlSettings

 /// <summary>
 /// Tries to set user controls to what they were last time the user used the app
 /// </summary>
 public static void SaveControlSettings(Control control)
 {
   try
   {
     if (control.GetType() == typeof(TextBox))
     {
       var textbox = control as TextBox;
       if (textbox == null)
         return;
       Set(textbox.Name, textbox.Text);
     }
     else if (control.GetType() == typeof(TextPlaceholder))
     {
       var textbox = control as TextPlaceholder;
       if (textbox == null)
         return;
       Set(textbox.Name, textbox.Text);
     }
     else if (control.GetType() == typeof(ComboBox))
     {
       var combobox = control as ComboBox;
       if (combobox == null)
         return;
       var elemIndex = combobox.SelectedIndex;
       if (elemIndex != -1)
         Set(combobox.Name, elemIndex.ToString());
     }
     else if (control.GetType() == typeof(CheckBox))
     {
       var checkbox = control as CheckBox;
       if (checkbox == null || !checkbox.IsChecked.HasValue)
         return;
       Set(checkbox.Name, checkbox.IsChecked.Value.ToString());
     }
     else if (control.GetType() == typeof(TabControl))
     {
       var tabcontrol = control as TabControl;
       if (tabcontrol == null)
         return;
       Set(tabcontrol.Name, tabcontrol.SelectedIndex.ToString());
     }
   }
   catch (Exception ex)
   {
     Console.Write(ex.Message);
   }
 }
开发者ID:whztt07,项目名称:BCFier,代码行数:50,代码来源:UserSettings.cs

示例12: LoadControlSettings

  /// <summary>
 /// Tries to set user controls to what they were last time the user used the app
 /// </summary>
 public static void LoadControlSettings(Control control)
 {
   try
   {
     if (control.GetType() == typeof(TextBox))
     {
       var textbox = control as TextBox;
       if (textbox == null)
         return;
       var value = Get(textbox.Name);
       if (!string.IsNullOrEmpty(value))
         textbox.Text = value;
     }
     else if (control.GetType() == typeof(TextPlaceholder))
     {
       var textbox = control as TextPlaceholder;
       if (textbox == null)
         return;
       var value = Get(textbox.Name);
       if (!string.IsNullOrEmpty(value))
         textbox.Text = value;
     }
     else if (control.GetType() == typeof(ComboBox))
     {
       var combobox = control as ComboBox;
       if (combobox == null)
         return;
       var value = Get(combobox.Name);
       if (!string.IsNullOrEmpty(value))
       {
         int elemIndex = 0;
         int.TryParse(value, out elemIndex);
         if (combobox.Items.Count > elemIndex)
           combobox.SelectedIndex = elemIndex;
       }     
     }
     else if (control.GetType() == typeof(CheckBox))
     {
       var checkbox = control as CheckBox;
       if (checkbox == null)
         return;
       bool value;
       if (Boolean.TryParse(Get(checkbox.Name), out value))
         checkbox.IsChecked = value;
     }
     else if (control.GetType() == typeof(TabControl))
     {
       var tabcontrol = control as TabControl;
       if (tabcontrol == null)
         return;
       int value;
       if (int.TryParse(Get(tabcontrol.Name), out value))
         tabcontrol.SelectedIndex = value;
     }
   }
   catch (Exception ex)
   {
     Console.Write(ex.Message);
   }
 }
开发者ID:whztt07,项目名称:BCFier,代码行数:63,代码来源:UserSettings.cs

示例13: attend_on_item

 private void attend_on_item(bool select, Control i)
 {
     if (i.GetType() != Type.GetType("nature_net.user_controls.collection_listbox_item")
         && i.GetType() != Type.GetType("nature_net.user_controls.item_generic_v2"))
         return;
     if (select)
     {
         if (i.GetType() != Type.GetType("nature_net.user_controls.collection_listbox_item"))
             i.Background = Brushes.LightGray;
         else
             i.Opacity = configurations.click_opacity_on_collection_item;
     }
     else
     {
         i.Background = Brushes.Transparent;
         i.Opacity = 1;
     }
 }
开发者ID:jamaher,项目名称:nature-net-ppi,代码行数:18,代码来源:custom_listbox_v2.xaml.cs

示例14: addSubitem

 private static void addSubitem(IEnumerable<Tuple<string, string, int>> tableList, Control item)
 {
     try
     {
         if (item.GetType() != typeof(MenuItem)) return;
         var tempMenus = new List<Control>();
         tempMenus.AddRange(((MenuItem)item).Items.Cast<Control>());
         ((MenuItem)item).Items.Clear();
         var enumerable = tableList as Tuple<string, string, int>[] ?? tableList.ToArray();
         foreach (
             var tm in
                 enumerable.Where(tb => tb.Item2 == item.Name)
                     .Select(tp => tempMenus.FirstOrDefault(m => m.Name == tp.Item1))
                     .Where(tm => tm != null))
         {
             ((MenuItem)item).Items.Add(tm);
             addSubitem(enumerable, tm);
         }
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
     }
 }
开发者ID:hyrmedia,项目名称:PNotes.NET,代码行数:24,代码来源:PNMenus.cs

示例15: CheckDefaultPropertiesEmptyOrNull

        /// <summary>
        /// Checks some default properties not empty or null for the control.
        /// </summary>
        /// <param name="control">The control that is verified</param>
        /// <returns>true if one property is found on the control and is empty or null; false otherwise</returns>
        private static bool CheckDefaultPropertiesEmptyOrNull(Control control)
        {
            // For Password
            var passwordPropertyInfo = control.GetType().GetProperty("Password");
            if (passwordPropertyInfo != null && passwordPropertyInfo.GetValue(control, null).ToString() == string.Empty)
            {
                return true;
            }

            // For rich textbox
            var richTextBoxPropertyInfo = control.GetType().GetProperty("Document");
            if (richTextBoxPropertyInfo != null)
            {
                var richTextBoxvalue = richTextBoxPropertyInfo.GetValue(control, null) as FlowDocument;
                if (richTextBoxvalue != null)
                {
                    var textRange = new TextRange(richTextBoxvalue.ContentStart, richTextBoxvalue.ContentEnd);
                    if (string.IsNullOrWhiteSpace(textRange.Text))
                    {
                        return true;
                    }
                }
            }

            // For Selector
            var comboboxPropertyInfo = control.GetType().GetProperty("SelectedItem");

            if (comboboxPropertyInfo != null && comboboxPropertyInfo.GetValue(control, null) == null)
            {
                return true;
            }

            // For textbox
            var textPropertyInfo = control.GetType().GetProperty("Text");
            return textPropertyInfo != null && textPropertyInfo.GetValue(control, null).ToString() == string.Empty;
        }
开发者ID:skilldrill,项目名称:AttachedBehaviours,代码行数:41,代码来源:WatermarkBehaviour.cs


注:本文中的System.Windows.Controls.Control.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。