既にデフォルトの contextMenuStrip を持つコントロールにカスタマイズする contextMenuStrip を追加します。
コードスニペット :
DBDisplay imageControl = new DBDisplay(); // This is third-party object
imageControl.ContextMenuStrip = this.contextMenuStripTableLayout;
ただし、デフォルトの contextMenu は新しい contextMenu に変更されました。デフォルト + 新しい contextMenu を使用したいと思います。ヒントやヘルプはありますか?
ありがとうグラント。もう1つ質問があります。
更新された編集
List<DBDisplay> m_pImage = new List<DBDisplay>();
for (int i = 0; i < 10; i++)
{
DBDisplay imageControl = new DBDisplay();
imageControl.Location = new System.Drawing.Point(0, 0);
imageControl.Dock = System.Windows.Forms.DockStyle.Fill;
imageControl.Size = new Size(columnWidth, rowHeight);
foreach (ToolStripItem tsItem in contextMenuStripTableLayout.Items)
imageControl.ContextMenuStrip.Items.Add(tsItem);
m_pImage.Add(imageControl);
}
int index = 0;
for (int i = 0; i < columnCount; i++)
{
//First add a column
tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, columnWidth));
for (int j = 0; j < rowCount; j++)
{
if (i == 0)
{
//defining the size of cell
tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, rowHeight));
}
tableLayoutPanel1.Controls.Add(m_pImage[index], i, j);
index++;
}
}
もう1つ質問があります。上記のコードを使用すると、imageControl contextMenuStrip は 10 回繰り返されます。この問題を解決するにはどうすればよいですか?
更新 基本的に、m_pImage リストは tableLayoutPanel1 コントロールに追加されます。各列と行の contextmenustrip を使用します。アプローチするのは正しいですか?
Update2 OK、ここに詳細なソース コードがあります。DBDisplay は DBCogDisplay です。
using System.ComponentModel;
using System.Windows.Forms;
using Cognex.VisionPro.Display;
namespace DBSubClass
{
public partial class DBCogDisplay : Cognex.VisionPro.Display.CogDisplay
{
public DBCogDisplay()
{
InitializeComponent();
SetLayoutSettings();
SetStyleSettings();
}
public DBCogDisplay(IContainer container)
{
container.Add(this);
InitializeComponent();
SetLayoutSettings();
SetStyleSettings();
}
private void SetLayoutSettings()
{
base.AllowDrop = true;
base.Dock = System.Windows.Forms.DockStyle.Fill;
base.Location = new System.Drawing.Point(0, 0);
base.MouseWheelMode = CogDisplayMouseWheelModeConstants.Zoom1;
base.ContextMenuStrip.AllowMerge = true;
}
private void SetStyleSettings()
{
base.DoubleBuffered = true;
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.ResizeRedraw, true);
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
UpdateStyles();
}
}
}
CogDisplay クラスのオブジェクトの説明です。 http://www.hyperbook.com/cognex/vpro/ja/Cognex.VisionPro.Display.CogDisplay.html