在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例桌面应用界面/GUI → 仿OutlookBar界面 控件源码

仿OutlookBar界面 控件源码

桌面应用界面/GUI

下载此实例
  • 开发语言:C#
  • 实例大小:0.12M
  • 下载次数:36
  • 浏览次数:1225
  • 发布时间:2015-11-06
  • 实例类别:桌面应用界面/GUI
  • 发 布 人:pplive_2015
  • 文件格式:.rar
  • 所需积分:2
 相关标签: OutLook out

实例介绍

【实例简介】 
跟XP系统左侧可折叠式菜单一样,可以折叠、展开,可以自己定义颜色,自己研究吧,非常有用的一个源码,样式和outlook左侧菜单差不多!我自己就在用,我用在erp项目里面,哈哈,很爽啊,大概步骤: 1.在你的解决方案里添加“现有项目”,找到BSE.Windows.Forms添加进去→2.在你自己的工程里面引用刚才添加的项目→3.运行一下,完成,在左边工具箱中就有啦。大概过程就是这样,反正死活就是要先引用。

【实例截图】

【核心代码】

using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Data;
using System.Windows.Forms;
using System.ComponentModel.Design;

namespace BSE.Windows.Forms
{
    #region Partial class XPanderPanel
	/// <summary>
	/// Used to group collections of controls. 
	/// </summary>
	/// <remarks>
	/// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
	/// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
	/// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
	/// PURPOSE. IT CAN BE DISTRIBUTED FREE OF CHARGE AS LONG AS THIS HEADER 
	/// REMAINS UNCHANGED.
	/// </remarks>
	/// <copyright>Copyright ?2006-2007 Uwe Eichkorn</copyright>
    [Designer(typeof(XPanderPanelDesigner))]
    [DesignTimeVisible(false)]
	public partial class XPanderPanel : BasePanel
	{
		#region EventsPublic
		/// <summary>
		/// Occurs when the caption of the xpanderpanel is clicked. 
		/// </summary>
        [Description("Occurs when the caption of the xpanderpanel is clicked.")]
        public event EventHandler<XPanderPanelClickEventArgs> CaptionClick;
		#endregion
		
		#region Constants
		#endregion

		#region FieldsPrivate
		
		private BSE.Windows.Forms.PanelStyle m_ePanelStyle;
		private System.Drawing.Image m_imageChevron;
        private System.Drawing.Image m_imageChevronUp;
        private System.Drawing.Image m_imageChevronDown;
        private Color m_colorChevron;
        private bool m_bExpand;

		#endregion

		#region Properties
		/// <summary>
		/// Gets or sets the caption style in this xpanderpanel.
		/// </summary>
		[DesignerSerializationVisibility( DesignerSerializationVisibility.Hidden)]
		public override BSE.Windows.Forms.PanelStyle PanelStyle
		{
			get {return this.m_ePanelStyle;}
			set
			{
                if (value != this.m_ePanelStyle)
                {
                    this.m_ePanelStyle = value;
                    this.Invalidate();
                }
			}
		}
        /// <summary>
        /// The foreground color of this component, which is used to display the caption text.
        /// </summary>
        [Description("The foreground color of this component, which is used to display the caption text.")]
        [DefaultValue(typeof(SystemColors), "System.Drawing.SystemColors.ActiveCaptionText")]
        [Category("Appearance")]
        public override Color CaptionForeColor
        {
            get { return base.CaptionForeColor; }
            set
            {
                if (value != base.CaptionForeColor)
                {
                    base.CaptionForeColor = value;
                    this.m_colorChevron = Color.FromArgb(255,
                        Math.Min(255, (int)((float)(base.CaptionForeColor.R) / (float)(1.01))),
                        Math.Min(255, (int)((float)(base.CaptionForeColor.G) / (float)(1.01))),
                        Math.Min(255, (int)((float)(base.CaptionForeColor.B) / (float)(1.01))));
                    this.Invalidate(this.CaptionRectangle);
                }
            }
        }
		/// <summary>
		/// Expands this xpanderpanel in it's xpanderpanellist
		/// </summary>
		[Description("Expand this XpanderPanel")]
		[DefaultValue(false)]
		[Category("Appearance")]
		public bool Expand
		{
			get {return this.m_bExpand;}
			set
			{
                if (value != this.m_bExpand)
                {
                    this.m_bExpand = value;
                    if (this.DesignMode == true)
                    {
                        if (this.m_bExpand == true)
                        {
                            if (this.CaptionClick != null)
                            {
                                this.CaptionClick(this, new XPanderPanelClickEventArgs(this.m_bExpand));
                            }
                        }
                    }
                    this.Invalidate();
                }
			}
		}
        internal Color ChevronColor
        {
            get { return this.m_colorChevron; }
        }
		#endregion

		#region MethodsPublic
		/// <summary>
		/// Initializes a new instance of the XPanderPanel class.
		/// </summary>
		public XPanderPanel()
		{
			InitializeComponent();

			this.CaptionForeColor = SystemColors.ControlText;
            this.BackColor = SystemColors.Window;
            this.ForeColor = SystemColors.ControlText;
            this.DockPadding.Top = this.CaptionHeight;
			this.Height = this.CaptionHeight;
			this.ShowBorder = true;

            this.m_imageChevronUp = global::BSE.Windows.Forms.Properties.Resources.chevron_up;
            this.m_imageChevronDown = global::BSE.Windows.Forms.Properties.Resources.chevron_down;
		}

		#endregion

		#region MethodsProtected
		/// <summary>
		/// Paints the background of the control.
		/// </summary>
		/// <param name="pevent">A PaintEventArgs that contains information about the control to paint.</param>
		protected override void OnPaintBackground(PaintEventArgs pevent)
		{
			base.OnPaintBackground(pevent);
		}
		/// <summary>
		/// Raises the Paint event.
		/// </summary>
		/// <param name="e">A PaintEventArgs that contains the event data.</param>
		protected override void OnPaint(PaintEventArgs e)
		{
			base.OnPaint(e);
            switch (this.m_ePanelStyle)
            {
                case PanelStyle.None:
                case PanelStyle.Default:
					DrawStyleDefault(e);
                    CalculatePanelHeights();
					DrawBorder(e);
                    break;
                case PanelStyle.Aqua:
					DrawStyleAqua(e);
                    CalculatePanelHeights();
                    break;
            }
		}
		/// <summary>
		/// Raises the OnMouseMove event.
		/// </summary>
		/// <param name="e">A MouseEventArgs that contains the event data.</param>
		protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e)
		{
            base.OnMouseMove(e);
            //Change cursor to hand when mouse moves over caption area.
			if (e.Y <= this.CaptionHeight)
			{
				Cursor.Current = Cursors.Hand;
			}
			else
			{
				Cursor.Current = Cursors.Default;
			}
		}
		/// <summary>
		/// Raises the MouseDown event.
		/// </summary>
		/// <param name="e">A MouseEventArgs that contains data about the OnMouseDown event.</param>
		protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
		{
            base.OnMouseDown(e);
            //Don't do anything if did not click on caption.
			if (e.Y > this.CaptionHeight)
			{
				return;
			}

			if (this.m_bExpand == false)
			{
				this.m_bExpand = true;
                if (this.CaptionClick != null)
                {
                    this.CaptionClick(this, new BSE.Windows.Forms.XPanderPanelClickEventArgs(this.m_bExpand));
                }
			}
		}
		/// <summary>
		/// Raises the VisibleChanged event.
		/// </summary>
		/// <param name="e">An EventArgs that contains the event data.</param>
        protected override void OnVisibleChanged(EventArgs e)
        {
            base.OnVisibleChanged(e);

            if (this.DesignMode == true)
            {
                return;
            }
            if (this.Visible == false)
            {
                if (this.Expand == true)
                {
                    this.Expand = false;
                    foreach (Control control in this.Parent.Controls)
                    {
                        BSE.Windows.Forms.XPanderPanel xpanderPanel =
                            control as BSE.Windows.Forms.XPanderPanel;

                        if (xpanderPanel != null)
                        {
                            if (xpanderPanel.Visible == true)
                            {
                                xpanderPanel.Expand = true;
                                return;
                            }
                        }
                    }
                }
            }
#if DEBUG
            //System.Diagnostics.Trace.WriteLine("Visibility: "   this.Name   this.Visible);
#endif
            CalculatePanelHeights();
        }

		#endregion

		#region MethodsPrivate

		private void DrawStyleDefault(PaintEventArgs e)
		{
            Rectangle rectangle = this.CaptionRectangle;
            Color colorGradientBegin = ProfessionalColors.ToolStripGradientBegin;
            Color colorGradientMiddle = ProfessionalColors.ToolStripGradientMiddle;
            Color colorGradientEnd = ProfessionalColors.ToolStripGradientEnd;

            if (this.ColorScheme == ColorScheme.Custom)
            {
                colorGradientBegin = this.ColorCaptionGradientBegin;
                colorGradientMiddle = this.ColorCaptionGradientMiddle;
                colorGradientEnd = this.ColorCaptionGradientEnd;
            }

            if (this.m_bExpand == true)
            {
                if (this.ColorScheme == ColorScheme.Professional)
                {
                    colorGradientBegin = ProfessionalColors.ButtonCheckedGradientBegin;
                    colorGradientMiddle = ProfessionalColors.ButtonCheckedGradientMiddle;
                    colorGradientEnd = ProfessionalColors.ButtonCheckedGradientEnd;
                }
                this.m_imageChevron = this.m_imageChevronUp;
            }
            else
            {
                this.m_imageChevron = this.m_imageChevronDown;
            }
            
			RenderDoubleBackgroundGradient(
				e.Graphics,
				rectangle,
				colorGradientBegin,
				colorGradientMiddle,
				colorGradientEnd,
				LinearGradientMode.Vertical,
				false);

			int iTextPositionX = CaptionSpacing;
			if (this.Image != null)
			{
				Rectangle imageRectangle = this.ImageRectangle;
				if (this.RightToLeft == RightToLeft.No)
				{
					DrawImage(e.Graphics, this.Image, imageRectangle);
					iTextPositionX  = this.ImageSize.Width   CaptionSpacing;
				}
				else
				{
					imageRectangle.X = rectangle.Right - RightImagePositionX;
					DrawImage(e.Graphics, this.Image, imageRectangle);
				}
			}
			Rectangle textRectangle = rectangle;
			textRectangle.X = iTextPositionX;
			textRectangle.Width -= iTextPositionX   CaptionSpacing;
			if (this.RightToLeft == RightToLeft.Yes)
			{
				if (this.Image != null)
				{
					textRectangle.Width -= RightImagePositionX;
				}
			}
			DrawString(e.Graphics, textRectangle, this.CaptionFont, this.CaptionForeColor, this.Text, this.RightToLeft);

            if (this.ShowBorder == true)
            {
                if (this.Expand == true)
                {
                    using (SolidBrush borderBrush = new SolidBrush(System.Windows.Forms.ProfessionalColors.ToolStripBorder))
                    {
                        using (Pen borderPen = new Pen(borderBrush, 1))
                        {
                            e.Graphics.DrawLine(
                                borderPen,
                                this.ClientRectangle.Left,
                                this.CaptionHeight,
                                this.ClientRectangle.Width,
                                this.CaptionHeight);
                        }
                    }
                }
            }
		}

        private void DrawStyleAqua(PaintEventArgs e)
        {
            Color colorGradientBegin = ProfessionalColors.ToolStripGradientBegin;
            Color colorGradientEnd = ProfessionalColors.ToolStripGradientEnd;

            if (this.ColorScheme == ColorScheme.Custom)
            {
                colorGradientBegin = this.ColorCaptionGradientBegin;
                colorGradientEnd = this.ColorCaptionGradientEnd;
            }
            // defines the chevron direction
            if (this.m_bExpand == true)
            {
                this.m_imageChevron = this.m_imageChevronUp;
            }
            else
            {
                this.m_imageChevron = this.m_imageChevronDown;
            }
            Rectangle outerRectangle = this.CaptionRectangle;

            using (GraphicsPath outerRectangleGraphicsPath = GetBackgroundPath(outerRectangle, 20))
            {
                using (LinearGradientBrush outerLinearGradientBrush = new LinearGradientBrush(
                    outerRectangle,
                    colorGradientBegin,
                    colorGradientEnd,
                    LinearGradientMode.Vertical))
                {
                    e.Graphics.FillPath(outerLinearGradientBrush, outerRectangleGraphicsPath); //draw top bubble
                }
            }
            //
            // Create top water color to give "aqua" effect
            // 
            Rectangle innerRectangle = outerRectangle;
            innerRectangle.Height = 14;

			using (GraphicsPath innerRectangleGraphicsPath = GetPath(innerRectangle, 20))
			{
                using (LinearGradientBrush innerRectangleBrush = new LinearGradientBrush(
                    innerRectangle,
                    Color.FromArgb(255, Color.White),
                    Color.FromArgb(32, Color.White),
                    LinearGradientMode.Vertical))
				{
					//
					// draw shapes
					//
					e.Graphics.FillPath(innerRectangleBrush, innerRectangleGraphicsPath); //draw top bubble
				}
			}
			//DrawImage
            int iTextPositionX1 = CaptionSpacing;
			Rectangle imageRectangleLeft = this.ImageRectangle;
            if (RightToLeft == RightToLeft.No)
            {
                if (this.Image != null)
                {
                    DrawImage(e.Graphics, this.Image, imageRectangleLeft);
                    iTextPositionX1  = this.ImageSize.Width   CaptionSpacing;
                }
            }
            else
            {
                DrawChevron(e.Graphics, this.m_imageChevron,imageRectangleLeft, this.ChevronColor);
				iTextPositionX1  = this.ImageSize.Width   CaptionSpacing;
            }
            //
            // Draw Caption text
            //
            Rectangle textRectangle = outerRectangle;
			textRectangle.X = iTextPositionX1;
			textRectangle.Width = outerRectangle.Width - textRectangle.X - RightImagePositionX - CaptionSpacing;
			int iTextPositionX2 = outerRectangle.Right - RightImagePositionX;
            Rectangle imageRectangleRight = this.ImageRectangle;
			imageRectangleRight.X = iTextPositionX2;
			if (RightToLeft == RightToLeft.No)
            {
                DrawChevron(e.Graphics, this.m_imageChevron, imageRectangleRight, this.ChevronColor);
            }
            else
            {
				if (this.Image != null)
				{
					DrawImage(e.Graphics, this.Image, imageRectangleRight);
				}
				else
				{
					textRectangle.Width  = CaptionSpacing   this.ImageSize.Width;
				}
            }
			DrawString(e.Graphics, textRectangle, this.CaptionFont, this.CaptionForeColor, this.Text, this.RightToLeft);
        }

		private void DrawBorder(PaintEventArgs e)
		{
			if (this.ShowBorder == true)
			{
                Rectangle borderRectangle = this.ClientRectangle;
                borderRectangle.Inflate(0, 1);
                borderRectangle.Offset(0, -1);

                ControlPaint.DrawBorder(
                    e.Graphics,
                    borderRectangle,
                    System.Windows.Forms.ProfessionalColors.ToolStripBorder,
                     ButtonBorderStyle.Solid);
			}
		}

		private void CalculatePanelHeights()
		{
			if (this.Parent == null)
			{
				return;
			}

            int iPanelHeight = this.Parent.Padding.Top;

            foreach (Control control in this.Parent.Controls)
            {
				BSE.Windows.Forms.XPanderPanel xpanderPanel =
					control as BSE.Windows.Forms.XPanderPanel;

				if (xpanderPanel != null)
				{
					if (xpanderPanel.Visible == true)
					{
						iPanelHeight  = this.CaptionHeight;
					}
				}
            }

			iPanelHeight  = this.Parent.Padding.Bottom;

            foreach (Control control in this.Parent.Controls)
			{
				BSE.Windows.Forms.XPanderPanel xpanderPanel =
					control as BSE.Windows.Forms.XPanderPanel;

                if (xpanderPanel != null)
                {
                    if (xpanderPanel.Expand == true)
                    {
                        xpanderPanel.Height = this.Parent.Height
                              this.CaptionHeight
                            - iPanelHeight;
                    }
                    else
                    {
                        xpanderPanel.Height = this.CaptionHeight;
                    }
                }
			}

			int iTop = this.Parent.Padding.Top;
			foreach (Control control in this.Parent.Controls)
			{
				BSE.Windows.Forms.XPanderPanel xpanderPanel =
					control as BSE.Windows.Forms.XPanderPanel;

				if (xpanderPanel != null)
			    {
					if (xpanderPanel.Visible == true)
					{
						xpanderPanel.Top = iTop;
						iTop  = xpanderPanel.Height;
					}
			    }
			}
		}

		#endregion
    }

    #endregion

    #region Class XPanderPanelDesigner

	internal class XPanderPanelDesigner : System.Windows.Forms.Design.ScrollableControlDesigner
	{
		#region FieldsPrivate

		private Pen m_BorderPen = new Pen(Color.FromKnownColor(KnownColor.ControlDarkDark));

		#endregion

		#region MethodsPublic
		/// <summary>
		/// 
		/// </summary>
		public XPanderPanelDesigner()
		{
			this.m_BorderPen.DashStyle = DashStyle.Dash;
		}
		/// <summary>
		/// Initializes the designer with the specified component.
		/// </summary>
		/// <param name="component">The IComponent to associate with the designer.</param>
		public override void Initialize(IComponent component)
		{
			base.Initialize(component);
		}
		/// <summary>
		/// Gets the selection rules that indicate the movement capabilities of a component.
		/// </summary>
		public override System.Windows.Forms.Design.SelectionRules SelectionRules
		{
			get
			{
				System.Windows.Forms.Design.SelectionRules selectionRules
					= System.Windows.Forms.Design.SelectionRules.None;

				return selectionRules;
			}
		}

		#endregion

		#region MethodsProtected
		/// <summary>
		/// Receives a call when the control that the designer is managing has painted its surface so the designer can
		/// paint any additional adornments on top of the xpanderpanel.
		/// </summary>
		/// <param name="e">A PaintEventArgs the designer can use to draw on the xpanderpanel.</param>
		protected override void OnPaintAdornments(PaintEventArgs e)
		{
			base.OnPaintAdornments(e);
			e.Graphics.DrawRectangle(
				this.m_BorderPen,
				0,
				0,
				this.Control.Width - 2,
				this.Control.Height - 2);
		}
		/// <summary>
		/// Allows a designer to change or remove items from the set of properties that it exposes through a <see cref="TypeDescriptor">TypeDescriptor</see>. 
		/// </summary>
		/// <param name="properties">The properties for the class of the component.</param>
		protected override void PostFilterProperties(IDictionary properties)
		{
			base.PostFilterProperties(properties);
			properties.Remove("AccessibilityObject");
			properties.Remove("AccessibleDefaultActionDescription");
			properties.Remove("AccessibleDescription");
			properties.Remove("AccessibleName");
			properties.Remove("AccessibleRole");
			properties.Remove("AllowDrop");
            properties.Remove("Anchor");
            properties.Remove("AntiAliasing");
			properties.Remove("AutoScroll");
			properties.Remove("AutoScrollMargin");
			properties.Remove("AutoScrollMinSize");
			properties.Remove("BackgroundImage");
			properties.Remove("BackgroundImageLayout");
			properties.Remove("CausesValidation");
			properties.Remove("ContextMenuStrip");
			properties.Remove("Dock");
			properties.Remove("GenerateMember");
			properties.Remove("ImeMode");
            properties.Remove("Location");
			properties.Remove("MaximumSize");
			properties.Remove("MinimumSize");
            properties.Remove("Size");
		}

		#endregion
	}

    #endregion

}

标签: OutLook out

实例下载地址

仿OutlookBar界面 控件源码

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

第 1 楼 century5200 发表于: 2016-03-26 15:22 31
没有实例,只是一个.DLL源代码,不知道运行效果

支持(0) 盖楼(回复)

第 2 楼 century5200 发表于: 2016-03-26 15:22 38
没有实例,只是一个.DLL源代码,不知道运行效果

支持(0) 盖楼(回复)

发表评论

(您的评论需要经过审核才能显示)

查看所有2条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警