如何从 Delphi DBGrid OnTitleClick 事件中删除黑线?
我有一个 Delphi DBGrid,第一次加载时看起来很正常。我设置了一个 OnTitleClick 事件,当单击标题时,该事件按列对 DBGrid 进行排序。一旦您单击标题,列标题就像按下按钮一样,并出现一条丑陋的黑线。 (参见下图2)
单击事件完成后,网格看起来又恢复正常了。
当您单击列标题时,如何防止出现这条黑线?
编辑:QC 提交给 Embarcadero
虽然关闭调整列大小的功能确实会使黑线行为消失确实剥夺了一个非常好的功能。我认为这种行为需要得到纠正。我已向 Embarcadero 提交了以下QC 98255。请为此条目投票。
更新:2017-07-30
我找到了这条水平黑线的绘制位置。
Vcl.Grids > 过程 TCustomGrid.DrawMove;
Canvas.Pen.Width 设置为 5。我将其更改为 Canvas.Pen.Width := 1;
看起来好多了。现在,当我单击“Contact_Last”标题单元格时,黑色指示线只有一个像素宽,而且干扰少得多。
procedure TCustomGrid.DrawMove;
var
OldPen: TPen;
Pos: Integer;
R: TRect;
begin
OldPen := TPen.Create;
try
with Canvas do
begin
OldPen.Assign(Pen);
try
Pen.Style := psDot;
Pen.Mode := pmXor;
//+----------------------------------------------------------------+
// Modified 2017-07-30 by Michael J Riley (MJR)
// Changed Pen.Width from 5 to 1
// This makes the vertical black move-indicator line 1 pixel wide
// Which is the same width as column resize vertical line
//+----------------------------------------------------------------+
//Pen.Width := 5;
Pen.Width := 1;
if FGridState = gsRowMoving then
begin
R := CellRect(0, FMovePos);
if FMovePos > FMoveIndex then
Pos := R.Bottom else
Pos := R.Top;
MoveTo(0, Pos);
LineTo(ClientWidth, Pos);
end
else
begin
R := CellRect(FMovePos, 0);
if FMovePos > FMoveIndex then
if not UseRightToLeftAlignment then
Pos := R.Right
else
Pos := R.Left
else
if not UseRightToLeftAlignment then
Pos := R.Left
else
Pos := R.Right;
MoveTo(Pos, 0);
LineTo(Pos, ClientHeight);
end;
finally
Canvas.Pen := OldPen;
end;
end;
finally
OldPen.Free;
end;
end;
I have a Delphi DBGrid that looks normal when it first loads. I have setup an OnTitleClick event that sorts the DBGrid by the column when the title is clicked. As soon as you click on the title, the column title acts like a button being pressed and an ugly black line appears. (See Fig. 2 below)
As soon as the click event is done, the grid looks normal again.
How do you prevent this black line from appearing when you click the column title?
EDIT: QC Submitted to Embarcadero
While turning off the ability to resize columns does make the black line behavior disappear it does take away a very nice feature. I think this behavior needs to be fixed. I have submitted the following QC 98255 to Embarcadero. Please vote for this entry.
UPDATE: 2017-07-30
I found where this horizontal black line is being drawn.
Vcl.Grids > procedure TCustomGrid.DrawMove;
The Canvas.Pen.Width is set to 5. I changed it so the Canvas.Pen.Width := 1;
It looks much so much better. Now when I clicked on the "Contact_Last" title cell the black indicator line is just one pixel wide and much less intrusive.
procedure TCustomGrid.DrawMove;
var
OldPen: TPen;
Pos: Integer;
R: TRect;
begin
OldPen := TPen.Create;
try
with Canvas do
begin
OldPen.Assign(Pen);
try
Pen.Style := psDot;
Pen.Mode := pmXor;
//+----------------------------------------------------------------+
// Modified 2017-07-30 by Michael J Riley (MJR)
// Changed Pen.Width from 5 to 1
// This makes the vertical black move-indicator line 1 pixel wide
// Which is the same width as column resize vertical line
//+----------------------------------------------------------------+
//Pen.Width := 5;
Pen.Width := 1;
if FGridState = gsRowMoving then
begin
R := CellRect(0, FMovePos);
if FMovePos > FMoveIndex then
Pos := R.Bottom else
Pos := R.Top;
MoveTo(0, Pos);
LineTo(ClientWidth, Pos);
end
else
begin
R := CellRect(FMovePos, 0);
if FMovePos > FMoveIndex then
if not UseRightToLeftAlignment then
Pos := R.Right
else
Pos := R.Left
else
if not UseRightToLeftAlignment then
Pos := R.Left
else
Pos := R.Right;
MoveTo(Pos, 0);
LineTo(Pos, ClientHeight);
end;
finally
Canvas.Pen := OldPen;
end;
end;
finally
OldPen.Free;
end;
end;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
黑线看起来像一个列顺序插入标记。
尝试寻找禁用列重新排序的选项。
The black line looks like a column order insert marker.
Try looking for an option that disables column re-ordering.