自己開發基於c#的垂直滾動條控件


由於Visual Studio工具箱中自帶滾動條控件外觀太老,而且沒有顏色外觀屬性可設置。 所以自己就試着開發一個垂直的滾動條,它可以用來控制TextBox的滾動。

由於代碼比較多,源文件已經打包到網盤,鏈接:http://pan.baidu.com/s/1dDtn8sD                   

 

Release目錄下生成的dll可以添加至工具箱

使用時需要設置的屬性:        

        #region 滑動條最短長度
        [System.ComponentModel.Browsable(true)]
        [Localizable(true)]
        [System.ComponentModel.Category("Appearance")]
        [System.ComponentModel.DefaultValue(null)]
        [System.ComponentModel.Description("滑動條最短長度")]
        public int MinSlideBarLenght{get; set;}
        #endregion

#region 要滑動的TextBox [System.ComponentModel.Browsable(true)] [Localizable(true)] [System.ComponentModel.Category("Appearance")] [System.ComponentModel.DefaultValue(null)] [System.ComponentModel.Description("要滾動的TextBox")] public TextBox TextBox{get; set;} #endregion

#region 滑動條被喚醒顏色 [System.ComponentModel.Browsable(true)] [Localizable(true)] [System.ComponentModel.Category("Appearance")] [System.ComponentModel.Description("滑動條被喚醒的顏色")] [System.ComponentModel.DefaultValue(null)] public Color WakedColor{get; set;} #endregion

#region 滑動條被按下顏色 [System.ComponentModel.Browsable(true)] [Localizable(true)] [System.ComponentModel.Category("Appearance")] [System.ComponentModel.DefaultValue(null)] [System.ComponentModel.Description("滑動條被按下的顏色")] public Color PressedColor{get;set;} #endregion

#region 鼠標進入滑動條顏色 [System.ComponentModel.Browsable(true)] [Localizable(true)] [System.ComponentModel.Category("Appearance")] [System.ComponentModel.DefaultValue(null)] [System.ComponentModel.Description("鼠標進入滑動條的顏色")] public Color EnterColor {get; set;} #endregion

 


 

例如:

在屬性瀏覽器中設置:

 


 

設計器自動生成如下代碼:

在Form類中:

  private MyControlLibrary.ScrollBar TextScrollBar;

在InitializeComponent()中:

            this.TextScrollBar.BackColor = System.Drawing.Color.White;
            this.TextScrollBar.EnterColor = System.Drawing.SystemColors.ControlDark;
            this.TextScrollBar.Location = new System.Drawing.Point(664, 44);
            this.TextScrollBar.MinSlideBarLenght = 30;
            this.TextScrollBar.Name = "TextScrollBar";
            this.TextScrollBar.PressedColor = System.Drawing.SystemColors.ControlDarkDark;
            this.TextScrollBar.Size = new System.Drawing.Size(10, 323);
            this.TextScrollBar.TabIndex = 18;
            this.TextScrollBar.TextBox = this.TextBox_Receive;
            this.TextScrollBar.WakedColor = System.Drawing.SystemColors.ControlLight;

 


 

效果圖:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM