「DevExpress.XtraEditors.ColorPickEdit」のポップアップ画面をリボンメニューで表示させる

「ColorPickEdit」のポップアップ画面をリボンメニューで表示させる場合のメモ

「ColorPickEdit」のポップアップ画面は、DevExpressのデザインメニューに定義されていません、なので、「ColorPickEdit」のポップアップ画面を利用するには裏技が必要になります。

「ColorPickEdit」のポップアップ画面は、「ColorPickEdit」の他にも、「DevExpress」の様々な昨日で使われています。今回はそれを利用してリボンメニューに再利用します。

今回は、「DevExpress.XtraSpreadsheet.UI」のクラスを使います。「DevExpress.XtraSpreadsheet.UI」は「DevExpress」でExcelのようなスプレッドシートを作成するのに使う機能です。

1.「ChangeCellFillColorItem」ボタンを準備

任意のリボンフォームに、「DevExpress.XtraSpreadsheet.UI.ChangeCellFillColorItem」ボタンのクラスを生成し、リボンメニューに追加する。
「ChangeCellFillColorItem」はデザイナーには表示されないため、手動で記述する。

以下、記述例です。

namespace ImportTool
{
    partial class TestForm
    {
        private void InitializeComponent()
        {
            this.changeCellFillColorItem1 = new DevExpress.XtraSpreadsheet.UI.ChangeCellFillColorItem();
            // 
            // changeCellFillColorItem1
            // 
            this.changeCellFillColorItem1.Caption = "塗りつぶし";
            this.changeCellFillColorItem1.Id = 1;
            this.changeCellFillColorItem1.ImageOptions.Image = ((System.Drawing.Image)(resources.GetObject("changeCellFillColorItem1.ImageOptions.Image")));
            this.changeCellFillColorItem1.ImageOptions.LargeImage = ((System.Drawing.Image)(resources.GetObject("changeCellFillColorItem1.ImageOptions.LargeImage")));
            this.changeCellFillColorItem1.Name = "changeCellFillColorItem1";
            this.changeCellFillColorItem1.RibbonStyle = DevExpress.XtraBars.Ribbon.RibbonItemStyles.Large;
            // 
            // ribbonPage1
            // 
            this.ribbonPage1.Groups.AddRange(new DevExpress.XtraBars.Ribbon.RibbonPageGroup[] {
            this.ribbonPageGroup1});
            this.ribbonPage1.Name = "ribbonPage1";
            this.ribbonPage1.Text = "ホーム";
            // 
            // ribbonPageGroup1
            // 
            this.ribbonPageGroup1.ItemLinks.Add(this.changeCellFillColorItem1);
            this.ribbonPageGroup1.Name = "ribbonPageGroup1";
            this.ribbonPageGroup1.Text = "スタイル編集";
        }

        #endregion
        private DevExpress.XtraSpreadsheet.UI.ChangeCellFillColorItem changeCellFillColorItem1;
    }
}

2.ボタンの編集

デザイナー画面で、ボタン画像を編集し、任意のリボンメニューに追加する。

3.イベントの追加

「ChangeCellFillColorItem」では、通常のクリックイベントでは、データ取得できないので、「ChangeCellFillColorItem」の
ポップアップ画面に対してイベントをフックする。

以下、記述例です。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraBars;

namespace ImportTool
{
    public partial class TestForm : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        public TestForm()
        {
            InitializeComponent();
        }
        private void TestForm_Load(object sender, EventArgs e)
        {
            this.changeCellFillColorItem1.SelectedColor = Color.Red;
            this.changeCellFillColorItem1.DropDownControl.Popup += DropDownControl_Popup;
        }
        private void DropDownControl_Popup(object sender, EventArgs e)
        {
            var col = this.changeCellFillColorItem1.SelectedColor;
        }
    }
}

以下、処理イメージです。

ポップアップで選択した画面に、ボタンの色が変更されています。

シェアする

  • このエントリーをはてなブックマークに追加

フォローする