首页 新闻 搜索 专区 学院

更改winform皮肤?

0
[已关闭问题]

我用的VS2005,会把皮肤加载上,就是把IrisSkin2.dll和皮肤文件放到项目的Debug文件夹下,拖到工具箱上,再把工具箱上的皮肤拖到Form里,然后在窗体的构造方法中写上:skinEngine1.SkinFile = 皮肤文件名;就可以了,但是我做了个下拉菜单,想一选就能改变正在运行中的程序的皮肤,不知道应该怎么弄啊,我能在改变下拉菜单事件里得到相对的皮肤文件名,然后怎么办啊? 给我个思路估计就行。。我在改变下拉菜单的事件中把登录的窗口重新实例了,然后再把那个文件名用构造方法传参导到skinEngine1.SkinFile = 皮肤文件名里,但是不行,一触发下拉菜单改变事件就会变回没有皮肤的样子。

问题补充: 1楼的朋友谢谢你的回答,但是我新手,看不懂啊,你的程序我都不会运行,一步一步的告诉下我怎么做,把这段代码解释下吧,我看不懂啊,试也试不出来,我就看懂一句了: string skinName = listBox1.SelectedItem.ToString();取得listBox1里所选的值。别的都没看懂。。。
天气预报的主页 天气预报 | 初学一级 | 园豆:200
提问于:2009-07-04 10:35
< >
分享
其他回答(1)
0
Code


Demo

winzheng | 园豆:8797 (大侠五级) | 2009-07-04 12:21
0

//TestSkin命令空间,别忘了改成你自己的。


namespace TestSkin


{


    class SkinClass


    {


        public static Sunisoft.IrisSkin.SkinEngine se = null;


        /// <summary>


        /// 增加换肤菜单


        /// </summary>


        /// <param name= "toolMenu "> </param>


        public static void AddSkinMenu(ToolStripMenuItem toolMenu)


        {


            DataSet skin = new DataSet();


            try


            {

 


                skin.ReadXml("skin.xml ", XmlReadMode.Auto);


            }


            catch


            {

 


            }


            if (skin == null || skin.Tables.Count < 1)


            {


                skin = new DataSet();


                skin.Tables.Add("skin ");


                skin.Tables["skin "].Columns.Add("style ");


                System.Data.DataRow dr = skin.Tables["skin "].NewRow();


                dr[0] = "系统默认 ";


                skin.Tables[0].Rows.Add(dr);


                skin.WriteXml("skin.xml ", XmlWriteMode.IgnoreSchema);


            }


            foreach (SkinType st in (SkinType[])System.Enum.GetValues(typeof(SkinType)))


            {


                toolMenu.DropDownItems.Add(new ToolStripMenuItem(st.ToString()));

 


                toolMenu.DropDownItems[toolMenu.DropDownItems.Count - 1].Click +=


                    new EventHandler(frm_Main_Click);


                if (st.ToString() == skin.Tables[0].Rows[0][0].ToString())


                {


                    ((ToolStripMenuItem)toolMenu.DropDownItems[


                        toolMenu.DropDownItems.Count - 1]).Checked = true;


                    frm_Main_Click(toolMenu.DropDownItems[


                        toolMenu.DropDownItems.Count - 1], null);

 


                }

 


            }

 


            toolMenu.DropDownItems.Add(new ToolStripMenuItem("系统默认 "));


            toolMenu.DropDownItems[toolMenu.DropDownItems.Count - 1].Click +=


                new EventHandler(frm_Main_Click);


            if (skin.Tables[0].Rows[0][0].ToString() == "系统默认 ")


            {


                ((ToolStripMenuItem)toolMenu.DropDownItems[toolMenu.DropDownItems.Count -


                    1]).Checked = true;


            }


        }


        static void frm_Main_Click(object sender, EventArgs e)


        {

 


            for (int i = 0; i < ((ToolStripMenuItem)(


                (ToolStripMenuItem)sender).OwnerItem).DropDownItems.Count; i++)


            {


                if (((ToolStripMenuItem)sender).Text == ((ToolStripMenuItem)(


                    (ToolStripMenuItem)sender).OwnerItem).DropDownItems[i].Text)


                {


                    ((ToolStripMenuItem)sender).CheckState = CheckState.Checked;


                    DataSet skin = new DataSet();


                    skin.Tables.Add("skin ");


                    skin.Tables["skin "].Columns.Add("style ");


                    System.Data.DataRow dr = skin.Tables["skin "].NewRow();


                    dr[0] =


                        ((ToolStripMenuItem)((ToolStripMenuItem)sender).OwnerItem).DropDownItems[i].Text;


                    skin.Tables[0].Rows.Add(dr);


                    skin.WriteXml("skin.xml ", XmlWriteMode.IgnoreSchema);

 


                }


                else


                {


                    ((ToolStripMenuItem)((ToolStripMenuItem)(


                        (ToolStripMenuItem)sender).OwnerItem).DropDownItems[i]).CheckState =


                        CheckState.Unchecked;


                }


            }


            if (((ToolStripMenuItem)sender).Text == "系统默认 ")


            {


                RemoveSkin();


                DataSet skin = new DataSet();


                skin.Tables.Add("skin ");


                skin.Tables["skin "].Columns.Add("style ");


                System.Data.DataRow dr = skin.Tables["skin "].NewRow();


                dr[0] = "系统默认 ";


                skin.Tables[0].Rows.Add(dr);


                skin.WriteXml("skin.xml ", XmlWriteMode.IgnoreSchema);


                return;


            }


            foreach (SkinType st in (SkinType[])System.Enum.GetValues(typeof(SkinType)))


            {


                if (st.ToString() == ((ToolStripMenuItem)sender).Text)


                {


                    ChangeSkin(st);


                    return;


                }


            }


        }


        /// <summary>


        /// 改变皮肤


        /// </summary>


        /// <param name= "st "> </param>


        public static void ChangeSkin(SkinType st)


        {


            System.Reflection.Assembly thisDll =


                System.Reflection.Assembly.GetExecutingAssembly();


            if (se == null)


            {


                //TestSkin是指命名空间,这里你可以换成你自己的。


                se = new Sunisoft.IrisSkin.SkinEngine(Application.OpenForms[0],


                    thisDll.GetManifestResourceStream("TestSkin.skin. " +


                    st.ToString() + ".ssk "));


                se.Active = true;


                for (int i = 0; i < Application.OpenForms.Count; i++)


                {


                    se.AddForm(Application.OpenForms[i]);


                }

 


            }


            else


            {


                //TestSkin是指命名空间,这里你可以换成你自己的。


                se.SkinStream =


                    thisDll.GetManifestResourceStream("TestSkin.skin. " +


                    st.ToString() + ".ssk ");


                se.Active = true;


            }


        }


        /// <summary>


        /// 移除皮肤


        /// </summary>


        public static void RemoveSkin()


        {


            if (se == null)


            {


                return;


            }


            else


            {


                se.Active = false;


            }


        }


    }


    /// <summary>


    /// 换肤类型


    /// </summary>


    public enum SkinType


    {


        Calmness,


        DeepCyan,


        Eighteen,


        Emerald,


        GlassBrown,


        Longhorn,


        MacOS,


        Midsummer,


        MP10,


        MSN,


        OneBlue,


        Page,


        RealOne,


        Silver,


        SportsBlack,


        SteelBlack,


        vista1,


        Vista2,


        Warm,


        Wave,


        XPSilver


    }


}

奥邦创新 | 园豆:202 (菜鸟二级) | 2012-10-27 14:08
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册