WEB开发网
开发学院软件开发C语言 C# WinForm下DataGridView单元按钮列 阅读

C# WinForm下DataGridView单元按钮列

 2009-07-01 07:07:41 来源:WEB开发网   
核心提示: 主要是要实现DataGridViewDisableCheckBoxCell的呈现方式,其中设置了CheckBoxState的状态为MixedDisabled,C# WinForm下DataGridView单元按钮列(2),表示支持三种状态,这个是实现效果的核心

主要是要实现DataGridViewDisableCheckBoxCell的呈现方式,其中设置了CheckBoxState的状态为MixedDisabled,表示支持三种状态,这个是实现效果的核心,如果要实现RadioButton列的效果,只需要将Paint方法改成下面这样即可:

    protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex,
DataGridViewElementStates elementState, object value, object formattedValue, string errorText,
DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
    {
        // Draw the cell background, if specified.
        if ((paintParts & DataGridViewPaintParts.Background) == DataGridViewPaintParts.Background)
        {
            SolidBrush cellBackground = new SolidBrush(cellStyle.BackColor);
            graphics.FillRectangle(cellBackground, cellBounds);
            cellBackground.Dispose();
        }

        // Draw the cell borders, if specified.
        if ((paintParts & DataGridViewPaintParts.Border) == DataGridViewPaintParts.Border)
        {
            PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
        }

        // Calculate the area in which to draw the checkBox.
        RadioButtonState state = value != null && (SelectedStatus)value == SelectedStatus.Selected ? RadioButtonState.CheckedNormal : RadioButtonState.UncheckedNormal;
        Size size = RadioButtonRenderer.GetGlyphSize(graphics, state);
        Point center = new Point(cellBounds.X, cellBounds.Y);
        center.X += (cellBounds.Width - size.Width) / 2;
        center.Y += (cellBounds.Height - size.Height) / 2;

        // Draw the disabled checkBox.
        RadioButtonRenderer.DrawRadioButton(graphics, center, state);
    }

上一页  1 2 3 4  下一页

Tags:WinForm DataGridView 单元

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接