drawgrid画图之后图像闪动很严重,求指点
时间:2011-08-29
来源:互联网
我用drawgrid学习制作一个表格工具,意图是通过拖拽工具栏里的人物一寸照片进入表格中可以实现动态排班的效果。
但是制作出来我发现了一个不知道怎么解决的情况就是,例如,我在表格第4列第一行拖入一个头像照片后,图像都剧烈的闪动。
我是基于五子棋程序的思想建立的,底层建立一个矩阵来控制drawgrid的,我检查了一下,发现矩阵的赋值没有任何问题。
请教delphi大师帮忙诊断一下会是哪里出了问题
private
Code:Array[0..16,0..5] of integer;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Bmp1:TBitMap;
Bmp2:TBitMap;
Bmp3:TBitMap;
Bmp4:TBitMap;
D:integer;
row:integer;
col:integer;
implementation
uses Unit2;
......
procedure TForm1.DrawGrid1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
Accept:=True;
drawgrid1.MouseToCell(x,y,col,row);
statusBar1.Panels[1].Text:='col='+inttostr(col);
statusBar1.Panels[0].Text:='row='+inttostr(row);
end;
procedure TForm1.DrawGrid1DragDrop(Sender, Source: TObject; X, Y: Integer);
var
i,j:integer;
begin
if(Sender Is TDrawgrid) and (Source Is TSpeedbutton ) then
begin
drawgrid1.MouseToCell(x,y,col,row);
Code[row,col]:=D;
Drawgrid1.OnDrawCell:= DrawGrid1DrawCell;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i,j: integer;
begin
D:=0;
for i:=1 to 16 do
for j:=1 to 5 do
begin
Code[i,j]:=0;
end;
Drawgrid1.OnDrawCell:= DrawGrid1DrawCell;
end;
procedure TForm1.SpeedButton1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if Button = mbLeft then
(Sender As TSpeedButton).BeginDrag(False);
D:=1;
end;
procedure TForm1.DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
I:Integer;
begin
Bmp1:= SpeedButton1.Glyph;
Bmp2:= Form2.SpeedButton2.Glyph;
Bmp3:= Form2.SpeedButton3.Glyph;
Bmp4:= Form2.SpeedButton4.Glyph;
with (Sender as TDrawGrid) do
begin
Drawgrid1.ColWidths[0]:=20; //第一列大小
For I:= 1 to 17 do //第一列行序号
begin
if (ACol = 0)and(ARow = i) then
Drawgrid1.Canvas.TextOut(Rect.Left+1, Rect.Top+14, IntToStr(ARow))
end;
//第一行列标题
if (ACol = 1)and(ARow = 0) then
Drawgrid1.Canvas.TextOut(Rect.Left+27, Rect.Top+14, 'A')
else if (ACol = 2)and(ARow = 0) then
Drawgrid1.Canvas.TextOut(Rect.Left+27, Rect.Top+14, 'B')
else if (ACol = 3)and(ARow = 0) then
Drawgrid1.Canvas.TextOut(Rect.Left+27, Rect.Top+14, 'C')
else if (ACol = 4)and(ARow = 0) then
Drawgrid1.Canvas.TextOut(Rect.Left+27, Rect.Top+14, 'D')
else if (ACol = 5)and(ARow = 0) then
Drawgrid1.Canvas.TextOut(Rect.Left+27, Rect.Top+14, 'E')
else if (code[acol,arow]=0)and(ACol <> 0)and(ARow <> 0) then
Drawgrid1.Invalidate //清空
else if (code[acol,arow]=1)and(ACol <> 0)and(ARow <> 0) then //成型
Drawgrid1.Canvas.Draw(Rect.Left+10,Rect.Top,Bmp1)
else if (code[acol,arow]=2)and(ACol <> 0)and(ARow <> 0) then
Drawgrid1.Canvas.Draw(Rect.Left+10,Rect.Top,Bmp2)
else if (code[acol,arow]=3)and(ACol <> 0)and(ARow <> 0) then
Drawgrid1.Canvas.Draw(Rect.Left+10,Rect.Top,Bmp3)
else if (code[acol,arow]=4)and(ACol <> 0)and(ARow <> 0) then
Drawgrid1.Canvas.Draw(Rect.Left+10,Rect.Top,Bmp4)
end;
end;
end.
但是制作出来我发现了一个不知道怎么解决的情况就是,例如,我在表格第4列第一行拖入一个头像照片后,图像都剧烈的闪动。
我是基于五子棋程序的思想建立的,底层建立一个矩阵来控制drawgrid的,我检查了一下,发现矩阵的赋值没有任何问题。
请教delphi大师帮忙诊断一下会是哪里出了问题
private
Code:Array[0..16,0..5] of integer;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Bmp1:TBitMap;
Bmp2:TBitMap;
Bmp3:TBitMap;
Bmp4:TBitMap;
D:integer;
row:integer;
col:integer;
implementation
uses Unit2;
......
procedure TForm1.DrawGrid1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
Accept:=True;
drawgrid1.MouseToCell(x,y,col,row);
statusBar1.Panels[1].Text:='col='+inttostr(col);
statusBar1.Panels[0].Text:='row='+inttostr(row);
end;
procedure TForm1.DrawGrid1DragDrop(Sender, Source: TObject; X, Y: Integer);
var
i,j:integer;
begin
if(Sender Is TDrawgrid) and (Source Is TSpeedbutton ) then
begin
drawgrid1.MouseToCell(x,y,col,row);
Code[row,col]:=D;
Drawgrid1.OnDrawCell:= DrawGrid1DrawCell;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i,j: integer;
begin
D:=0;
for i:=1 to 16 do
for j:=1 to 5 do
begin
Code[i,j]:=0;
end;
Drawgrid1.OnDrawCell:= DrawGrid1DrawCell;
end;
procedure TForm1.SpeedButton1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if Button = mbLeft then
(Sender As TSpeedButton).BeginDrag(False);
D:=1;
end;
procedure TForm1.DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
I:Integer;
begin
Bmp1:= SpeedButton1.Glyph;
Bmp2:= Form2.SpeedButton2.Glyph;
Bmp3:= Form2.SpeedButton3.Glyph;
Bmp4:= Form2.SpeedButton4.Glyph;
with (Sender as TDrawGrid) do
begin
Drawgrid1.ColWidths[0]:=20; //第一列大小
For I:= 1 to 17 do //第一列行序号
begin
if (ACol = 0)and(ARow = i) then
Drawgrid1.Canvas.TextOut(Rect.Left+1, Rect.Top+14, IntToStr(ARow))
end;
//第一行列标题
if (ACol = 1)and(ARow = 0) then
Drawgrid1.Canvas.TextOut(Rect.Left+27, Rect.Top+14, 'A')
else if (ACol = 2)and(ARow = 0) then
Drawgrid1.Canvas.TextOut(Rect.Left+27, Rect.Top+14, 'B')
else if (ACol = 3)and(ARow = 0) then
Drawgrid1.Canvas.TextOut(Rect.Left+27, Rect.Top+14, 'C')
else if (ACol = 4)and(ARow = 0) then
Drawgrid1.Canvas.TextOut(Rect.Left+27, Rect.Top+14, 'D')
else if (ACol = 5)and(ARow = 0) then
Drawgrid1.Canvas.TextOut(Rect.Left+27, Rect.Top+14, 'E')
else if (code[acol,arow]=0)and(ACol <> 0)and(ARow <> 0) then
Drawgrid1.Invalidate //清空
else if (code[acol,arow]=1)and(ACol <> 0)and(ARow <> 0) then //成型
Drawgrid1.Canvas.Draw(Rect.Left+10,Rect.Top,Bmp1)
else if (code[acol,arow]=2)and(ACol <> 0)and(ARow <> 0) then
Drawgrid1.Canvas.Draw(Rect.Left+10,Rect.Top,Bmp2)
else if (code[acol,arow]=3)and(ACol <> 0)and(ARow <> 0) then
Drawgrid1.Canvas.Draw(Rect.Left+10,Rect.Top,Bmp3)
else if (code[acol,arow]=4)and(ACol <> 0)and(ARow <> 0) then
Drawgrid1.Canvas.Draw(Rect.Left+10,Rect.Top,Bmp4)
end;
end;
end.
作者: kalelshey 发布时间: 2011-08-29
闪烁产生一般都是刷新背景造成的。
你可以建立一个大的TBitmap对象,把你的图先画在TBitmap上面, 然后就bitblt到你显示的Canvas上面,就可以避免图像闪烁的问题。不要直接在显示的Canvas对象上直接画图。
用Drawgrid的话,处理游戏一类的情况还是不太合用的。
你可以建立一个大的TBitmap对象,把你的图先画在TBitmap上面, 然后就bitblt到你显示的Canvas上面,就可以避免图像闪烁的问题。不要直接在显示的Canvas对象上直接画图。
用Drawgrid的话,处理游戏一类的情况还是不太合用的。
作者: robotdeng 发布时间: 2011-09-26
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28