stringgrid开始设置属性goAlwaysShowEditor时,光标移入另一个控件,如edit1中,则第一行第一列原来设置的标题居中,粗体效果失去。
请问此种情况如何处理呢?
6 个解决方案
#1
响应OnDrawCell
#2
这个问题在大富翁里解决了
#3
谁来领分啊
#4
正巧路过,不过楼主应该把方法帖出来共享一下。
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if gdSelected in State then
begin
with StringGrid1.Canvas do
begin
Brush.Color:=clwindow;
FillRect(Rect);
end;
end
end;
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if gdSelected in State then
begin
with StringGrid1.Canvas do
begin
Brush.Color:=clwindow;
FillRect(Rect);
end;
end
end;
#5
问题是内容也没了
怎么解决啊?
怎么解决啊?
#6
rzStringGrid1.Canvas.Font.Assign(rzStringGrid1.Font);//这一句可以放到Form的OnCreate里
with rzStringGrid1.Canvas do begin
Brush.Color := clWindow;
Font.Color := clWindowText;
if gdFixed in State then Brush.Color := rzStringGrid1.FixedColor;
if (gdSelected in State) and rzStringGrid1.Focused then begin//关键!如果StringGrid失去焦点就不加亮显示
Brush.Color := clHighLight;
Font.Color := clHighLightText;
end;
FillRect(Rect);
with rzStringGrid1 do TextRect(Rect, Rect.Left + 2, Rect.Top + 2, Cells[ACol, ARow]);
if gdFixed in State then DrawEdge(Handle, Rect, BDR_RAISEDINNER, BF_RECT);
if gdFocused in State then DrawFocusRect(Rect);
end;
with rzStringGrid1.Canvas do begin
Brush.Color := clWindow;
Font.Color := clWindowText;
if gdFixed in State then Brush.Color := rzStringGrid1.FixedColor;
if (gdSelected in State) and rzStringGrid1.Focused then begin//关键!如果StringGrid失去焦点就不加亮显示
Brush.Color := clHighLight;
Font.Color := clHighLightText;
end;
FillRect(Rect);
with rzStringGrid1 do TextRect(Rect, Rect.Left + 2, Rect.Top + 2, Cells[ACol, ARow]);
if gdFixed in State then DrawEdge(Handle, Rect, BDR_RAISEDINNER, BF_RECT);
if gdFocused in State then DrawFocusRect(Rect);
end;
#1
响应OnDrawCell
#2
这个问题在大富翁里解决了
#3
谁来领分啊
#4
正巧路过,不过楼主应该把方法帖出来共享一下。
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if gdSelected in State then
begin
with StringGrid1.Canvas do
begin
Brush.Color:=clwindow;
FillRect(Rect);
end;
end
end;
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if gdSelected in State then
begin
with StringGrid1.Canvas do
begin
Brush.Color:=clwindow;
FillRect(Rect);
end;
end
end;
#5
问题是内容也没了
怎么解决啊?
怎么解决啊?
#6
rzStringGrid1.Canvas.Font.Assign(rzStringGrid1.Font);//这一句可以放到Form的OnCreate里
with rzStringGrid1.Canvas do begin
Brush.Color := clWindow;
Font.Color := clWindowText;
if gdFixed in State then Brush.Color := rzStringGrid1.FixedColor;
if (gdSelected in State) and rzStringGrid1.Focused then begin//关键!如果StringGrid失去焦点就不加亮显示
Brush.Color := clHighLight;
Font.Color := clHighLightText;
end;
FillRect(Rect);
with rzStringGrid1 do TextRect(Rect, Rect.Left + 2, Rect.Top + 2, Cells[ACol, ARow]);
if gdFixed in State then DrawEdge(Handle, Rect, BDR_RAISEDINNER, BF_RECT);
if gdFocused in State then DrawFocusRect(Rect);
end;
with rzStringGrid1.Canvas do begin
Brush.Color := clWindow;
Font.Color := clWindowText;
if gdFixed in State then Brush.Color := rzStringGrid1.FixedColor;
if (gdSelected in State) and rzStringGrid1.Focused then begin//关键!如果StringGrid失去焦点就不加亮显示
Brush.Color := clHighLight;
Font.Color := clHighLightText;
end;
FillRect(Rect);
with rzStringGrid1 do TextRect(Rect, Rect.Left + 2, Rect.Top + 2, Cells[ACol, ARow]);
if gdFixed in State then DrawEdge(Handle, Rect, BDR_RAISEDINNER, BF_RECT);
if gdFocused in State then DrawFocusRect(Rect);
end;