关于DEV皮肤的换肤 也是系统风格的代码 C#

来源:互联网 发布:js 代码整理 编辑:程序博客网 时间:2024/06/05 08:17
 

DEV中的系统风格

Add PageGroup ->Add ribbonGalleryBarItem-> Add GalleryGroup

首先在设计窗口加上defaultLookAndFeel1控件

引用有:

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Linq;

using System.IO;

using System.Windows.Forms;

using DevExpress.XtraBars;

 

using ESRI.ArcGIS.Display;

using ESRI.ArcGIS.Carto;

using ESRI.ArcGIS.Geometry;

using ESRI.ArcGIS.esriSystem;

using ESRI.ArcGIS.Controls;

using ESRI.ArcGIS.SystemUI;

using ESRI.ArcGIS.Output;

using DevExpress.XtraEditors;

using DevExpress.Skins;

using DevExpress.XtraBars.Ribbon;

using DevExpress.Utils.Drawing;

(加上这些肯定够 但其中也有别的功能)

 

在RibbonForm1.Designer.cs中加上:(有定义就不用加了)

private DevExpress.XtraBars.BarSubItem iPaintStyle;

private DevExpress.XtraBars.RibbonGalleryBarItem ribbonGalleryBarItem1;

private DevExpress.LookAndFeel.DefaultLookAndFeel defaultLookAndFeel1;

 

在private void InitializeComponent()中加上

this.iPaintStyle = new DevExpress.XtraBars.BarSubItem();

//

            // iPaintStyle

            //

            this.iPaintStyle.Caption = "Paint style";

            this.iPaintStyle.Description = "Select a paint scheme";

            this.iPaintStyle.Hint = "Select a paint scheme";

            this.iPaintStyle.Id = 7;

            this.iPaintStyle.ImageIndex = 26;

            this.iPaintStyle.Name = "iPaintStyle";

            this.iPaintStyle.Popup += new System.EventHandler(this.iPaintStyle_Popup);

 

 

 

 

还有一句  this.iPaintStyle,加在          

 // ribbon

 //

 

在Form1.CS中加入

namespace Test//请注意这里是命名空间  自己的程序自己的命名

{

public partial class RibbonForm1 : DevExpress.XtraBars.Ribbon.RibbonForm

    {

       // private DevExpress.LookAndFeel.DefaultLookAndFeel defaultLookAndFeel1;(前面有的就不需要这句了)

        public RibbonForm1()

        {

            InitializeComponent();

            InitSkinGallery();

        }

 

        void InitSkinGallery()

        {

            SimpleButton imageButton = new SimpleButton();

            foreach (SkinContainer cnt in SkinManager.Default.Skins)

            {

                imageButton.LookAndFeel.SetSkinStyle(cnt.SkinName);

                GalleryItem gItem = new GalleryItem();

                int groupIndex = 0;

                if (cnt.SkinName.IndexOf("Office") > -1) groupIndex = 1;

                ribbonGalleryBarItem1.Gallery.Groups[groupIndex].Items.Add(gItem);

                gItem.Caption = cnt.SkinName;

 

                gItem.Image = GetSkinImage(imageButton, 32, 17, 2);

                gItem.HoverImage = GetSkinImage(imageButton, 70, 36, 5);

                gItem.Caption = cnt.SkinName;

                gItem.Hint = cnt.SkinName;

                ribbonGalleryBarItem1.Gallery.Groups[1].Visible = false;

            }

        }

        Bitmap GetSkinImage(SimpleButton button, int width, int height, int indent)

        {

            Bitmap image = new Bitmap(width, height);

            using (Graphics g = Graphics.FromImage(image))

            {

                StyleObjectInfoArgs info = new StyleObjectInfoArgs(new GraphicsCache(g));

                info.Bounds = new Rectangle(0, 0, width, height);

                button.LookAndFeel.Painter.GroupPanel.DrawObject(info);

                button.LookAndFeel.Painter.Border.DrawObject(info);

                info.Bounds = new Rectangle(indent, indent, width - indent * 2, height - indent * 2);

                button.LookAndFeel.Painter.Button.DrawObject(info);

            }

            return image;

        }

        private void iPaintStyle_Popup(object sender, System.EventArgs e)

        {

            foreach (BarItemLink link in iPaintStyle.ItemLinks)

                ((BarCheckItem)link.Item).Checked = link.Item.Caption == defaultLookAndFeel1.LookAndFeel.ActiveSkinName;

        }

 

 

 

        private void RibbonForm1_Load(object sender, EventArgs e)

        {

            // 设置绑定控件

            axTOCControl1.SetBuddyControl(axMapControl1);(这是绑定控件的在系统风格中不需要这句)

           foreach (DevExpress.Skins.SkinContainer skin in DevExpress.Skins.SkinManager.Default.Skins)

            {

                BarCheckItem item = ribbon.Items.CreateCheckItem(skin.SkinName, false);

                item.Tag = skin.SkinName;

                item.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(OnPaintStyleClick);

                iPaintStyle.ItemLinks.Add(item);

            }

 

           

        }

        void OnPaintStyleClick(object sender, ItemClickEventArgs e)

        {

            defaultLookAndFeel1.LookAndFeel.SetSkinStyle(e.Item.Tag.ToString());

 

        }

}

}

 

再加两个事件 ribbonGalleryBarItem1_Gallery_InitDropDownGallery(InitDropDownGallery事件)

ribbonGalleryBarItem1_Gallery_ItemClick(ItemClick事件)

请注意 两个事件在属性事件中是挨着的都在(倒数第二和倒数第三个事件)

 

 

 

 

        private void ribbonGalleryBarItem1_Gallery_InitDropDownGallery(object sender, InplaceGalleryEventArgs e)

        {

            e.PopupGallery.CreateFrom(ribbonGalleryBarItem1.Gallery);

            e.PopupGallery.AllowFilter = false;

            e.PopupGallery.ShowItemText = true;

            e.PopupGallery.ShowGroupCaption = true;

            e.PopupGallery.AllowHoverImages = false;

            foreach (GalleryItemGroup galleryGroup in e.PopupGallery.Groups)

                foreach (GalleryItem item in galleryGroup.Items)

                    item.Image = item.HoverImage;

            e.PopupGallery.ColumnCount = 2;

            e.PopupGallery.ImageSize = new Size(70, 36);

        }

 

        private void ribbonGalleryBarItem1_Gallery_ItemClick(object sender, GalleryItemClickEventArgs e)

        {

            DevExpress.LookAndFeel.UserLookAndFeel.Default.SetSkinStyle(e.Item.Caption);

        }

原创粉丝点击