资源简介

本例中,为WinForm提供方法,批量设置其界面上所有的控件为不可编辑状态 方法: SetReadOnly( Control.ControlCollection , List<KeyValuePair> , List) 说明: 当窗体内的控件存在[ReadOnly]属性时,只设置[ReadOnly]属性,否则设置[Enabled]属性 方法中,List参数提供时,代表不修改其可编辑性,保持其状态为原始的可编辑或不可编辑 List<KeyValuePair>参数,布尔值表示是否同时忽略修改其子控件,如放在GroupBox内的按钮 List参数,该列表内的类型的控件均不修改其可编辑属性,如Label控件一般不设置可编辑性。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;

namespace SetReadOnly
{
    /// 
    /// 
    /// **************************************************
    ///                 本例由[Hekainy]编写
    ///                    仅供初学者参考
    ///          ---- 版权所有 禁止作商业用途----
    ///       
    ///                     QQ:277902872
    ///                     Email:hekainy@163.com
    ///                     有任何疑问请联系我.
    /// **************************************************
    /// 
    /// 本例中,为WinForm提供方法,设置其控件为不可编辑
    /// 
    /// 说明:
    ///     当窗体内的控件存在[ReadOnly]属性时,只设置[ReadOnly]属性,否则设置[Enabled]属性
    ///     方法中,List参数提供时,代表不修改其可编辑性,保持其状态为原始的可编辑或不可编辑
    ///     List>参数,布尔值表示是否同时忽略修改其子控件,如放在GroupBox内的按钮
    ///     List参数,该列表内的类型的控件均不修改其可编辑属性,如Label控件一般不设置可编辑性
    /// 
    /// 

    public class Commonhelper
    {
        private static List _baseExcludeTypes = new List
                                                            new Type[] 
                                                            {
                                                                typeof(Label)
                                                                typeof(GroupBox)
                                                                typeof(Panel)
                                                            });

        /// 
        /// 设置窗体的控件为只读或不可编辑
        /// 

        /// 
        public static void SetReadOnly(Form form)
        {
            if (form != null)
                SetReadOnly(form.Controls null null);
        }

        /// 
        /// 设置窗体的控件为只读或不可编辑
        /// 

        /// 需要设置控件为只读的窗体
        /// 排除指定的控件键值设置为True将同时排除其子控件
        public static void SetReadOnly(Form form List> excludeControls)
        {
            if (form != null)
                SetReadOnly(form.Controls excludeControls null);
        }

        /// 
        /// 设置窗体的控件为只读或不可编辑
        /// 

        /// 需要设置控件为只读的窗体
        /// 排除指定类型的控件如: Label
        public static void SetReadOnly(Form form List excludeTypes)
        {
            if (form != null)
                SetReadOnly(form.Controls null excludeTypes);
        }

        /// 
        /// 设置窗体的控件为只读或不可编辑
        /// 

        /// 需要设置控件为只读的窗体
        /// 排除指定的控件键值设置为True将同时排除其子控件
        /// 排除指定类型的控件如: Label
        public static void SetReadOnly(Form form List> excludeContro

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      26624  2011-05-23 15:10  SetReadOnly\SetReadOnly\bin\Debug\SetReadOnly.exe

     文件      38400  2011-05-23 15:10  SetReadOnly\SetReadOnly\bin\Debug\SetReadOnly.pdb

     文件      14328  2011-05-23 15:10  SetReadOnly\SetReadOnly\bin\Debug\SetReadOnly.vshost.exe

     文件        490  2007-07-21 02:33  SetReadOnly\SetReadOnly\bin\Debug\SetReadOnly.vshost.exe.manifest

     文件       8710  2011-05-23 14:55  SetReadOnly\SetReadOnly\Commonhelpers.cs

     文件       1078  2011-05-23 13:02  SetReadOnly\SetReadOnly\Icon1.ico

     文件        500  2011-05-23 15:06  SetReadOnly\SetReadOnly\MainForm.cs

     文件       3146  2011-05-23 15:06  SetReadOnly\SetReadOnly\MainForm.Designer.cs

     文件       7076  2011-05-23 15:06  SetReadOnly\SetReadOnly\MainForm.resx

     文件        953  2011-05-23 15:10  SetReadOnly\SetReadOnly\obj\Debug\SetReadOnly.csproj.FileListAbsolute.txt

     文件        950  2011-05-23 15:10  SetReadOnly\SetReadOnly\obj\Debug\SetReadOnly.csproj.GenerateResource.Cache

     文件      26624  2011-05-23 15:10  SetReadOnly\SetReadOnly\obj\Debug\SetReadOnly.exe

     文件       1362  2011-05-23 15:10  SetReadOnly\SetReadOnly\obj\Debug\SetReadOnly.MainForm.resources

     文件      38400  2011-05-23 15:10  SetReadOnly\SetReadOnly\obj\Debug\SetReadOnly.pdb

     文件       1804  2011-05-23 15:10  SetReadOnly\SetReadOnly\obj\Debug\SetReadOnly.Properties.Resources.resources

     文件       1168  2011-05-23 15:10  SetReadOnly\SetReadOnly\obj\Debug\SetReadOnly.TestForm.resources

     文件       4608  2011-05-23 13:09  SetReadOnly\SetReadOnly\obj\Debug\TempPE\Properties.Resources.Designer.cs.dll

     文件        495  2011-05-23 14:53  SetReadOnly\SetReadOnly\Program.cs

     文件       1362  2011-05-23 12:54  SetReadOnly\SetReadOnly\Properties\AssemblyInfo.cs

     文件       3095  2011-05-23 13:09  SetReadOnly\SetReadOnly\Properties\Resources.Designer.cs

     文件       6197  2011-05-23 13:09  SetReadOnly\SetReadOnly\Properties\Resources.resx

     文件       1096  2011-05-23 12:54  SetReadOnly\SetReadOnly\Properties\Settings.Designer.cs

     文件        249  2011-05-23 12:53  SetReadOnly\SetReadOnly\Properties\Settings.settings

     文件       1334  2011-05-23 13:09  SetReadOnly\SetReadOnly\Resources\Start.bmp

     文件       4260  2011-05-23 13:10  SetReadOnly\SetReadOnly\SetReadOnly.csproj

     文件       1859  2011-05-23 15:10  SetReadOnly\SetReadOnly\TestForm.cs

     文件      28864  2011-05-23 15:10  SetReadOnly\SetReadOnly\TestForm.Designer.cs

     文件       7309  2011-05-23 15:10  SetReadOnly\SetReadOnly\TestForm.resx

     文件        923  2011-05-23 12:54  SetReadOnly\SetReadOnly.sln

    ..A..H.     18432  2011-05-23 15:10  SetReadOnly\SetReadOnly.suo

............此处省略13个文件信息

评论

共有 条评论