我在网上下了一个表格类,但发现这个类在批量加数据时有时会重绘失败变成一个大红叉,现在想加多一个功能就是增加一个属性来控制是否让这个表格重绘,在网上查了一个有人说只截取所有的重绘消息就行了,但我是菜鸟可不可以具体一点给点代码,谢谢大侠们了!
解决方案 »
- 哪里有.net的rapi下载?
- 资源的释放
- OA网络办公系统文档管理
- 请教在DataGridView中怎样生成自适应的列宽?
- 关于DataGridView自定义按钮列的问题
- "未能启用约束。一行或多行中包含违反非空、唯一或外键约束的值。"
- 怎么判断一个控件是鼠标或是键盘让其获得焦点的
- 点击tabcontrol中的tabpage第一次显示的时候发生什么事件,为什么没有show的事件呢。
- C# 运用windows自带的API,将AVI视频拆分为BMP图片,求指点
- 为啥我项目的所有页面都运行不了了,全部是404!刚才还好好!
- 请教一个datagridview单元格CellValidating验证的问题
- 20090811新手求助?
richTextBox1.Text = "123";
richTextBox1.Select(0, 1);
richTextBox1.SelectionColor = Color.Red;
richTextBox1.Clear();//清除文本,包括样式
//或richTextBox1.Text="";
richTextBox1.Text = "abc";
richTextBox1.Text = "efg";
这样重置后的文本颜色就会是黑色.【关键字着色】public partial class RichTextBox : Form
...{
public RichTextBox()
...{
InitializeComponent();
} private void tSql_TextChanged(object sender, EventArgs e) //文本框改变事件
...{
int index = this.tSql.SelectionStart; //记录修改的位置
this.tSql.SelectAll();
this.tSql.SelectionColor = Color.Black;
string[] keystr =...{ "select ", "from ", "where ", " and ", " or ", " order ", " by ", " desc ", " when ", " case ",
" then ", " end ", " on ", " in ", " is ", " else ", " left ", " join ", " not ", " null " };
for (int i = 0; i < keystr.Length; i )
this.getbunch(keystr[i], this.tSql.Text); this.tSql.Select(index, 0); //返回修改的位置
this.tSql.SelectionColor = Color.Black; }
public int getbunch(string p, string s) //给关键字上色
...{
int cnt = 0; int M = p.Length; int N = s.Length;
char[] ss = s.ToCharArray(), pp = p.ToCharArray();
if (M > N) return 0;
for (int i = 0; i < N - M 1; i )
{
int j;
for (j = 0; j < M; j )
...{
if (ss[i j] != pp[j]) break;
}
if (j == p.Length)
...{
this.tSql.Select(i, p.Length);
this.tSql.SelectionColor = Color.Blue;
cnt ;
}
}
return cnt; } }
【绘制颜色提议】最好的做法是继承RichTextBox,重载新类的Paint方法。 并且在设置SelectionLength的时候,禁止控件的重绘过程,这样才不会出现被语法高亮的文本有一个突然选中的过程。 以下2个方法将会对你解决这一问题有很大的帮助.
[DllImport("user32")]
private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, IntPtr lParam);
private const int WM_SETREDRAW = 0xB; //停止控件的重绘
private void BeginPaint()
{
SendMessage(yourRichTextBox.Handle, WM_SETREDRAW, 0, IntPtr.Zero);
} //允许控件重绘.
private void EndPaint()
{
SendMessage(yourRichTextBox.Handle, WM_SETREDRAW, 1, IntPtr.Zero);
yourRichTextBox.Refresh();
}
[DllImport("user32")]
private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, IntPtr lParam);
private const int WM_SETREDRAW = 0xB; //停止控件的重绘
private void BeginPaint()
{
SendMessage(yourRichTextBox.Handle, WM_SETREDRAW, 0, IntPtr.Zero);
} //允许控件重绘.
private void EndPaint()
{
SendMessage(yourRichTextBox.Handle, WM_SETREDRAW, 1, IntPtr.Zero);
yourRichTextBox.Refresh();
}
Const WM_SETREDRAW As Integer = &H10 '0xB
Private Sub MyBase_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
If NoDrawGrid = True Then '不重绘控件
SendMessage(MyBase.Handle.ToInt32, WM_SETREDRAW, 0, IntPtr.Zero.ToInt32)
End If End Sub