PowerTools SPREAD for Windows Forms 8.0J
コンテキストメニュー

コンテキストメニューを作成して、FpSpreadクラスのContextMenuプロパティに追加できます。コントロールを右クリックすると、状況に適したメニューオプションを表すコンテキストメニューが自動的に表示されるようになります。

次の図は、2つのオプションから成るコンテキストメニューを表示しています。

コンテキストメニューの表示

デフォルトでは、コントロールはスクロールバーにも固有のコンテキストメニューを装備しています。

サンプルコード

次のサンプルコードは、上図のコンテキストメニューを設定します。

C#
コードのコピー
private void Form1_Load(object sender, System.EventArgs e)
{
    ContextMenu custommenu = new ContextMenu();
    custommenu.MenuItems.Add("&Table");
    custommenu.MenuItems.Add("&Color", new EventHandler(ContextMenu_Color);
    fpSpread1.ContextMenu = custommenu;
}
private void ContextMenu_Color(object sender, System.EventArgs e)
{
    MessageBox.Show("You chose color.");
}
Visual Basic
コードのコピー
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim custommenu As New ContextMenu
    custommenu.MenuItems.Add("&Table")
    custommenu.MenuItems.Add("&Color", New EventHandler(AddressOf ContextMenu_Color))
    FpSpread1.ContextMenu = custommenu
End Sub
Private Sub ContextMenu_Color(ByVal sender As Object, ByVal e As System.EventArgs)
    MsgBox("You chose color.")
End Sub
設計時にツールボックスからコンテキストメニューをドロップし、これによって生成されたコードを見ると、コーディングの詳細を確認できます。
関連トピック

 

 


© 2004-2015, GrapeCity inc. All rights reserved.