PowerTools MultiRow for Windows Forms 8.0J
Scope プロパティ (CellPaintingEventArgs)
使用例 

イベントが発生したセルの領域を取得します。
構文
Public ReadOnly Property Scope As CellScope
public CellScope Scope {get;}

プロパティ値

イベントが発生したセルの領域を表すCellScope値の1つ。
使用例
次のサンプルコードは、セルの描画ロジックをカスタマイズする方法を示します。このサンプルコードは、GcMultiRow.CellPaintingイベントに示されている詳細なコード例の一部を抜粋したものです。
void gcMultiRow_CellPainting(object sender, CellPaintingEventArgs e)
{
    if (e.CellIndex == 1 && e.Scope == CellScope.Row)
    {
        e.PaintBackground(e.ClipBounds);

        PaintRateBlock(e);

        e.PaintForeground(e.ClipBounds);

        e.PaintBorder(e.ClipBounds);

        // If you customize the paint logic, make sure, the Handled property should be set to true.
        e.Handled = true;
    }
}
private static void PaintRateBlock(CellPaintingEventArgs e)
{
    Color color1 = Color.Red;
    Color color2 = Color.Orange;
    if (e.Selected)
    {
        color1 = Color.Blue;
        color2 = Color.SkyBlue;
    }

    decimal rate = 0m;

    if (e.Value != null)
    {
        rate = (decimal)(e.Value) / 100m;
    }

    // Calculate block size.
    int spinButtonWidth = 17;
    int blockWidth = (int)((e.ClipBounds.Width - spinButtonWidth) * rate);

    if (blockWidth > 0)
    {
        Rectangle rect = e.CellBounds;

        rect.Width = blockWidth;

        LinearGradientBrush brush = new LinearGradientBrush(rect, color1, color2, LinearGradientMode.Vertical);

        e.Graphics.FillRectangle(brush, rect);
    }
}
Private Sub gcMultiRow_CellPainting(ByVal sender As Object, ByVal e As CellPaintingEventArgs) Handles gcMultiRow.CellPainting
    If e.CellIndex = 1 AndAlso e.Scope = CellScope.Row Then
        e.PaintBackground(e.ClipBounds)

        PaintRateBlock(e)

        e.PaintForeground(e.ClipBounds)

        e.PaintBorder(e.ClipBounds)

        ' If you customize the paint logic, make sure, the Handled property should be set to true.
        e.Handled = True
    End If
End Sub
Private Shared Sub PaintRateBlock(ByVal e As CellPaintingEventArgs)
    Dim color1 As Color = Color.Red
    Dim color2 As Color = Color.Orange
    If e.Selected Then
        color1 = Color.Blue
        color2 = Color.SkyBlue
    End If

    Dim rate As Decimal = 0D

    If e.Value <> Nothing Then
        rate = DirectCast((e.Value), Decimal) / 100D
    End If

    ' Calculate block size.
    Dim spinButtonWidth As Integer = 17
    Dim blockWidth As Integer = CInt((e.ClipBounds.Width - spinButtonWidth) * rate)

    If blockWidth > 0 Then
        Dim rect As Rectangle = e.CellBounds

        rect.Width = blockWidth

        Dim brush As New LinearGradientBrush(rect, color1, color2, LinearGradientMode.Vertical)

        e.Graphics.FillRectangle(brush, rect)
    End If
End Sub
参照

CellPaintingEventArgs クラス
CellPaintingEventArgs メンバ

 

 


© 2008-2015 GrapeCity inc. All rights reserved.