程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> C#之PropertyGrid使用實例介紹

C#之PropertyGrid使用實例介紹

編輯:C#入門知識

view plaincopy to clipboardprint?
using System.Drawing;  
using System.Text;  
using System.Windows.Forms;  
using System.IO;  
using System.Windows.Forms.Design;  
using System.Drawing.Design;  
namespace Quick.Dialog  
{  
    public partial class OptionsDlg : Form  
    {  
        OptionsInfo m_optInfo = new OptionsInfo();  
        public OptionsDlg()  
        {  
            InitializeComponent();  
            InitOptInfo();  
        }  
        private void InitOptInfo()  
        {  
            LogicCommon comon = new LogicCommon();  
            m_optInfo.ReportPath = comon.GetQualityKeys("ReportPath");  
            m_optInfo.ClientLocat = comon.GetQualityKeys("ClientLocat");  
            m_optInfo.InitDataList();  
        }  
        private void OptionsDlg_Load(object sender, EventArgs e)  
        {  
            propertyGrid_optProp.SelectedObject = m_optInfo;  
        }  
        private void propertyGrid_optProp_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)  
        {  
            string strKey = e.ChangedItem.Label;  
            object objValue = e.ChangedItem.Value;  
            m_optInfo.m_optDataList[strKey] = objValue.ToString();  
        }  
        private void button_ok_Click(object sender, EventArgs e)  
        {  
            string strReportPath = m_optInfo.m_optDataList["ReportPath"];  
            LogicCommon common = new LogicCommon();  
            if (strReportPath == "")  
            {  
                MessageBox.Show("報告文件路徑不能為空!", "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);  
                return;  
            }  
            try
            {  
                Directory.CreateDirectory(strReportPath);  
                common.SetQualityKeys("ReportPath", strReportPath);  
            }  
            catch (System.Exception err)  
            {  
                MessageBox.Show(err.Message, "無效路徑");  
                return;  
            }  
            string strClientLocat = m_optInfo.m_optDataList["ClientLocat"];  
            if (strClientLocat == "")  
            {  
                MessageBox.Show("客戶端路徑不能為空!", "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);  
                return;  
            }  
            common.SetQualityKeys("ClientLocat", strClientLocat);  
            this.DialogResult = DialogResult.OK;  
        }  
        private void button_cancel_Click(object sender, EventArgs e)  
        {  
        }  
    }  
    public class PathEditor : UITypeEditor  
    {  
        public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)  
        {  
            if (context != null && context.Instance != null)  
            {  
                return UITypeEditorEditStyle.Modal;  
            }  
            return base.GetEditStyle(context);  
        }  
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)  
        {  
            IWindowsFormsEditorService editorService = null;  
            if (context != null && context.Instance != null && provider != null)  
            {  
                editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));  
                if (editorService != null)  
                {  
                    FolderBrowserDialog dirDlg = new FolderBrowserDialog();  
                 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved