如何改变DataGridView中的winform复选框大小 [英] how to change checkbox size in datagridview winform

查看:1675
本文介绍了如何改变DataGridView中的winform复选框大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能修改复选框的尺寸在DataGridViewCheckBoxCell [NOT单元格的大小] 我使用.NET 3.5

How I can change the size of the checkbox in the DataGridViewCheckBoxCell [NOT the size of the cell] I am using .net 3.5

推荐答案

我想你想改变这种状况被画insice细胞的复选框正方形的大小。 如果多数民众赞成的情况下,我怀疑有可能不是一个很简单的办法,但你可以通过acheive风俗画的图像,而不是选中,未框的结果。这里有一个提示如何工作的了.. 将两个图像(你想要的大小,因为它是对你很重要的大小),其中包含您的datagridview窗体上的图像列表。 (两幅图像当然会对应选中/未选中复选框视觉) 处理DataGridView中的CellPainting事件这样写:

I think you want to change the size of the square that's drawn insice the cell for a checkbox. If thats the case I suspect there might not be a very easy solution to it, but you can acheive the results by custom painting images instead of the "Checked", "Unchecked" boxes. Here's a hint how to work that out.. Add two images (of the size you want since its the size that's important to you) in an imagelist on the form which contains your datagridview. (The two images will of course correspond to the Checked/Unchecked checkbox visual) Handle "CellPainting" event of the DataGridView and write something like this:

if (e.ColumnIndex == 0 && e.RowIndex >= 0)//Assuming the checkbox is in Column 0
        {
            e.PaintBackground(e.ClipBounds, false);
            int index = 0;//Unchecked image
            if (e.Value != null && (bool)e.Value == true)
                index = 1;//Checked image
                e.Graphics.DrawImageUnscaled(imageList1.Images[index], e.CellBounds.X + 5, e.CellBounds.Y + 5);

            e.Handled = true;
        }

在单元格现在为了得到选中/取消选中的图像,所有你需要做的是设置在CellClick事件的底层数据源的值(这是如果你想,当细胞上的复选框被选中用户点击,如果只有那么这可能不需要它的读)

Now in order to get checked/unchecked image in the cell all you need to do is set the value of the underlying datasource on the CellClick event (this is if you want that when user clicks on the cell the checkbox gets checked, if its read only then this might not be required)

注:我不知道,如果我们能得到一个更好的解决方案比这个,请稍候,看看是否有人有一个美好的想法

NOTE: I am not sure if we can get a more elegant solution than this, please wait to see if someone has a brighter idea.

这篇关于如何改变DataGridView中的winform复选框大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆