如何在Windows窗体中设置XtraUserControl上的皮肤?

时间:2015-03-25 03:57:01

标签: c# devexpress-windows-ui

我有一个简单的Windows窗体。在其中,我嵌入了一个源自XtraUserControl(DevEx v10.1)的ChildXtraUserControl。

我想用'Office 2010 Blue'为ChildXtraUserControl设置皮肤,我希望在运行表单时它看起来很蓝。我已经尝试过这两种不同的方式,但我无法让它发挥作用。

尝试1:在ChildXtraUserControl中设置LookAndFeel,将ChildXtraUserControl设置为Windows窗体面板,格式为

当我运行时,我只看到面板,我将其涂成浅黄色。

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        var devExUserControl = new DevExpressUserControl {Dock = DockStyle.Fill};
        panel1.Controls.Add(devExUserControl);
    }
}

public partial class ChildXtraUserControl : XtraUserControl
{
    public ChildXtraUserControl()
    {
        InitializeComponent();
        IntializeSkin();
    }

    private void IntializeSkin()
    {
        LookAndFeel.UseDefaultLookAndFeel = false;
        LookAndFeel.UseWindowsXPTheme = false;
        LookAndFeel.Style = LookAndFeelStyle.Skin;
        LookAndFeel.SkinName = "Office 2010 Blue";
    }
}

尝试2:我读了on the DevEx Support Center,ChildXtraUserControl可能在DevExpress PanelControl中,而且LookConndFeel在PanelControl上设置

和以前一样,我只看到淡黄色的PanelControl。这个帖子确实看起来像是针对不同的DevEx版本,但我认为值得一试。

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        panelControl1.LookAndFeel.UseDefaultLookAndFeel = false;
        panelControl1.LookAndFeel.UseWindowsXPTheme = false;
        panelControl1.LookAndFeel.Style = LookAndFeelStyle.Skin;
        panelControl1.LookAndFeel.SkinName = "Office 2010 Blue";

        var devExUserControl = new ChildXtraUserControl { Dock = DockStyle.Fill };
        panelControl1.Controls.Add(devExUserControl);
    }
}

public partial class ChildXtraUserControl : XtraUserControl
{
    public ChildXtraUserControl()
    {
        InitializeComponent();
    }
}

有没有人有任何想法我做错了什么?提前谢谢。

1 个答案:

答案 0 :(得分:1)

我设法通过使用第二种方法并修改Form1构造函数来实现这一点。如图所示。

    public Form1()
    {
        InitializeComponent();

        // add this line
        DevExpress.UserSkins.OfficeSkins.Register();

        panelControl1.LookAndFeel.UseDefaultLookAndFeel = false;
        panelControl1.LookAndFeel.UseWindowsXPTheme = false;
        panelControl1.LookAndFeel.Style = LookAndFeelStyle.Skin;
        panelControl1.LookAndFeel.SkinName = "Office 2010 Blue";

        var childXtraUserControl = new ChildXtraUserControl {Dock = DockStyle.Fill};
        panelControl1.Controls.Add(childXtraUserControl);
    }