コード例 #1
0
        public static object InvokeProperty(System.Windows.Forms.Control obj, string propertyName, params object[] paramValues)
        {
            Delegate del = null;
            string   key = obj.GetType().Name + "." + propertyName;
            Type     tp;

            lock (methodLookup)
            {
                if (methodLookup.Contains(key))
                {
                    tp = (Type)methodLookup[key];
                }
                else
                {
                    Type[] paramList = new Type[obj.GetType().GetProperty(propertyName).GetSetMethod().GetParameters().Length];
                    int    n         = 0;
                    foreach (ParameterInfo pi in obj.GetType().GetProperty(propertyName).GetSetMethod().GetParameters())
                    {
                        paramList[n++] = pi.ParameterType;
                    }
                    TypeBuilder        typeB = builder.DefineType("Del_" + obj.GetType().Name + "_" + propertyName, TypeAttributes.Class | TypeAttributes.AutoLayout | TypeAttributes.Public | TypeAttributes.Sealed, typeof(MulticastDelegate), PackingSize.Unspecified);
                    ConstructorBuilder conB  = typeB.DefineConstructor(MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName, CallingConventions.Standard, new Type[] { typeof(object), typeof(IntPtr) });
                    conB.SetImplementationFlags(MethodImplAttributes.Runtime);
                    MethodBuilder mb = typeB.DefineMethod("Invoke", MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.HideBySig, obj.GetType().GetProperty(propertyName).GetSetMethod().ReturnType, paramList);
                    mb.SetImplementationFlags(MethodImplAttributes.Runtime);
                    tp = typeB.CreateType();
                    methodLookup.Add(key, tp);
                }
            }

            del = MulticastDelegate.CreateDelegate(tp, obj, obj.GetType().GetProperty(propertyName).GetSetMethod().Name);
            return(obj.Invoke(del, paramValues));
        }
コード例 #2
0
		} // end private void ConvertControls(System.Windows.Forms.Control rootControl, System.Text.StringBuilder stringBuilder)

		/// <summary>
		/// The method assigns values to the _FullName, _RootName and _Namespace 
		/// private variables based on the rootControl' type properties.
		/// </summary>
		/// <param name="rootControl"></param>
		private void CheckNames(System.Windows.Forms.Control rootControl)
		{
			if(this._FullName == null)
			{
				this._FullName = rootControl.GetType().FullName;
			} // end if(this._FullName == null)
			if(this._RootName == null)
			{
				this._RootName = rootControl.GetType().Name;
			} // end if(this._RootName == null)
			if(this._Namespace == null)
			{
				this._Namespace = rootControl.GetType().Namespace;
			} // end if(this._Namespace == null)
		} // end private void CheckNames(System.Windows.Forms.Control rootControl)
コード例 #3
0
        private IEnumerable <System.Reflection.FieldInfo> GetControls(System.Windows.Forms.Control input)
        {
            if (IsContentTextStatic(input))
            {
                Type t = input.GetType();
                System.Reflection.BindingFlags flags = System.Reflection.BindingFlags.GetField;
                flags |= System.Reflection.BindingFlags.Public;
                flags |= System.Reflection.BindingFlags.NonPublic;
                flags |= System.Reflection.BindingFlags.Instance;
                System.Reflection.FieldInfo[] tab = t.GetFields(flags);

                foreach (System.Reflection.FieldInfo fi in tab)
                {
                    System.Diagnostics.Trace.WriteLine("property=" + fi.Name);
                }

                return((from f in tab where (f.FieldType.FullName.StartsWith("System.Windows.Forms") || (f.FieldType.FullName.StartsWith("EasyHTMLDev"))) select f).AsEnumerable());
            }
            else
            {
                return(new List <System.Reflection.FieldInfo>()
                {
                });
            }
        }
コード例 #4
0
        /// <summary>
        /// Method to test if the control or it's parent is in design mode
        /// </summary>
        /// <param name="control">Control to examine</param>
        /// <returns>True if in design mode, otherwise false</returns>
        private static bool ResolveDesignMode(System.Windows.Forms.Control control)
        {
            System.Reflection.PropertyInfo designModeProperty;
            bool designMode;


            // Get the protected property
            designModeProperty = control.GetType().GetProperty(
                "DesignMode",
                System.Reflection.BindingFlags.Instance
                | System.Reflection.BindingFlags.NonPublic);


            // Get the controls DesignMode value
            designMode = (bool)designModeProperty.GetValue(control, null);


            // Test the parent if it exists
            if (control.Parent != null)
            {
                designMode |= ResolveDesignMode(control.Parent);
            }


            return(designMode);
        }
コード例 #5
0
 public SettingsMenagerStructure(System.Windows.Forms.Control control)
 {
     this.type    = control.GetType();
     this.name    = control.Name;
     this.text    = control.Text;
     this.control = control;
 }
コード例 #6
0
        private int GenerateId(System.Windows.Forms.Control control, Atf.Applications.ControlInfo controlInfo, Atf.Applications.IControlHostClient client)
        {
            int clientType  = client.GetType().Name.GetHashCode();
            int controlType = control.GetType().Name.GetHashCode();
            int controlName = controlInfo.Name.GetHashCode();

            return(clientType ^ controlType ^ controlName);
        }
コード例 #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="control"></param>
        /// <param name="enable"></param>
        public static void DoubleBuffered(this System.Windows.Forms.Control control, bool enable)
        {
            var doubleBufferPropertyInfo = control.GetType().GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);

            if (doubleBufferPropertyInfo != null)
            {
                doubleBufferPropertyInfo.SetValue(control, enable, null);
            }
        }
コード例 #8
0
        static PDNBulkUpdaterEffect()
        {
            try
            {
                if (System.Windows.Forms.Application.OpenForms.Count > 0)
                {
                    m_mainWindow = System.Windows.Forms.Application.OpenForms[System.Windows.Forms.Application.OpenForms.Count - 1];

                    while (m_mainWindow.Owner != null)
                    {
                        m_mainWindow = m_mainWindow.Owner;
                    }
                }

                foreach (System.Windows.Forms.Control ctrl in m_mainWindow.Controls)
                {
                    System.Windows.Forms.UserControl workSpace = ctrl as System.Windows.Forms.UserControl;

                    if (workSpace != null)
                    {
                        PropertyInfo info = workSpace.GetType().GetProperty("ToolBar");

                        if (info != null)
                        {
                            System.Windows.Forms.Control toolbar = info.GetGetMethod().Invoke(workSpace, new object[0]) as System.Windows.Forms.Control;

                            if (toolbar != null)
                            {
                                info = toolbar.GetType().GetProperty("MainMenu");

                                if (info != null)
                                {
                                    System.Windows.Forms.MenuStrip menu = info.GetGetMethod().Invoke(toolbar, new object[0]) as System.Windows.Forms.MenuStrip;

                                    if (menu != null)
                                    {
                                        // "Effects" drop down menu
                                        System.Windows.Forms.ToolStripMenuItem fileItem = menu.Items[6] as System.Windows.Forms.ToolStripMenuItem;
                                        //fileItem.DropDownOpening += new EventHandler(fileItem_DropDownOpening);
                                        fileItem_DropDownOpening(fileItem, null);
                                    }
                                }
                            }
                        }

                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                m_loaderException = ex;
                System.Diagnostics.Debug.WriteLine(ex.ToString());
            }
        }
コード例 #9
0
        private bool IsControlTypeMatched(System.Windows.Forms.Control control, bool allowDerived)
        {
            Type argControlType = control.GetType();

            if (argControlType.Equals(this.ControlType))
            {
                return(true);
            }

            return(allowDerived && argControlType.IsSubclassOf(this.ControlType));
        }
コード例 #10
0
        public static WindowsFormsHost FindWpfHost(this System.Windows.Forms.Control control)
        {
            while (control.Parent != null)
            {
                control = control.Parent;
            }

            const string typeName = "System.Windows.Forms.Integration.WinFormsAdapter";

            if (control.GetType().FullName != typeName)
            {
                return(null);
            }

            var adapterAssembly     = control.GetType().Assembly;
            var winFormsAdapterType = adapterAssembly.GetType(typeName);

            return((WindowsFormsHost)winFormsAdapterType.InvokeMember("_host",
                                                                      BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance, null, control, new object[0], null));
        }
コード例 #11
0
        //public new int Count
        //{
        //	get { return base.Count; }
        //}
        //
        //public new bool IsReadOnly
        //{
        //	get { return base.IsReadOnly; }
        //}
        #endregion

        #region New/Override and Novel Methods/Functions
        // public override void Add(System.Windows.Forms.Control control)
        // public override void AddRange(System.Windows.Forms.Control[] controls)
        //     public new void AddRange(params System.Windows.Forms.Control[] controls)
        //
        /// <summary>
        /// Adds the specified control.
        /// </summary>
        /// <param name="control">The control.</param>
        public override void Add(System.Windows.Forms.Control control)
        {
//			if( (control.GetType() == typeof(ZeroitAyensuTab.ZeroitAyensuTabPage))
//			|| control.GetType().IsSubclassOf(typeof(ZeroitAyensuTab.ZeroitAyensuTabPage))
//			)
//			{
//				_owner.TabPages.Add((ZeroitAyensuTab.ZeroitAyensuTabPage)control);
//			}
//			else
//			{
//				base.Add(control);
//			}

            if ((control.GetType() == typeof(System.Windows.Forms.TabPage)) ||                                                                  // 1.0.020
                control.GetType().IsSubclassOf(typeof(System.Windows.Forms.TabPage))                                                            // 1.0.020
                )                                                                                                                               // 1.0.020
            {                                                                                                                                   // 1.0.020
                _owner.TabPages.Add((System.Windows.Forms.TabPage)control);                                                                     // 1.0.020
            }                                                                                                                                   // 1.0.020
        }
コード例 #12
0
 public static void SetControlPropertyThreadSafe(System.Windows.Forms.Control control, string propertyName, object propertyValue)
 {
     if (control.InvokeRequired)
     {
         control.Invoke(new SetControlPropertyThreadSafeDelegate(SetControlPropertyThreadSafe), new object[] { control, propertyName, propertyValue });
     }
     else
     {
         control.GetType().InvokeMember(propertyName, System.Reflection.BindingFlags.SetProperty, null, control, new object[] { propertyValue });
     }
 }
コード例 #13
0
        /* ----------------------------------------------------------------- */
        ///
        /// Detach
        ///
        /// <summary>
        /// 指定されたコントロール以下の全てのコントロールから関連付けた
        /// イベントを解除します。
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        private void Detach(Control control)
        {
            MonitoredControlList.Remove(control);

            control.ControlAdded   -= Control_ControlAdded;
            control.ControlRemoved -= Control_ControlRemoved;

            switch (control.GetType().Name)
            {
            case nameof(Cube.Forms.ColorButton):
                var color = control as Cube.Forms.ColorButton;
                color.BackColorChanged -= ColorButtonChanged;
                if (CustomColors == color.CustomColors)
                {
                    color.CustomColors = null;
                }
                break;

            case nameof(Cube.Forms.FontButton):
                var font = control as Cube.Forms.FontButton;
                font.FontChanged -= FontButtonChanged;
                break;

            case nameof(System.Windows.Forms.CheckBox):
                var check = control as System.Windows.Forms.CheckBox;
                check.CheckedChanged -= CheckBoxChanged;
                break;

            case nameof(System.Windows.Forms.ComboBox):
                var combo = control as System.Windows.Forms.ComboBox;
                combo.SelectedIndexChanged -= ComboBoxChanged;
                break;

            case nameof(System.Windows.Forms.NumericUpDown):
                var num = control as System.Windows.Forms.NumericUpDown;
                num.ValueChanged -= NumericUpDownChanged;
                break;

            case nameof(System.Windows.Forms.RadioButton):
                var radio = control as System.Windows.Forms.RadioButton;
                radio.CheckedChanged -= RadioButtonChanged;
                break;

            case nameof(System.Windows.Forms.TextBox):
                var text = control as System.Windows.Forms.TextBox;
                text.TextChanged -= TextBoxChanged;
                break;

            default:
                break;
            }
        }
コード例 #14
0
        /* ----------------------------------------------------------------- */
        ///
        /// RaisePropertyChanged
        ///
        /// <summary>
        /// PropertyChanged イベントを発生させます。
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        protected void RaisePropertyChanged(Control control, object value)
        {
            var name = control.Name.Replace(control.GetType().Name, string.Empty);

            if (string.IsNullOrEmpty(name))
            {
                return;
            }

            OnPropertyChanged(new KeyValueEventArgs <string, object>(name, value));
            if (ApplyButton != null)
            {
                ApplyButton.Enabled = true;
            }
        }
コード例 #15
0
        /// <summary>
        /// load the specified control
        /// </summary>
        /// <param name="control"></param>
        public void LoadControlGoingback(System.Windows.Forms.Control control)
        {
            // verwijder het huidige item uit de navigatie
            ApplicationState.GetValue <List <object> >(ApplicationVariables.listNavigationHistory).RemoveAt(0);

            // load the control
            wfhTest.Child           = control;
            ccPageContainer.Content = null;

            // laad het menu
            if (control.GetType().BaseType == typeof(WFControl))
            {
                LoadMenu(((WFControl)control));
            }
        }
コード例 #16
0
    private void RestoreEventList()
    {
        object o = eventsFieldInfo.GetValue(target);

        if (o != null && headFieldInfo.GetValue(o) != null)
        {
            throw new Exception($"Events on {target.GetType().Name} (local name: {target.Name}) added while event handling suspended.");
        }
        else
        {
            eventsFieldInfo.SetValue(target, eventHandlerList);
            eventHandlerList = null;
            target           = null;
        }
    }
コード例 #17
0
        void ITranslator.Translate(System.Windows.Forms.Control control, string sourceCultureName, string targetCultureName)
        {
            if (control is System.Windows.Forms.ListControl)
            {
                return;
            }

            if (control is System.Windows.Forms.TextBoxBase)
            {
                return;
            }

            if (control is System.Windows.Forms.WebBrowserBase)
            {
                return;
            }

            if (control is System.Windows.Forms.WebBrowserBase)
            {
                return;
            }

            if (this.SkipControlFullNames.Contains(control.GetType().FullName))
            {
                return;
            }

            if (!this.controls.ContainsKey(control))
            {
                this.controls.Add(control, control.Text);
            }

            if (control.Controls != null && control.Controls.Count > 0)
            {
                ((ITranslator)this).Translate(control.Controls, sourceCultureName, targetCultureName);
            }

            //Text 속석을 사용 할 수 없는 컨트롤도 있음
            try
            {
                control.Text = ((ITranslator)this).Translate(this.controls[control], sourceCultureName, targetCultureName);
            }
            catch (Exception exception)
            {
                DiagnosticsTool.MyTrace(exception);
            }
        }
コード例 #18
0
        private static string GetNomForRegistre(System.Windows.Forms.Control liste, string strName)
        {
            string strPath = "Preferences\\Panel_Listes\\";

            if (liste.FindForm() != null)
            {
                strPath += liste.FindForm().GetType().Name + "_";
            }
            else
            {
                System.Windows.Forms.Control ctrl = liste;
                while (ctrl.Parent != null)
                {
                    ctrl = ctrl.Parent;
                }
                strPath += ctrl.GetType().Name + "_";
            }
            strPath += strName;
            return(strPath);
        }
コード例 #19
0
ファイル: UCTheme.cs プロジェクト: suyana/NetWinformControl
 /// <summary>
 /// 刷新样式
 /// </summary>
 private void ThemeRefresh()
 {
     //循环所有页面已经存在的控件
     foreach (var item in this.Container.Components)
     {
         try
         {
             System.Windows.Forms.Control con = (System.Windows.Forms.Control)item;
             Assembly assembly = Assembly.GetExecutingAssembly();
             Object   obj      = assembly.CreateInstance(con.GetType().FullName);
             //判断控件基类是否来自UCControlBase
             if (typeof(UCControlBase).IsAssignableFrom(obj.GetType()))
             {
                 //根据对应的主题找到实现类
                 IControlTheme uct = (IControlTheme)assembly.CreateInstance("HZH_Controls.Theme." + this._ThemeType);
                 uct.ControlTheme(con);
             }
         }
         catch { }
     }
 }
コード例 #20
0
 /// <summary>
 /// Ecrit le texte associé à la propriété 'Text" du control vers la/les sorties configurées.
 /// </summary>
 /// <param name="control"></param>
 public static void Write(System.Windows.Forms.Control control)
 {
     try
     {
         Type ctrlType = control.GetType();
         if (ctrlType == typeof(System.Windows.Forms.TextBox) || ctrlType == typeof(System.Windows.Forms.Label))
         {
             Write(control.Name + " has for Text value : " + control.Text);
         }
         if (ctrlType == typeof(System.Windows.Forms.CheckBox))
         {
             Write((control as System.Windows.Forms.CheckBox).Name + "is " + (control as System.Windows.Forms.CheckBox).Checked);
         }
         if (ctrlType == typeof(System.Windows.Forms.ComboBox))
         {
             Write((control as System.Windows.Forms.ComboBox).Name + " has index " + (control as System.Windows.Forms.ComboBox).SelectedIndex.ToString() + " Selected." + (((control as System.Windows.Forms.ComboBox).SelectedIndex != -1)?(control as System.Windows.Forms.ComboBox).SelectedItem.ToString():""));
         }
     }
     catch (Exception)
     { }
 }
コード例 #21
0
        /// <summary>
        /// Get if the control should be translated.
        /// </summary>
        /// <param name="control">Control to check name and type from</param>
        /// <returns>True if control text should be translated</returns>
        private static bool IsTranslatableControl(System.Windows.Forms.Control control)
        {
            bool translatecontrol = false;
            Type controltype      = control.GetType();

            // whitelist control type
            if (controltype == typeof(System.Windows.Forms.Label) ||
                controltype == typeof(System.Windows.Forms.ToolStripMenuItem) ||
                controltype == typeof(System.Windows.Forms.Button) ||
                controltype == typeof(System.Windows.Forms.CheckBox) ||
                controltype == typeof(System.Windows.Forms.TabPage) ||
                controltype == typeof(System.Windows.Forms.ToolTip) ||
                controltype == typeof(System.Windows.Forms.LinkLabel) ||
                controltype == typeof(System.Windows.Forms.TabControl) ||
                controltype == typeof(System.Windows.Forms.TableLayoutPanel) ||
                controltype == typeof(System.Windows.Forms.Panel) ||
                controltype == typeof(SearchTextBox))
            {
                // blacklist control name
                if (control.Name != "btnKeywordClear" &&
                    control.Name != "btnClose" &&
                    control.Name != "btnTextBold" &&
                    control.Name != "btnTextItalic" &&
                    control.Name != "btnTextUnderline" &&
                    control.Name != "btnTextStriketrough" &&
                    control.Name != "btnTextBulletlist" &&
                    control.Name != "btnFontBigger" &&
                    control.Name != "btnFontSmaller" &&
                    control.Name != "btnHideNote" &&
                    control.Name != "lblNoteTitle" &&
                    control.Name != "lblProductName" &&
                    control.Name != "lblProductVersion")
                {
                    translatecontrol = true;
                }
            }

            return(translatecontrol);
        }
コード例 #22
0
        private bool findDevXManager(System.Windows.Forms.Control FormOrUserControl)
        {
            bool   found     = false;
            object tucMgrObj = null;

            //searches for the TUC_HMDevXManager and sets its value
            foreach (FieldInfo myFieldInfo in
                     FormOrUserControl.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
            {
                if (myFieldInfo.FieldType.ToString() == "TUC_HMDevXManager.TUC_HMDevXManager")
                {                //finds and sets the TUC manager
                    tucMgrObj = myFieldInfo.GetValue(FormOrUserControl);
                    break;
                }
            }

            if (tucMgrObj != null)
            {
                this.dxmgr = (TUC_HMDevXManager.TUC_HMDevXManager)tucMgrObj;
                found      = true;
            }

            return(found);
        }
コード例 #23
0
        /// <summary>
        /// Extension method to invoke a generic Delegate for a known Event Name, on any Control.
        /// This is because Fees read data out of Textboxes on the Textbox OnLeave() event, so
        /// we needed a way to simuluate the user "leaving" the Textbox.
        ///
        /// Note: I kinda stole this from work... Meh, whatever. I am the person who researched and made this workaround anyways,
        /// and it's generic enough as to be a more universally applicable pattern for workarounds with GUI stuff.
        /// </summary>
        /// <param name="controlToInvoke"></param>
        /// <param name="eventName"></param>
        public static void InvokeGenericDelegateForControlEventName(this System.Windows.Forms.Control controlToInvoke, string eventName)
        {
            MethodInfo methodInfo = controlToInvoke.GetType().GetMethod(string.Format("On{0}", eventName), BindingFlags.NonPublic | BindingFlags.Instance);

            methodInfo?.Invoke(controlToInvoke, new object[] { EventArgs.Empty });
        }
コード例 #24
0
ファイル: XmlManager.cs プロジェクト: Albedaia/Grimoire
        void localizeControls(System.Windows.Forms.Control.ControlCollection controls)
        {
            foreach (System.Windows.Forms.Control control in controls)
            {
                ControlConfig config = null;

                // If the control is a MenuStrip we have to loop through its base controls (toolstripmenuitem)
                // then if applicable we must loop through its children
                if (control.GetType() == typeof(System.Windows.Forms.MenuStrip))
                {
                    System.Windows.Forms.MenuStrip ms = (System.Windows.Forms.MenuStrip)control;

                    foreach (System.Windows.Forms.ToolStripMenuItem tsmi in ms.Items)
                    {
                        config = locale.Controls.Find(c => c.Name == tsmi.Name);

                        if (config != null)
                        {
                            tsmi.Text        = config.Text.Text;
                            tsmi.TextAlign   = config.Text.Alignment;
                            tsmi.RightToLeft = config.Text.RightToLeft;

                            if (!control.Size.IsEmpty)
                            {
                                tsmi.Size = config.Size;
                            }
                        }

                        if (tsmi.HasDropDownItems)
                        {
                            foreach (System.Windows.Forms.ToolStripMenuItem subTSMI in tsmi.DropDownItems)
                            {
                                config = locale.Controls.Find(c => c.Name == subTSMI.Name);

                                if (config != null)
                                {
                                    subTSMI.Text        = config.Text.Text;
                                    subTSMI.TextAlign   = config.Text.Alignment;
                                    subTSMI.RightToLeft = config.Text.RightToLeft;

                                    if (!control.Size.IsEmpty)
                                    {
                                        subTSMI.Size = config.Size;
                                    }
                                }
                            }
                        }
                    }
                }
                else if (control.GetType() == typeof(System.Windows.Forms.GroupBox))
                {
                    // Define the base group_box and set his text
                    System.Windows.Forms.GroupBox grpBx = (System.Windows.Forms.GroupBox)control;

                    config = locale.Controls.Find(c => c.Name == grpBx.Name);
                    if (config != null)
                    {
                        grpBx.Text = config.Text.Text;
                    }

                    // Define each child control inside of the group box
                    // set their attributes accordingly
                    for (int i = 0; i < grpBx.Controls.Count; i++)
                    {
                        System.Windows.Forms.Control ctrl = grpBx.Controls[i];

                        if (ctrl.GetType() == typeof(System.Windows.Forms.Button))
                        {
                            System.Windows.Forms.Button btn = (System.Windows.Forms.Button)ctrl;

                            config = locale.Controls.Find(c => c.Name == btn.Name);

                            if (config != null)
                            {
                                btn.TextAlign = config.Text.Alignment;
                            }
                        }
                        else if (ctrl.GetType() == typeof(System.Windows.Forms.RadioButton))
                        {
                            System.Windows.Forms.RadioButton rBtn = (System.Windows.Forms.RadioButton)ctrl;

                            config = locale.Controls.Find(c => c.Name == rBtn.Name);

                            if (config != null)
                            {
                                rBtn.TextAlign = config.Text.Alignment;
                            }
                        }
                        else if (ctrl.GetType() == typeof(System.Windows.Forms.Label))
                        {
                            System.Windows.Forms.Label lbl = (System.Windows.Forms.Label)ctrl;

                            config = locale.Controls.Find(c => c.Name == lbl.Name);

                            if (config != null)
                            {
                                lbl.TextAlign = config.Text.Alignment;
                            }
                        }
                        else if (ctrl.GetType() == typeof(System.Windows.Forms.CheckBox))
                        {
                            System.Windows.Forms.CheckBox chkBx = (System.Windows.Forms.CheckBox)ctrl;

                            config = locale.Controls.Find(c => c.Name == chkBx.Name);

                            if (config != null)
                            {
                                chkBx.TextAlign = config.Text.Alignment;
                            }
                        }
                        else if (ctrl.GetType() == typeof(System.Windows.Forms.TextBox)) /*Textbox shouldn't be touched*/ } {
                        if (config != null)
                        {
                            ctrl.Font        = new System.Drawing.Font(config.Font.Name, (float)config.Font.Size, config.Font.Style);
                            ctrl.RightToLeft = config.Text.RightToLeft;

                            if (!config.Location.IsEmpty)
                            {
                                ctrl.Location = config.Location;
                            }

                            if (!config.Size.IsEmpty)
                            {
                                ctrl.Size = config.Size;
                            }

                            ctrl.Text = config.Text.Text;
                        }

                        config = null;
                }
            }
            else if (control.GetType() == typeof(System.Windows.Forms.ToolStrip))
            {
                foreach (object tso in ((System.Windows.Forms.ToolStrip)control).Items)
                {
                    if (tso.GetType() == typeof(System.Windows.Forms.ToolStripDropDownButton))
                    {
                        System.Windows.Forms.ToolStripDropDownButton tsb = (System.Windows.Forms.ToolStripDropDownButton)tso;

                        config = locale.Controls.Find(c => c.Name == tsb.Name);

                        if (config != null)
                        {
                            tsb.Text        = config.Text.Text;
                            tsb.TextAlign   = config.Text.Alignment;
                            tsb.Font        = new System.Drawing.Font(config.Font.Name, (float)config.Font.Size, config.Font.Style);
                            tsb.RightToLeft = config.Text.RightToLeft;
                        }
                    }
                    else if (tso.GetType() == typeof(System.Windows.Forms.ToolStripButton))
                    {
                        System.Windows.Forms.ToolStripButton tsb = (System.Windows.Forms.ToolStripButton)tso;

                        config = locale.Controls.Find(c => c.Name == tsb.Name);

                        if (config != null)
                        {
                            tsb.Text        = config.Text.Text;
                            tsb.TextAlign   = config.Text.Alignment;
                            tsb.Font        = new System.Drawing.Font(config.Font.Name, (float)config.Font.Size, config.Font.Style);
                            tsb.RightToLeft = config.Text.RightToLeft;
                        }
                    }
                    else if (tso.GetType() == typeof(System.Windows.Forms.ToolStripMenuItem))
                    {
                        System.Windows.Forms.ToolStripMenuItem tsi = (System.Windows.Forms.ToolStripMenuItem)tso;

                        config = locale.Controls.Find(c => c.Name == tsi.Name);

                        if (config != null)
                        {
                            tsi.Text        = config.Text.Text;
                            tsi.TextAlign   = config.Text.Alignment;
                            tsi.Font        = new System.Drawing.Font(config.Font.Name, (float)config.Font.Size, config.Font.Style);
                            tsi.RightToLeft = config.Text.RightToLeft;
                        }
                    }
                    else if (tso.GetType() == typeof(System.Windows.Forms.ToolStripLabel))
                    {
                        System.Windows.Forms.ToolStripLabel tsl = (System.Windows.Forms.ToolStripLabel)tso;

                        config = locale.Controls.Find(c => c.Name == tsl.Name);

                        if (config != null)
                        {
                            tsl.Text        = config.Text.Text;
                            tsl.TextAlign   = config.Text.Alignment;
                            tsl.Font        = new System.Drawing.Font(config.Font.Name, (float)config.Font.Size, config.Font.Style);
                            tsl.RightToLeft = config.Text.RightToLeft;
                        }
                    }

                    if (config != null)
                    {
                        if (!config.Location.IsEmpty)
                        {
                            control.Location = config.Location;
                        }

                        if (!config.Size.IsEmpty)
                        {
                            control.Size = config.Size;
                        }

                        control.Text = config.Text.Text;
                    }

                    config = null;
                }
            }
            else
            {
                config = locale.Controls.Find(c => c.Name == control.Name);

                if (config != null)
                {
                    System.Drawing.Font font = new System.Drawing.Font(config.Font.Name, (float)config.Font.Size, config.Font.Style);

                    control.Font = font;

                    Type t = control.GetType();
                    if (t == typeof(System.Windows.Forms.CheckBox))
                    {
                        System.Windows.Forms.CheckBox chkBx = (System.Windows.Forms.CheckBox)control;
                        chkBx.TextAlign = config.Text.Alignment;
                    }
                    else if (t == typeof(System.Windows.Forms.Label))
                    {
                        System.Windows.Forms.Label lbl = (System.Windows.Forms.Label)control;
                        lbl.TextAlign = config.Text.Alignment;
                    }
                    else if (t == typeof(System.Windows.Forms.Button))
                    {
                        System.Windows.Forms.Button lbl = (System.Windows.Forms.Button)control;
                        lbl.TextAlign = config.Text.Alignment;
                    }
                    else if (t == typeof(System.Windows.Forms.ToolStripMenuItem))
                    {
                        System.Windows.Forms.ToolStrip     tsm = (System.Windows.Forms.ToolStrip)control;
                        System.Windows.Forms.ToolStripItem tsi = tsm.Items[config.Name];

                        tsi.TextAlign = config.Text.Alignment;
                    }
                    else if (t == typeof(System.Windows.Forms.ToolStripDropDownButton))
                    {
                        System.Windows.Forms.ToolStrip     tsm = (System.Windows.Forms.ToolStrip)control;
                        System.Windows.Forms.ToolStripItem tsi = tsm.Items[config.Name];

                        tsi.TextAlign = config.Text.Alignment;
                    }
                    else
                    {
                        /*Alignment doesn't exist bruh*/
                    }

                    if (!config.Location.IsEmpty)
                    {
                        control.Location = config.Location;
                    }

                    if (!config.Size.IsEmpty)
                    {
                        control.Size = config.Size;
                    }

                    control.Text = config.Text.Text;
                }
                else
                {
                    lManager.Enter(Sender.MANAGER, Level.DEBUG, "Control: {0} is not configured! It will default.", control.Name);
                }
            }
        }
    }
コード例 #25
0
 public ToolStripPanelCell(System.Windows.Forms.ToolStripPanelRow parent, System.Windows.Forms.Control control)
 {
     this.maxSize           = LayoutUtils.MaxSize;
     this.cachedBounds      = Rectangle.Empty;
     this.ToolStripPanelRow = parent;
     this._wrappedToolStrip = control as ToolStrip;
     if (control == null)
     {
         throw new ArgumentNullException("control");
     }
     if (this._wrappedToolStrip == null)
     {
         throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, System.Windows.Forms.SR.GetString("TypedControlCollectionShouldBeOfType", new object[] { typeof(ToolStrip).Name }), new object[0]), control.GetType().Name);
     }
     CommonProperties.SetAutoSize(this, true);
     this._wrappedToolStrip.LocationChanging += new ToolStripLocationCancelEventHandler(this.OnToolStripLocationChanging);
     this._wrappedToolStrip.VisibleChanged   += new EventHandler(this.OnToolStripVisibleChanged);
 }
コード例 #26
0
 /// <summary>
 /// コントロールの DoubleBuffered を設定します。
 /// </summary>
 /// <param name="control">対象となるコントロール。</param>
 /// <param name="flag">設定するフラグ。既定では true です。</param>
 public static void SetDoubleBuffered(System.Windows.Forms.Control control, bool flag = true)
 {
     System.Reflection.PropertyInfo prop = control.GetType().GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
     prop.SetValue(control, flag, null);
 }
コード例 #27
0
        public bool SaveControl(System.Windows.Forms.Form parentForm)
        {
            try {
                System.Windows.Forms.Control controlToSet = null;
                controlToSet = UtilityStatic.FindControlOnForm(parentForm, mControlName);
                if (controlToSet == null)
                {
                    return(false);
                }
                switch (controlToSet.GetType().Name)
                {
                case "Label":
                    System.Windows.Forms.Label label = (System.Windows.Forms.Label)controlToSet;
                    mValueCurrent = label.Text;
                    break;

                case "TextBox":
                    System.Windows.Forms.TextBox textBox = (System.Windows.Forms.TextBox)controlToSet;
                    mValueCurrent = textBox.Text;
                    break;

                case "ComboBox":
                    System.Windows.Forms.ComboBox comboBox = (System.Windows.Forms.ComboBox)controlToSet;
                    mValueCurrent = comboBox.Text;
                    break;

                case "ListBox":
                    System.Windows.Forms.ListBox listBox = (System.Windows.Forms.ListBox)controlToSet;
                    mValueCurrent = listBox.Text;
                    break;

                case "CheckBox":
                    System.Windows.Forms.CheckBox checkBox = (System.Windows.Forms.CheckBox)controlToSet;
                    if (checkBox.Checked)
                    {
                        mValueCurrent = "true";
                    }
                    else
                    {
                        mValueCurrent = "false";
                    }
                    break;

                case "RadioButton":
                    System.Windows.Forms.RadioButton radioButton = (System.Windows.Forms.RadioButton)controlToSet;
                    if (radioButton.Checked)
                    {
                        mValueCurrent = "true";
                    }
                    else
                    {
                        mValueCurrent = "false";
                    }
                    break;

                case "GroupBox":
                    System.Windows.Forms.GroupBox    groupBox = (System.Windows.Forms.GroupBox)controlToSet;
                    System.Windows.Forms.RadioButton radioButtonInGroup;
                    foreach (System.Windows.Forms.Control controlTest in groupBox.Controls)
                    {
                        if (controlTest.GetType() == typeof(System.Windows.Forms.RadioButton))
                        {
                            radioButtonInGroup = (System.Windows.Forms.RadioButton)controlTest;
                            if (radioButtonInGroup.Checked)
                            {
                                mValueCurrent = radioButtonInGroup.Name;
                                break;
                            }
                        }
                    }
                    break;

                default:
                    System.Windows.Forms.MessageBox.Show(
                        "Unknown case in switch statement in ControlSetting.SaveControl.");
                    return(false);
                }
            }
            catch (Exception exception) {
                System.Windows.Forms.MessageBox.Show(exception.Message);
                return(false);
            }
            return(true);
        }
コード例 #28
0
        // ************************************************ Public Functions ******************************************

        public bool SetControl(System.Windows.Forms.Form parentForm)
        {
            try {
                System.Windows.Forms.Control controlToSet = UtilityStatic.FindControlOnForm(parentForm, mControlName);
                if (controlToSet == null)
                {
                    System.Windows.Forms.MessageBox.Show(
                        "Unable to find control named: '" + mControlName + "' in ControlSetting.SetControl.");
                    return(false);
                }
                switch (controlToSet.GetType().Name)
                {
                case "Label":
                    System.Windows.Forms.Label label = (System.Windows.Forms.Label)controlToSet;
                    label.Text = mValueCurrent;
                    break;

                case "TextBox":
                    System.Windows.Forms.TextBox textBox = (System.Windows.Forms.TextBox)controlToSet;
                    textBox.Text = mValueCurrent;
                    break;

                case "ComboBox":
                    System.Windows.Forms.ComboBox comboBox = (System.Windows.Forms.ComboBox)controlToSet;
                    comboBox.Text = mValueCurrent;
                    break;

                case "ListBox":
                    System.Windows.Forms.ListBox listBox = (System.Windows.Forms.ListBox)controlToSet;
                    if (listBox.Items.Contains(mValueCurrent))
                    {
                        listBox.Text = mValueCurrent;
                    }
                    break;

                case "CheckBox":
                    System.Windows.Forms.CheckBox checkBox = (System.Windows.Forms.CheckBox)controlToSet;
                    if (mValueCurrent == "true")
                    {
                        checkBox.Checked = true;
                    }
                    else
                    {
                        checkBox.Checked = false;
                    }
                    break;

                case "RadioButton":
                    System.Windows.Forms.RadioButton radioButton = (System.Windows.Forms.RadioButton)controlToSet;
                    if (mValueCurrent == "true")
                    {
                        radioButton.Checked = true;
                    }
                    else
                    {
                        radioButton.Checked = false;
                    }
                    break;

                case "GroupBox":
                    System.Windows.Forms.GroupBox    groupBox = (System.Windows.Forms.GroupBox)controlToSet;
                    System.Windows.Forms.RadioButton radioButtonInGroup;
                    foreach (System.Windows.Forms.Control controlTest in groupBox.Controls)
                    {
                        if (controlTest.GetType() == typeof(System.Windows.Forms.RadioButton))
                        {
                            radioButtonInGroup = (System.Windows.Forms.RadioButton)controlTest;
                            if (radioButtonInGroup.Name == mValueCurrent)
                            {
                                radioButtonInGroup.Checked = true;
                                break;
                            }
                        }
                    }
                    break;

                default:
                    System.Windows.Forms.MessageBox.Show(
                        "Unknown case in switch statement in ControlSetting.SetControl");
                    return(true);
                }
                return(true);
            }
            catch (Exception exception) {
                System.Windows.Forms.MessageBox.Show(exception.Message);
                return(false);
            }
        }