ContextMenu cm = new ContextMenu();
FarPoint.Win.Spread.DrawingSpace.EllipseShape el = new FarPoint.Win.Spread.DrawingSpace.EllipseShape();
public Form1()
{
// 〜記述略〜
el.MouseDown += new MouseEventHandler(el_MouseDown);
}
private void Form1_Load(object sender, System.EventArgs e)
{
//コンテキストメニューを作成します
cm.MenuItems.Add("ロック", new System.EventHandler(this.LockMethod));
cm.MenuItems.Add("背景色を赤", new System.EventHandler(this.ColorMethod));
//Ellipseシェイプを追加します
el.Name = "Ellipse-01";
el.BackColor = Color.LightYellow;
el.SetBounds(10, 30, 120, 120);
fpSpread1.ActiveSheet.AddShape(el);
}
private void LockMethod(object sender, System.EventArgs e)
{
//ロック処理を記述します
}
private void ColorMethod(object sender, System.EventArgs e)
{
//背景色変更処理を記述します
}
private void el_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (fpSpread1.ActiveWindowlessObject != null && e.Button == MouseButtons.Right)
{
//独自のコンテキストメニューを設定します
fpSpread1.ContextMenu = cm;
}
else
{
fpSpread1.ContextMenu = null;
}
}
private void fpSpread1_CellClick(object sender, FarPoint.Win.Spread.CellClickEventArgs e)
{
//シェイプの選択解除(セルクリック)のタイミングでコンテキストメニューをクリアします
fpSpread1.ContextMenu = null;
}
Dim cm As New ContextMenu
Dim WithEvents El As New FarPoint.Win.Spread.DrawingSpace.EllipseShape
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
'コンテキストメニューを作成します
cm.MenuItems.Add("ロック", New System.EventHandler(AddressOf LockMethod))
cm.MenuItems.Add("背景色を赤", New System.EventHandler(AddressOf ColorMethod))
'Ellipseシェイプを追加します
El.Name = "Ellipse-01"
El.BackColor = Color.LightYellow
El.SetBounds(10, 30, 120, 120)
FpSpread1.ActiveSheet.AddShape(El)
End Sub
Private Sub LockMethod(ByVal sender As Object, ByVal e As System.EventArgs)
'ロック処理を記述します
End Sub
Private Sub ColorMethod(ByVal sender As Object, ByVal e As System.EventArgs)
'背景色変更処理を記述します
End Sub
Private Sub El_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles El.MouseDown
If Not (FpSpread1.ActiveWindowlessObject Is Nothing) And e.Button = MouseButtons.Right Then
'独自のコンテキストメニューを設定します
FpSpread1.ContextMenu = cm
Else
FpSpread1.ContextMenu = Nothing
End If
End Sub
Private Sub FpSpread1_CellClick(ByVal sender As Object, ByVal e As FarPoint.Win.Spread.CellClickEventArgs) Handles FpSpread1.CellClick
'シェイプの選択解除(セルクリック)のタイミングでコンテキストメニューをクリアします
FpSpread1.ContextMenu = Nothing
End Sub