添加C1Themes到WinForms应用程序

本文介绍如何添加C1Themes到已经存在的WinForms应用程序。C1Themes内置超过25种专业设计的主题,也可以自定义主题,用于应用程序。本文主要介绍了给C1FlexGrid和C1TrueDBGrid设置主题,根据下述步骤,也可以给ComponentOne Studio for WinForms的C1Report,C1Ribbon以及其他控件,添加C1Themes。Demo运行起来的效果如下图所示,可以在ComboBox的下拉菜单里选择不同的Theme设置给窗体上的C1FlexGrid和C1TrueDBGrid。<p><a href="http://www.grapecity.com.cn/image.ashx?picture=C1Themepng.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="C1Themepng" src="http://www.grapecity.com.cn/image.ashx?picture=C1Themepng_thumb.png" alt="C1Themepng" width="799" height="556" border="0" /></a></p>

发布于 2014/05/29 00:00

ComponentOne Enterprise

本文介绍如何添加C1Themes到已经存在的WinForms应用程序。C1Themes内置超过25种专业设计的主题,也可以自定义主题,用于应用程序。本文主要介绍了给C1FlexGrid和C1TrueDBGrid设置主题,根据下述步骤,也可以给ComponentOne Studio for WinForms的C1Report,C1Ribbon以及其他控件,添加C1Themes。

1 添加C1ThemeController

首先添加需要更改主题的控件到应用程序中,在本文Demo中,先从工具箱拖拽C1FlexGrid和C1TrueDBGrid到窗体,并且对两个控件进行数据绑定。C1FlexGridDataSource绑定Employees数据表,C1TrueDBGrid绑定EmployeesOrders,数据绑定代码如下:

this.c1TrueDBGrid1.DataSource = this.employeesOrdersBindingSource;
this.c1FlexGrid1.DataSource = this.employeesBindingSource;

然后从工具箱中拖拽C1ThemeController到窗体,会弹出如下编辑框:

C1Theme-ThemeController

 

可以在给C1FlexGrid、C1TrueDBGrid何窗体设置不同的主题,默认为None。

2 将所有Themes添加到ComboBox

添加标准的ComboBox到窗体,然后在FormLoad的时候,将C1ThemController所有可用的主题都加入到ComboBox的下拉菜单中,方便运行时选择,并设置初始化主题,代码如下:

// populate combobox with all available themes
            this.comboBox1.Items.AddRange(C1.Win.C1Themes.C1ThemeController.GetThemes());
            // set initial theme
            comboBox1.SelectedIndex = 0;

3 设置主题

设置ComboBox的SelectedIndexChanged事件,当打开下拉框选择相应的主题时,调用该事件改变窗体上所有控件的主题,具体代码如下:

  private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            // Set theme on the theme controller:
            this.c1ThemeController1.Theme = this.comboBox1.SelectedItem.ToString();
            // ...and apply it to all themable controls (this will override any control-specific theme settings):
            Action setTheme = null;
            setTheme = (c) =>
            {
                if (C1.Win.C1Themes.C1ThemeController.IsObjectThemeable(c))
                    this.c1ThemeController1.SetTheme(c, this.c1ThemeController1.Theme);
                foreach (Control cc in c.Controls)
                    setTheme(cc);
            };
            setTheme(this);
        }
    }

根据代码,首先将ComboBox下拉菜单中选择的Theme设置给C1ThemeController,然后给所有的窗体上的控件使用该Theme。运行起来的效果如下图所示,可以在ComboBox的下拉菜单里选择不同的Theme设置给窗体上的C1FlexGrid和C1TrueDBGrid。

C1Themepng

 

本文Demo的源代码如下:

 

C1Theme1.7z (2.83 mb)

ComponentOne Enterprise | 下载试用

ComponentOne 是一套专注于企业 .NET开发、支持 .NET Core 平台,并完美集成于 Visual Studio 的第三方控件集,包含 300 多种 .NET开发控件,提供表格数据管理、数据可视化、报表和文档、日程安排、输入和编辑、导航和布局、系统提升工具等七大功能,被誉为“.NET开发的‘瑞士军刀’”。

ComponentOne 为您提供专业的产品咨询服务,并由技术支持工程师为您1对1解答。>> 发帖提问

相关产品
推荐相关案例
关注微信
葡萄城社区二维码

关注“葡萄城社区”

加微信获取技术资讯

加微信获取技术资讯

想了解更多信息,请联系我们, 随时掌握技术资源和产品动态