拉個RibbonControl

在某個Page裡放個Group

然後接者我們要動態在Group裡產生RibbonGalleryBarItem

假設這個Group命名為mySkin

只要在主要的程式呼叫下面的InitSkinGallery()就好啦

最好是放在建構子的InitializeComponent();下面

 

public void InitSkinGallery()

{

            RibbonGalleryBarItem rgbiSkins = new RibbonGalleryBarItem(ribbonControl1.Manager);

 

            GalleryItemGroup itemGroup1 = new GalleryItemGroup();

 

            itemGroup1.Caption = "Main";

 

            rgbiSkins.Gallery.Groups.Add(itemGroup1);

 

            SimpleButton imageButton = new SimpleButton();

 

            //將你目前有的Skin都讀進來

            foreach (SkinContainer cnt in SkinManager.Default.Skins)

            {

                imageButton.LookAndFeel.SetSkinStyle(cnt.SkinName);

                GalleryItem gItem = new GalleryItem();

                int groupIndex = 0;

                rgbiSkins.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;

               

            }

            rgbiSkins.Gallery.AllowHoverImages = true;

 

            rgbiSkins.Gallery.FixedHoverImageSize = false;

 

            rgbiSkins.Gallery.ItemClick += new DevExpress.XtraBars.Ribbon.GalleryItemClickEventHandler(rgbiSkins_Gallery_ItemClick);

 

            ribbonControl1.Pages[0].Groups["mySkin"].ItemLinks.Add(rgbiSkins);

           

}

 

 

 public 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 rgbiSkins_Gallery_ItemClick(object sender, DevExpress.XtraBars.Ribbon.GalleryItemClickEventArgs e)

{

            //按下去按鈕後就更換Skin了

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

}

 

 

 

下面補上要用到的NameSpace(我全部貼上了,有的沒用到,懶的分=.=)

 

 

using DevExpress.XtraEditors;

using DevExpress.XtraGrid.Views.Layout;

using DevExpress.Skins;

using DevExpress.XtraBars.Ribbon;

using DevExpress.Utils.Drawing;

using DevExpress.XtraBars;

 

 

arrow
arrow
    全站熱搜

    welkingunther 發表在 痞客邦 留言(0) 人氣()