MESCIUS SPREAD for ASP.NET 10.0J
コマンドボタンのカスタマイズ

MESCIUS SPREAD for ASP.NET 10.0J > 開発者の手引き > コマンドバー > コマンドボタンのカスタマイズ

コマンドボタンは、ボタンのタイプを設定でき、また表示画像や文字列のカスタマイズも可能です。

コマンドバーに表示するボタンのタイプは、CommandBarInfo クラスButtonType プロパティを使用して設定できます。 ButtonType プロパティは、ButtonType 列挙型で、以下の設定が可能です。

ボタンタイプ ButtonType列挙体 既定の表示
イメージ(アイコン) ImageButton

イメージ

テキストリンク LinkButton

テキスト リンク

プッシュボタン PushButton

プッシュボタン

LinkButtonは、FpSpread クラスEnableClientScript プロパティがfalseに設定されている場合のみ有効です。

ButtonType プロパティがImageButtonのときの既存のイメージを変更するには、fp_client フォルダのイメージサブディレクトリ内のイメージを置き換えるか、CreateButton イベント のイベントパラメータである、CreateButtonEventArgs クラスのプロパティを使用して設定します。

また、PushButtonやLinkButtonの表示文字もCreateButton イベントのパラメータを使用して変更できます。特定のボタンのみ非表示にすることも可能です。

サンプルコード

次のサンプルコードは、シート0がアクティブのときはイメージボタンの画像を、シート1がアクティブのときは、プッシュボタンのテキストを変更する例です。

protected void FpSpread1_CreateButton(object sender, CreateButtonEventArgs e)
{
    if (FpSpread1.ActiveSheetViewIndex == 0)
    {
        FpSpread1.CommandBar.ButtonType = FarPoint.Web.Spread.ButtonType.ImageButton;
        if (e.Command == "Update")
        {
            e.EnabledImgUrl = "~/image/update.png";
            e.DisabledImgUrl = "~/image/disabledUpdate.png";
        }
        else if (e.Command == "Cancel")
        {
            e.EnabledImgUrl = "~/image/cancel.png";
            e.DisabledImgUrl = "~/image/desabledCancel.png";
        }
    }
    else if(FpSpread1.ActiveSheetViewIndex == 1)
    {
        FpSpread1.CommandBar.ButtonType = FarPoint.Web.Spread.ButtonType.PushButton;
        if (e.Command == "Cut")
        {
            e.Label = "カット";
        }
        else if(e.Command == "Paste")
        {
            e.Label = "ペースト";
        }
    }
}       
Protected Sub FpSpread1_CreateButton(ByVal sender As Object, ByVal e As FarPoint.Web.Spread.CreateButtonEventArgs) Handles FpSpread1.CreateButton
    If FpSpread1.ActiveSheetViewIndex = 0 Then
        FpSpread1.CommandBar.ButtonType = FarPoint.Web.Spread.ButtonType.ImageButton
        
        If e.Command = "Update" Then
            e.EnabledImgUrl = "~/image/update.png"
            e.DisabledImgUrl = "~/image/disabledUpdate.png"
        ElseIf e.Command = "Cancel" Then
            e.EnabledImgUrl = "~/image/cancel.png"
            e.DisabledImgUrl = "~/image/desabledCancel.png"
            End If
    ElseIf FpSpread1.ActiveSheetViewIndex = 1 Then
        FpSpread1.CommandBar.ButtonType = FarPoint.Web.Spread.ButtonType.PushButton
        
        If e.Command = "Cut" Then
            e.Label = "カット"
        ElseIf e.Command = "Paste" Then
            e.Label = "ペースト"
        End If
    End If
End Sub

特定のボタンを非表示にすることも可能です。CreateButton イベントのイベントパラメータのVisible プロパティを使用します。

サンプルコード

次のサンプルコードは、下図のように印刷ボタンを非表示にします。

private void FpSpread1_CreateButton(object sender, FarPoint.Web.Spread.CreateButtonEventArgs e)
{
    if (e.Command == "Print")
    {
        e.Visible = false;
    }
}
Private Sub FpSpread1CreateButton(ByVal sender As Object, ByVal e As FarPoint.Web.Spread.CreateButtonEventArgs) Handles FpSpread1.CreateButton
    If e.Command = "Print" Then
        e.Visible = False
    End If
End Sub
関連トピック