using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace KssSmaPlaLib.Forms.Controls { public class PoiDgv : DataGridView { private IContainer components; [Category("Poi拡張"), Description("共通メニューを自動で追加するかどうか")] public bool EnablePoiMenu { get; set; } = true; /// /// コンストラクタ /// public PoiDgv() { // これが今回の本命! this.DoubleBuffered = true; // DGB初期設定 this.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; this.RowHeadersVisible = false; this.SelectionMode = DataGridViewSelectionMode.FullRowSelect; this.AllowUserToAddRows = false; this.AllowUserToDeleteRows = false; this.AllowUserToOrderColumns = true; this.AllowUserToResizeColumns = true; this.AllowUserToResizeRows = false; this.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing; } /// /// コンテキストメニュー設定時 /// /// protected override void OnContextMenuStripChanged(EventArgs e) { base.OnContextMenuStripChanged(e); // ユーザーがデザイナーでセットしたメニューに「Poi」のスパイスを加える if (EnablePoiMenu && this.ContextMenuStrip != null) { var menu = this.ContextMenuStrip; //// 重複防止チェック //if (menu.Items.Find("poiItem_AutoFit", true).Length == 0) //{ // if (menu.Items.Count > 0) menu.Items.Add(new ToolStripSeparator()); // var fitItem = new ToolStripMenuItem("列幅をぽいっと自動調整"); // fitItem.Name = "poiItem_AutoFit"; // fitItem.Click += (s, ev) => this.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells); // menu.Items.Add(fitItem); //} } } private void InitializeComponent() { ((System.ComponentModel.ISupportInitialize)(this)).BeginInit(); this.SuspendLayout(); // // PoiDgv // this.RowTemplate.Height = 21; ((System.ComponentModel.ISupportInitialize)(this)).EndInit(); this.ResumeLayout(false); } } }