积极答复者
DataGridView中使用paint事件绘制直线,在滚动DataGridView中的数据时位置显示不固定!请教

问题
答案
-
private void dataGridView1_Scroll(object sender, ScrollEventArgs e)
{
dataGridView1.Invalidate();
}
http://feiyun0112.cnblogs.com/- 已建议为答案 Riquel_DongModerator 2009年7月6日 2:17
- 已标记为答案 Riquel_DongModerator 2009年7月6日 8:05
全部回复
-
你好,
能够给出你的代码让我重现你是如何处理Paint事件来绘制直线的。同时看下这个控件(这是一个第三方控件,不是微软的产品,只是给你参考,我们不支持关于这个产品使用中的问题)是否满足你的需要:
http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvb/thread/92432cb1-3872-40dd-80fa-e45731add30b/
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. -
你好,谢谢你关注我的问题
我的代码其实很简单
int pageRows=21;
int pageHeight=0;
int pageWidth=0;
Font font=new Font ("宋体",72.0f);
StringFormat sf=new StringFormat ();
sf.Alignment =StringAlignment.Center ;
sf.LineAlignment =StringAlignment .Center ;DataGridView dgv=(DataGridView )sender ;
for (int i = 0; i < pageRows; i++)
pageHeight += dgv.Rows[i].Height;
for (int j=0;j<dgv.Columns .Count ;j++)
pageWidth +=dgv.Columns [j ].Width ;
RectangleF rectF=new RectangleF (0f,0f,(float )pageWidth ,(float )pageHeight );
e.Graphics.DrawString("第"+page.ToString ()+"页",font ,Brushes.Gray ,rectF ,sf );
Pen dashPen = new Pen(Color.Blue ,2.0f);
dashPen.DashStyle = DashStyle.Dash;
e.Graphics.DrawLine(dashPen ,0f,(float)pageHeight,(float )dgv.Width,(float )pageHeight);
但是它不能很好的工作
刚启动后显示正常,滚动后就不正常了
最开心的是今天有收获。 -
private void dataGridView1_Scroll(object sender, ScrollEventArgs e)
{
dataGridView1.Invalidate();
}
http://feiyun0112.cnblogs.com/- 已建议为答案 Riquel_DongModerator 2009年7月6日 2:17
- 已标记为答案 Riquel_DongModerator 2009年7月6日 8:05