面板控件库 XPanderControls

作者: Uwe Eichkorn.
翻译: [yn]Yuxiang

本文介绍一个可对子控件分组的可扩展面板控件库的使用。
C# (C# 2.0)
Windows (Win2K, WinXP, Vista), .NET (.NET 2.0)
Win32, VS (VS2005)
Dev
发表日期: 2007-4-13
更新日期: 2007-9-29

下载源代码和演示文件(http://www.codeproject.com/useritems/XPanderControls/xpandercontrols.zip) - 177.8 KB

原文:XPanderControls

译者注:(另外,限于篇幅,译文的大部分插图没有贴上来,请下载译文查看)
(1)在解压缩源代码后,建议把源码文件的只读属性取消,避免在保存时出现警告对话框
(2)在第一次打开解决方案后,需要先生成控件库 BSE.Windows.Forms.dll,否则演示窗体 Form1.cs 不能被打开
(3)在启动调试前,请把 BSE.Windows.Test 项目设置为启动项目
(4)
请注意:在使用 RightToLeft 功能时,在运行时刻,会产生错误(imageList2 控件初始,请参阅下面的相关说明),请关注作者的更新

简介

XPander 控件库提供了把多个用户控件放置在单个容器中的机制。可以随意地显示或隐藏它。 Xpander 控件追随 MS Outlook 的视觉风格。所有控件都支持可视化设计器、智能标记和 RightToLeft 功能。面板的使用与 toolstripenders 相关联,可形成有趣的视觉效果。

面板风格(Panel styles)

在演示项目中,面板的风格可以通过在 tooltrip 中的组合框进行更改。

水溶效果(Aqua effects)

Office2007 效果(Office2007 effects)

在可视化设计器中,面板颜色和属性都是可以定制和改变的。

RightToLeft 属性值被设置为 RightToLeft.Yes 时,控件元素的水平对齐方式就改变为从右向左。

 

代码使用

使用鼠标右键单击工具箱,然后选中“选择项”菜单项, 浏览找到文件 BSE.Windows.Forms.dll ,然后单击[确定]按钮。所有的控件将被添加到工具箱下的“用户控件”选项卡下。然后设置 BSE.Windows.Test 作为启动项目。

使用测试用例中的 RightToLeft 功能

打开 BSE.Windows.Test 项目中的文件 Program.cs,然后移除相关语句前面的注释符号:

[STAThread]
        static void Main()
        {
            //// if you want to use the RightToLeft demo,
            //// please remove this comments
            //CultureInfo currentCulture = new CultureInfo(BSE.Windows.Test.Properties.Settings.Default.Language);
            //Thread.CurrentThread.CurrentCulture = currentCulture;
            //Thread.CurrentThread.CurrentUICulture = currentCulture;

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            //// if you want to use the RightToLeft demo,
            //// please remove this comments
            //using (CCountrySelectionForm form = new CCountrySelectionForm())
            //{
                //form.ShowDialog();
            //}

            Application.Run(new Form1());
        }

再次对演示项目启动调试,首先会弹出如下对话框,供用户选择语系,选择“ar-EG(阿拉伯-埃及)语系”项目,则可演示 RightToLeft 功能。译者注:在初始 imageList2 控件时,产生错误“Index was outside the bounds of the array(数组下标越界)”,请关注作者的更新或自行解决。

 

控件属性

XPanderPanelList 集合控件的属性

  • XpanderPanels: 返回在 xpanderpanellist 中的 xpanderpanel 集合
  • PanelStyle:  指定 xpanderpanellist 中的面板的风格
    • Default:  以默认的 office2003 风格绘制面板的标题栏
    • Aqua:  以水溶(aqua)风格绘制面板的标题栏
    • Office2007:  以 office2007 风格绘制面板的标题栏
    • None:  隐藏标题栏(仅在 panel 控件中使用)
  • ColorScheme:  包含用于绘制 panel 或 xpanderpanel 的颜色信息
    • Professional:  以 System.Windows.Forms.ProfessionalColors 颜色绘制面板标题栏
    • Custom:  以自定义的颜色绘制面板标题栏
  • LinearGradientMode:  xpanderpanellist 的背景 LinearGradientMode
  • ShowGradientBackground:  返回或设置一个值,确定 xpanderpanellist 的渐变背景是否显示
  • ShowBorder:  返回或设置一个值,确定 xpanderpanellist 是否显示边框 (仅用于 PanelStyle.Default)
  • ShowExpandIcon:  返回或设置一个值,确定 xpanderpanellist 中的 XPanderPanel 的展开图标是否可见
  • ShowCloseIcon:  返回或设置一个值,确定 xpanderpanellist 中的 XPanderPanel 的关闭图标是否可见
  • GradientBackground:  xpanderpanellist 的渐变色背景

Panel 和 XPanderPanel 控件的属性

  • CaptionFont:  返回或设置显示在标题栏的文本字体
  • CaptionForeColor:  返回或设置标题栏文本的前景色
  • ColorScheme:  返回或设置 panel 的配色方案
    • Professional:  以 System.Windows.Forms.ProfessionalColors 颜色绘制面板标题栏
    • Custom:  以自定义的颜色绘制面板标题栏
  • ColorCaptionGradientBegin:  返回或设置标题栏的渐变开始颜色 (仅用于 ColorScheme.Custom)
  • ColorCaptionGradientMiddle:  返回或设置标题栏的渐变中间颜色 (仅用于 ColorScheme.Custom)
  • ColorCaptionGradientEnd:  返回或设置标题栏的渐变结束颜色 (仅用于 ColorScheme.Custom)
  • ColorContentPanelGradientBegin:  返回或设置面板背景的渐变开始颜色 (仅用于 panel 控件)
  • ColorContentPanelGradientEnd:  返回或设置面板背景的渐变结束颜色 (仅用于 panel 控件)
  • Image:  返回或设置显示在面板标题栏的图像
  • BorderColor:  返回或设置 panel 的边框颜色
  • LinearGradientMode:  面板背景的 LinearGradientMode (仅用于 panel 控件).
  • PanelStyle:  确定 xpanderpanellist 中的面板的风格
      • Default:  以默认的 office2003 风格绘制面板的标题栏
      • Aqua:  以水溶(aqua)风格绘制面板的标题栏
      • Office2007:  以 office2007 风格绘制面板的标题栏
      • None:  隐藏标题栏(仅在 panel 控件中使用)
  • ShowBorder:  返回或设置一个值,确定控件是否显示边框
  • ShowTransparentBackground:  返回或设置一个值,确定控件背景是否透明 (仅用于 panel 控件)
  • ShowXPanderPanelProfessionalStyle:  返回或设置一个值,确定控件标题栏的专业配色方案是否相同 (仅用于 panel 控件,仅用于 PanelStyle Default).
  • Expand:  展开在 XPanderPanelList 中的 xpanderpanel
  • ShowExpandIcon:  返回或设置一个值,确定 XPanderPanel 的展开图标是否可见
  • ShowCloseIcon:  返回或设置一个值,确定 XPanderPanel 的关闭图标是否可见
  • CloseIconForeColor:  返回或设置 XPanderPanel 关闭图标的前景色
  • IsClosable:  返回或设置一个值,确定 XPanderPanel 是否可被关闭

展开 XPanderPanel

在设计时刻展开一个 XPanderPanelList 集合中的 XPanderPanel

(1)使用鼠标右键单击 XPanderPanelList 控件,在弹出的快捷菜单中选中 "选择 'xPanderPanelList...'"菜单项,此时 XPanderPanels 控件被选定

(2)单击控件的智能标记,在弹出的上下文菜单中选中"Edit XPanderPanels Collection" 菜单项

(3)在弹出的“XPanderPane 集合编辑器”对话框中,设置指定 XPanderPanel 的 Expand 属性为 True

 

在运行时刻展开一个 XPanderPanelList 集合中的 XPanderPanel

private void toolStripButton1_Click(object sender, EventArgs e)
{
    if (xPanderPanel11 != null)
    {
        xPanderPanelList3.Expand(xPanderPanel11);
    }
}

除了当前的 XPanderPanel 被展开以外,XPanderPanelList 集合中的其他 XPanderPanel 将全部被折叠。

/// expands the specified xpanderpanel
public void Expand(XPanderPanel xpanderPanel)
{
    if (xpanderPanel == null)
    {
        throw new ArgumentException(
            string.Format(
            System.Globalization.CultureInfo.CurrentUICulture,
            Resources.IDS_ArgumentException,
            typeof(XPanderPanel).Name));
    }
    else
    {
        foreach (XPanderPanel tmpXPanderPanel in this.m_xpanderPanels)
        {
            if (tmpXPanderPanel.Equals(xpanderPanel) == false)
            {
                tmpXPanderPanel.Expand = false;
            }
        }
        xpanderPanel.Expand = true;
    }
}

面板配置管理器(PanelSettingsManager)

在运行时刻使用面板配置管理器(PanelSettingsManager):

  • 把配置写入 PanelProperties 对象

 

BSE.Windows.Forms.PanelProperties panelPropertiesOffice2007Silver = new BSE.Windows.Forms.PanelProperties();
panelPropertiesOffice2007Silver.StyleName = "Office2007 Silver";
panelPropertiesOffice2007Silver.PanelStyle = BSE.Windows.Forms.PanelStyle.Office2007;
panelPropertiesOffice2007Silver.ColorScheme = BSE.Windows.Forms.ColorScheme.Custom;
panelPropertiesOffice2007Silver.CaptionForeColor = Color.Black;
panelPropertiesOffice2007Silver.ColorCaptionGradientBegin = Color.FromArgb(248, 248, 248);
panelPropertiesOffice2007Silver.ColorCaptionGradientEnd = Color.FromArgb(199, 203, 209);
panelPropertiesOffice2007Silver.BackColor = Color.FromArgb(240, 241, 242);
panelPropertiesOffice2007Silver.BorderColor = Color.FromArgb(76, 83, 92);
panelPropertiesOffice2007Silver.ShowBorder = true;

 

  • 并设置属性
BSE.Windows.Forms.PanelSettingsManager.SetPanelProperties(
    this.Controls,
    panelPropertiesOffice2007Silver);

 

 

版本更新记录

  • 2007.04.13 - 第一版
  • 2007.04.30 - 第二版
    • 添加对 RightToLeft 的支持
  • 2007.09.29 - 第三版
    • 对 PanelStyle 添加 Office2007 风格
    • 对 XPanderPanel 添加关闭和展开(折叠)图标
    • 对 PanelSettingsManager 添加外部的属性设置功能
posted @ 2009-06-11 14:15  【Nanao】  阅读(3775)  评论(8编辑  收藏  举报