serveru
serveru
posts - 2,  comments - 6,  trackbacks - 0

我的程序框架大概是这样的:
代码省略了很多

private void Form1_Load(object sender, System.EventArgs e)
{
    
//这里初始化Form1里的dataGrid1,风格是系统默认的。
    dataGrid1.DataSource = dt;
    
while(i<numCols)
   
{
    DataGridTextBoxColumn tbc 
= new DataGridTextBoxColumn();
    ts.GridColumnStyles.Add(tbc);
   }

   dataGrid1.TableStyles.Add(ts);
}

窗体里有个button1,它的事件是

private void button1_Click(object sender, System.EventArgs e)
{
   
//DataGridCellColorTextBoxColumn继承于DataGridTextBoxColumn,重写了Paint事件,另外它还加入了一个新的方法PaintCol,这个方法为了能重画单个单元格,代码在下面
   DataGridCellColorTextBoxColumn columnTextColumn ;
   
for(int i = 0; i < numCols; ++i)
   
{
     columnTextColumn 
= new DataGridCellColorTextBoxColumn();
     columnTextColumn.CheckCellColor 
+= new
 CellColorEventHandlerSetColorValues);
     tableStyle.GridColumnStyles.Add(columnTextColumn);
    }

    dataGrid1.TableStyles.Add(tableStyle);
    dataGrid1.DataSource 
= ds.Tables["Quote"];
}


public void PaintCol(Graphics g, Rectangle cellRect, CurrencyManager cm, int rowNum, 
Brush bBrush, Brush fBrush, 
bool isVisible)
   
{
    
this.Paint(g, cellRect, cm, rowNum, bBrush, fBrush, isVisible);
   }

 

窗体里有个button2,它的事件是

private void button2_Click(object sender, System.EventArgs e)
{
   
//通过调用DataGridCellColorTextBoxColumn里的PaintCol方法重画七行七列的单元格的外观
 DataGridCellColorTextBoxColumn tbc =
(DataGridCellColorTextBoxColumn)dgt.GridColumnStyles[
7];
 Graphics g 
= dataGrid1.CreateGraphics();
 Rectangle cellRect;
 cellRect
=dataGrid1.GetCellBounds(7,7);
 CurrencyManager cm 
=
(CurrencyManager)dataGrid1.BindingContext[ds.Tablesdgt.MappingName]];
   Brush fBrush 
= new System.Drawing.SolidBrush(Color.Red);
   Brush bBrush
= new System.Drawing.SolidBrush(Color.Black);
   tbc.PaintCol(g, cellRect, cm, 
7, bBrush, fBrush, false );
}


运行时先点button1,再点button2,则button2重画的单元格的风格会在窗体最小化和最
大化后变回button1执行后产生的风格。我现在的问题是就是怎样才能把button2产生的
风格一直保留下来?
谢谢

另外在实际应用过程中不是只通过button触发事件更改单元格的外观的
有可能根据某个事件来随时更改指定单元格的外观

还有谁能说说当窗口最小化后再最大化时 发生了什么事情?

posted on 2004-07-08 13:13 鬼七 阅读(1587) 评论(5) 编辑 收藏

FeedBack:
2004-07-08 15:23 | foo
挺好的,想知道 “同步器”是什么,有什么作用?
 回复 引用   
2004-07-10 01:53 | Ying-Shen
你好像没有设置TableStyle和ColumnStyle的MappingName?
TableStyle.MappingName应该是DataTable的名字
ColumnStyle的MappingName是Column的Name.

 回复 引用   
2004-07-10 01:54 | Ying-Shen
还有谁能说说当窗口最小化后再最大化时 发生了什么事情?

整个DataGrid重画了一遍。

 回复 引用   
2006-04-13 17:09 | 拉登·闸      
c#窗体有没有自动重画的功能?
即有没有类似于AUTOREDRAW的属性?

 回复 引用 查看   
2006-07-07 15:55 | yinwer[未注册用户]
DataGridCellColorTextBoxColumn会用当前的ColumnStyle重新paint一次datagrid,,,要保留button2里面的应该clear掉前面的style,重新构造一个style,paint上去
 回复 引用   
昵称:鬼七
园龄:7年10个月
粉丝:0
关注:0

<2004年7月>
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567

搜索

 
 

常用链接

随笔档案

文章分类

技术

积分与排名

  • 积分 - 2738
  • 排名 - 18086

最新评论