procedure TForm1.Button1Click(Sender: TObject);
var
mypanel:tpanel;
begin
mypanel:=tpanel.create(RzStringGrid1);
mypanel.Parent:=StringGrid1;
mypanel.Width:=180;
mypanel.caption:='yes';
mypanel.Top:=100;
mypanel.Left:=120;
mypanel.Height:=50;
end;
通过上述代码生成了panel之后,只要StringGrid的滚动条滚动后,就会出现如下图的情况。
如果我用mypanel.repaint,就会使mypanel.top和left乱掉,于是我在StringGrid1TopLeftChanged事件里控制滚动条滚动后mypanel的.top和left时,stringgrid上只有一两个panel时,效果还免强可以,但panel很多时,panel在改变top和left时就会看得到位置变动时的闪动。
求高手帮我解决。非常感谢。
var
mypanel:tpanel;
begin
mypanel:=tpanel.create(RzStringGrid1);
mypanel.Parent:=StringGrid1;
mypanel.Width:=180;
mypanel.caption:='yes';
mypanel.Top:=100;
mypanel.Left:=120;
mypanel.Height:=50;
end;
通过上述代码生成了panel之后,只要StringGrid的滚动条滚动后,就会出现如下图的情况。
如果我用mypanel.repaint,就会使mypanel.top和left乱掉,于是我在StringGrid1TopLeftChanged事件里控制滚动条滚动后mypanel的.top和left时,stringgrid上只有一两个panel时,效果还免强可以,但panel很多时,panel在改变top和left时就会看得到位置变动时的闪动。
求高手帮我解决。非常感谢。
解决方案 »
- 请问如何改鼠标在DBGRIDEH某列上的形状?
- 求教一个类似腾讯挂机积分的思路。
- 怎么解压缩unix下的.z文件?
- Delphi的Panel怎么随着窗体变化而变化呢?
- 菜鳥問題!
- 请问Delphi中有没有类似VB中的on ERROR goto 之类的错误捕获语句吗??(20分)在线等
- 我怎么对DB_GRID的某字段加一个汇总?
- 请指教:DBGRID 是否可以打印?(急!!!在线等待)
- 高分问Inno Setup两个问题:
- 如果有很多个客户端同时发数据,TldUDPServer控件的 OnUDPRead 事件怎么处理才能保证不丢包呀?
- webbrowser里怎么清除session
- 做了两个FORM,放入一个工程,但是run了一下很多错误
如果我用mypanel.repaint,就会使mypanel.top和left乱掉,于是我在StringGrid1TopLeftChanged事件里控制滚动条滚动后mypanel的.top和left时,stringgrid上只有一两个panel时,效果还免强可以,但panel很多时,panel在改变top和left时就会看得到位置变动时的闪动。
Rect: TRect; State: TGridDrawState);
begin
//根据行列限制panel的大小,可以改为一个区域的
if (ACol = 1) and (ARow = 1) then
begin
Panel1.SetBounds(Rect.Left,Rect.Top,rect.Right-rect.Left,Rect.Bottom-rect.Top);
end;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
Panel1.Parent := StringGrid1;
end;
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, Grids, RzGrids, StdCtrls;type
TForm1 = class(TForm)
grdTest: TRzStringGrid;
btnCreatePanel: TButton;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure btnCreatePanelClick(Sender: TObject);
procedure grdTestTopLeftChanged(Sender: TObject);
private
FPanelList: TList;
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementationtype
PRecPanel = ^TRecPanel;
TRecPanel = record
Panel : TPanel;
LeftCol: Integer;
TopRow : Integer;
end;{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
begin
FPanelList := TList.Create;
end;procedure TForm1.FormDestroy(Sender: TObject);
var
FData: PRecPanel;
begin
while FPanelList.Count > 0 do
begin
if Assigned(FPanelList.Items[0]) then
begin
FData := PRecPanel(FPanelList.Items[0]);
FData^.Panel.Free;
Dispose(FData);
end;
FPanelList.Delete(0);
end;
FPanelList.Free;
end;procedure TForm1.btnCreatePanelClick(Sender: TObject);
var
FData : PRecPanel;
FPanel: TPanel;
begin
FPanel := TPanel.Create(grdTest);
FPanel.Parent := grdTest;
FPanel.Caption := 'Panel ' + IntToStr(FPanelList.Count + 1);
FPanel.Left := 100;
FPanel.Top := 30;
FPanel.Width := 180;
FPanel.Height := 50;
New(FData);
FData^.Panel := FPanel;
FData^.LeftCol := grdTest.LeftCol;
FData^.TopRow := grdTest.TopRow;
FPanelList.Add(FData);
end;procedure TForm1.grdTestTopLeftChanged(Sender: TObject);
var
I : Integer;
FData: PRecPanel;
begin
LockWindowUpdate(grdTest.Handle);
try
for I:=0 to FPanelList.Count-1 do
begin
FData := PRecPanel(FPanelList.Items[I]);
FData^.Panel.Left := FData^.Panel.Left - (grdTest.LeftCol - FData^.LeftCol) * grdTest.DefaultColWidth;
FData^.Panel.Top := FData^.Panel.Top - (grdTest.TopRow - FData^.TopRow) * grdTest.DefaultRowHeight;
FData^.LeftCol := grdTest.LeftCol;
FData^.TopRow := grdTest.TopRow;
end;
grdTest.Invalidate;
finally
LockWindowUpdate(0);
end;
end;end.
因为第0行和第0列是做为title的,不能因为panel的滚动而被它覆盖。
如果可以使用DrawCell来绑定,就采用bdmh的方法,如果不能满足你的要求,就采用我的方法,最多就是再添加两个StringGrid作为标题栏和边栏就可以了,处理一下TopLeftChange的事件,让这两个假的标题栏和边栏同步滚动,直接就可以满足你的要求了。
代码:
procedure TForm1.FormCreate(Sender: TObject);
begin
Panel1.Parent:=RzStringGrid1;
end;procedure TForm1.RzStringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if (ACol = 1) and (ARow = 1) then
begin
Panel1.SetBounds(Rect.Left,Rect.Top,rect.Right-rect.Left,Rect.Bottom-rect.Top);
end;
end;效果:
StringGrid1.DoubleBuffered := True;
Rect: TRect; State: TGridDrawState);
begin
if (ACol = 2) and (ARow = 2) then
begin
Panel1.SetBounds(Rect.Left,Rect.Top,rect.Right-rect.Left,Rect.Bottom-rect.Top);
end;
if (StringGrid1.TopRow > 2) or (StringGrid1.LeftCol > 2) then
Panel1.Visible := False
else
Panel1.Visible := True;
end;