<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      WinForm控件開發總結(九)-----為屬性提下拉式屬性編輯器

            在上一篇文章,我介紹了如何編寫模態對話框屬性編輯器,這篇文章我將介紹如何編寫下拉式屬性編輯器。下拉式(DropDown)屬性編輯器和模態對話框屬性編輯器的不同之處就是,當你點擊屬性值修改的時候,模態對話框編輯器是彈出一個模態對話框,而下拉式屬性編輯器卻是在緊貼著屬性值的地方顯示一個下拉的控件。不知道大家注意到了沒有,這里我說的是顯示一個下拉的控件,而這個控件也是需要你去開發的,接下來我還是以Scope屬性為例,介紹一下具體的實現。
            首先我們要創建一個用于編輯屬性的控件,在本系列文章的開始,我們介紹了自定義控件有三種類型:復合控件,擴展控件,自定義控件。在本例中我們制作一個復合控件(Compsite control),復合控件的開發比較簡單,不在本系列文章的講解范圍,我簡單做個介紹,在Solution 瀏覽器里右鍵點擊CustomControlSample工程選擇Add->User Control…,輸入文件名ScopeEditorControl.cs。我們做的這個復合控件上一篇文章介紹的模態對話框所包含子控件基本一樣,除了用于確認和取消的按鈕,如下圖:
            
            由于我們取消了用于確認和取消的按鈕,并且是一個下拉的編輯器控件,在出現下面三種情況的時候下拉的編輯器控件會關閉:用戶敲了回車,用戶敲了ESC鍵,用戶點擊了編輯器以外的地方。當下拉編輯器控件關閉的時候我們就需要更新屬性的值。下邊是這個控件的代碼:
            
      using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.Drawing;
      using System.Data;
      using System.Text;
      using System.Windows.Forms;

      namespace CustomControlSample
      {
          
      public partial class ScopeEditorControl : UserControl
          
      {
              
      private Scope _oldScope;
              
      private Scope _newScope;
              
      private Boolean canceling;
              
              
      public ScopeEditorControl(Scope scope)
              
      {
                  _oldScope 
      = scope;
                  _newScope 
      = scope;
                  InitializeComponent();
              }


              
      public Scope Scope
              
      {
                  
      get
                  
      {
                      
      return _newScope;
                  }

              }


              
      private void textBox1_Validating(object sender, CancelEventArgs e)
              
      {
                  
      try
                  
      {
                      Int32.Parse(textBox1.Text);

                  }

                  
      catch (FormatException)
                  
      {
                      e.Cancel 
      = true;
                      MessageBox.Show(
      "無效的值""驗證錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
                  }

              }


              
      private void textBox2_Validating(object sender, CancelEventArgs e)
              
      {
                  
      try
                  
      {
                      Int32.Parse(textBox2.Text);
                  }

                  
      catch (FormatException)
                  
      {
                      e.Cancel 
      = true;
                      MessageBox.Show(
      "無效的值""驗證錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
                  }

              }


              
      protected override bool ProcessDialogKey(Keys keyData)
              
      {
                  
      if (keyData == Keys.Escape)
                  
      {
                      _oldScope 
      = _newScope;
                      canceling 
      = true;
                  }

                  
      return base.ProcessDialogKey(keyData);
              }


              
      private void ScopeEditorControl_Leave(object sender, EventArgs e)
              
      {
                  
      if (!canceling)
                  
      {
                      _newScope.Max 
      = Convert.ToInt32(textBox1.Text);
                      _newScope.Min 
      = Convert.ToInt32(textBox2.Text);
                  }

              }


              
      private void ScopeEditorControl_Load(object sender, EventArgs e)
              
      {
                  textBox1.Text 
      = _oldScope.Max.ToString();
                  textBox2.Text 
      = _oldScope.Min.ToString();
              }



          }

      }


               和模態對話框編輯器一樣,開發環境并不會直接調用我們的編輯器控件,而是用過UITypeEditor類的派生來實現編輯器的調用,所以我們必須實現一個下拉式編輯器。代碼如下:
            
      using System;
      using System.ComponentModel;
      using System.Drawing.Design;
      using System.Windows.Forms.Design;
      using System.Windows.Forms;

      namespace CustomControlSample
      {
          
      public class ScopeDropDownEditor : UITypeEditor
          
      {
              
      public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
              
      {
                  
      if (context != null && context.Instance != null)
                  
      {
                      
      return UITypeEditorEditStyle.DropDown;
                  }


                  
      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)
                      
      {
                          MyListControl control 
      = (MyListControl)context.Instance;
                          ScopeEditorControl editorControl 
      = new ScopeEditorControl(control.Scope);
                          editorService.DropDownControl(editorControl);
                          value 
      = editorControl.Scope;
                          
      return value;
                      }

                  }


                  
      return value;
              }


          }

      }

            看過上一篇文章的朋友應該對這段代碼很熟悉,是的,這兩個編輯器的代碼只有幾行不同之處,在GetEditStyle方法中,我們返回的是UITypeEditorEditStyle.DropDown,而不是UITypeEditorEditStyle.Modal,表明我們的編輯器是一個下拉式的編輯器。在EditValue中的不同之處是,我們使用DropDownControl方法來顯示編輯器。編輯器制作完畢,我們把Scope以前的編輯器替換成下拉式編輯器,如下:
            

      [Browsable(true)]
              [Editor(
      typeof(ScopeDropDownEditor), typeof(UITypeEditor))]
              
      public Scope Scope
              
      {
                  
      get
                  
      {
                      
      return _scope;
                  }

                  
      set
                  
      {
                      _scope 
      = value;
                  }

              }

            現在build CustomControlSample工程,然后切換到測試工程查看Scope屬性。當我們點擊屬性的值,在屬性值的后邊出現了一個按鈕:
               

         當點擊這個按鈕的時候,下拉的屬性編輯器出現了:
            

         好了,屬性的編輯到這里就講完了。

      posted @ 2006-12-19 22:05  綸巾客  閱讀(11363)  評論(9)    收藏  舉報
      主站蜘蛛池模板: 精品国产欧美一区二区三区在线| 国产高清在线A免费视频观看| 乌鲁木齐市| 深夜福利成人免费在线观看| 亚洲中文字幕日产无码成人片| 一本色道久久加勒比综合| h无码精品动漫在线观看| 成人区人妻精品一区二蜜臀 | 肥臀浪妇太爽了快点再快点| 亚洲韩国精品无码一区二区三区| 亚洲AV永久无码一区| 霍林郭勒市| 九九综合va免费看| 国产线播放免费人成视频播放| 绥江县| 亚洲精品国产无套在线观| 免费av深夜在线观看| 97亚洲熟妇自偷自拍另类图片 | 少妇特黄a一区二区三区| 天堂网av成人在线观看| 久视频久免费视频久免费| 九色综合狠狠综合久久| 无码人妻出轨黑人中文字幕| 亚洲国产天堂久久综合226114| 丰满人妻一区二区三区无码AV| 国语对白刺激在线视频国产网红 | 色一伊人区二区亚洲最大| 人成午夜免费大片| 老熟妇仑乱一区二区视頻| 精品国产中文字幕在线| 五月婷婷深开心五月天| 日本a在线播放| 亚洲a∨国产av综合av| 汝州市| 亚洲乱妇老熟女爽到高潮的片| 成人午夜免费无码视频在线观看| 人妻内射一区二区在线视频| 亚洲成人精品综合在线| 商河县| 三级国产在线观看| 四虎永久免费很黄的视频|