有在QQ问我怎么绘制边框,这里将分析框线部分完整贴出,占程序的 1/20,它分析一个格子 4 条边的
边框如何绘制,按挨首7468标准,菜鸟作品是没有注释的。这里没有使用技巧,全部都是普通代码,组
织起来实现一个巨繁复的算法。
许多人看了或者觉得没意思,或者看晕了,但控件就是这么做出来的,x,y 是待绘格子的坐标。
procedure CheckLine(X, Y: Integer);
var
D, E, F, T: Integer;
Loc: TRect;
LineStyle: Integer;
LineColor: TColor;
LineStyle1: Integer;
LineColor1: TColor;
LineStyle2: Integer;
LineColor2: TColor;
LineStyle3: Integer;
LineColor3: TColor;
LineStyle4: Integer;
LineColor4: TColor;
procedure GetLineStyles;
begin
LineStyle1 := CellInfos[X, Y].TopLineStyle;
LineColor1 := CellInfos[X, Y].TopLineColor;
if Y - 1 >= 0 then
if (FLineWidth[LineStyle1] < FLineWidth[CellInfos[X, Y - 1].BottomLineStyle])
or ((FLineWidth[LineStyle1] = FLineWidth[CellInfos[X, Y - 1].BottomLineStyle])
and (LineColor1 < CellInfos[X, Y - 1].BottomLineColor)) then
begin
LineStyle1 := CellInfos[X, Y - 1].BottomLineStyle;
LineColor1 := CellInfos[X, Y - 1].BottomLineColor;
end;
LineStyle2 := CellInfos[X, Y].LeftLineStyle;
LineColor2 := CellInfos[X, Y].LeftLineColor;
if X - 1 >= 0 then
if (FLineWidth[LineStyle2] < FLineWidth[CellInfos[X - 1, Y].RightLineStyle])
or ((FLineWidth[LineStyle2] = FLineWidth[CellInfos[X - 1, Y].RightLineStyle])
and (LineColor2 < CellInfos[X - 1, Y].RightLineColor)) then
begin
LineStyle2 := CellInfos[X - 1, Y].RightLineStyle;
LineColor2 := CellInfos[X - 1, Y].RightLineColor;
end;
if X - 1 >= 0 then
begin
LineStyle3 := CellInfos[X - 1, Y].TopLineStyle;
LineColor3 := CellInfos[X - 1, Y].TopLineColor;
end
else
begin
LineStyle3 := 0;
LineColor3 := 0;
end;
if (X - 1 >= 0) and (Y - 1 >= 0) then
if (FLineWidth[LineStyle3] < FLineWidth[CellInfos[X - 1, Y - 1].BottomLineStyle])
or ((FLineWidth[LineStyle3] = FLineWidth[CellInfos[X - 1, Y - 1].BottomLineStyle])
and (LineColor3 < CellInfos[X - 1, Y - 1].BottomLineColor)) then
begin
LineStyle3 := CellInfos[X - 1, Y - 1].BottomLineStyle;
LineColor3 := CellInfos[X - 1, Y - 1].BottomLineColor;
end;
if Y - 1 >= 0 then
begin
LineStyle4 := CellInfos[X, Y - 1].LeftLineStyle;
LineColor4 := CellInfos[X, Y - 1].LeftLineColor;
end
else
begin
LineStyle4 := 0;
LineColor4 := 0;
end;
if (X - 1 >= 0) and (Y - 1 >= 0) then
if (FLineWidth[LineStyle4] < FLineWidth[CellInfos[X - 1, Y - 1].RightLineStyle])
or ((FLineWidth[LineStyle4] = FLineWidth[CellInfos[X - 1, Y - 1].RightLineStyle])
and (LineColor4 < CellInfos[X - 1, Y - 1].RightLineColor)) then
begin
LineStyle4 := CellInfos[X - 1, Y - 1].RightLineStyle;
LineColor4 := CellInfos[X - 1, Y - 1].RightLineColor;
end;
if ExtCell then
begin
LineStyle2:=1;
LineColor2:=1;
LineStyle4:=1;
LineColor4:=1;
end;
end;
function DrawQuadrateCorner(AWidth: Integer): Boolean;
begin
result := False;
T := 0;
if FLineWidth[LineStyle1] = AWidth then
T := 1;
if FLineWidth[LineStyle2] = AWidth then
T := T + 2;
if FLineWidth[LineStyle3] = AWidth then
T := T + 4;
if FLineWidth[LineStyle4] = AWidth then
T := T + 8;
if (T <> 0) and (T <> 1) and (T <> 2) and (T <> 4) and (T <> 8) then
begin
Loc := EXBoxRect(X, Y, X, Y);
InflateRect(Loc, 1, 1);
Loc := Rect(Loc.Left - 1, Loc.Top - 1, Loc.Left + AWidth - 1, Loc.Top + AWidth - 1);
case T of
7: begin
if (LineColor2 = LineColor3) and (LineColor1 <> LineColor3) then
begin
LineStyle := LineStyle3;
LineColor := LineColor3;
Loc.Bottom := Loc.Top;
end
else
begin
LineStyle := LineStyle1;
LineColor := LineColor1;
Loc.Bottom := Loc.Top;
end;
end;
13: begin
if (LineColor3 = LineColor4) and (LineColor1 <> LineColor3) then
begin
LineStyle := LineStyle3;
LineColor := LineColor3;
Loc.Bottom := Loc.Top;
end
else
begin
LineStyle := LineStyle1;
LineColor := LineColor1;
Loc.Bottom := Loc.Top;
end;
end;
5:
begin
LineStyle := LineStyle1;
LineColor := LineColor1;
Loc.Bottom := Loc.Top;
end;
11:
begin
if (LineColor1 = LineColor4) and (LineColor2 <> LineColor4) then
begin
LineStyle := LineStyle4;
LineColor := LineColor4;
Loc.Right := Loc.Left;
end
else
begin
LineStyle := LineStyle2;
LineColor := LineColor2;
Loc.Right := Loc.Left;
end;
end;
14:
begin
if (LineColor3 = LineColor4) and (LineColor2 <> LineColor4) then
begin
LineStyle := LineStyle4;
LineColor := LineColor4;
Loc.Right := Loc.Left;
end
else
begin
LineStyle := LineStyle2;
LineColor := LineColor2;
Loc.Right := Loc.Left;
end;
end;
10:
begin
LineStyle := LineStyle2;
LineColor := LineColor2;
Loc.Right := Loc.Left;
end;
3: begin
E := 1;
if X + E < ColCount then
repeat
LineStyle := CellInfos[X + E, Y].TopLineStyle;
LineColor := CellInfos[X + E, Y].TopLineColor;
if FLineWidth[LineStyle] < FLineWidth[CellInfos[X + E, Y].BottomLineStyle] then
begin
LineStyle := CellInfos[X + E, Y].BottomLineStyle;
LineColor := CellInfos[X + E, Y].BottomLineColor;
end;
if FLineWidth[LineStyle] = FLineWidth[CellInfos[X + E, Y].BottomLineStyle] then
if LineColor < CellInfos[X + E, Y].BottomLineColor then
begin
LineStyle := CellInfos[X + E, Y].BottomLineStyle;
LineColor := CellInfos[X + E, Y].BottomLineColor;
end;
Inc(E);
until (X + E >= ColCount) or (FLineWidth[LineStyle] <> AWidth) or (LineColor1 <> LineColor);
F := 0;
repeat
LineStyle := CellInfos[X, Y + F].LeftLineStyle;
LineColor := CellInfos[X, Y + F].LeftLineColor;
if FLineWidth[LineStyle] < FLineWidth[CellInfos[X - 1, Y + F].RightLineStyle] then
begin
LineStyle := CellInfos[X - 1, Y + F].RightLineStyle;
LineColor := CellInfos[X - 1, Y + F].RightLineColor;
end;
if FLineWidth[LineStyle] = FLineWidth[CellInfos[X - 1, Y + F].RightLineStyle] then
if LineColor < CellInfos[X - 1, Y + F].RightLineColor then
begin
LineStyle := CellInfos[X - 1, Y + F].RightLineStyle;
LineColor := CellInfos[X - 1, Y + F].RightLineColor;
end;
Inc(F);
until (Y + F >= RowCount) or (FLineWidth[LineStyle] <> AWidth) or (LineColor2 <> LineColor);
D := 0;
if E > F then
D := 1
else
if E < F then
D := 2
else
if LineColor2 > LineColor1 then
D := 2
else
D := 1;
if FLineCorner[LineStyle1] and not FLineCorner[LineStyle2] then
begin
LineStyle := LineStyle2;
LineColor := LineColor2;
Loc.Right := Loc.Left;
end
else
if not FLineCorner[LineStyle1] and FLineCorner[LineStyle2] then
begin
LineStyle := LineStyle1;
LineColor := LineColor1;
Loc.Bottom := Loc.Top;
end
else
if D = 1 then
begin
LineStyle := LineStyle1;
LineColor := LineColor1;
Loc.Bottom := Loc.Top;
end
else
begin
LineStyle := LineStyle2;
LineColor := LineColor2;
Loc.Right := Loc.Left;
end;
end;
6: begin
E := 1;
if X - E > 0 then
begin
repeat
LineStyle := CellInfos[X - E, Y].TopLineStyle;
LineColor := CellInfos[X - E, Y].TopLineColor;
if FLineWidth[LineStyle] < FLineWidth[CellInfos[X - E, Y - 1].BottomLineStyle] then
begin
LineStyle := CellInfos[X - E, Y - 1].BottomLineStyle;
LineColor := CellInfos[X - E, Y - 1].BottomLineColor;
end;
if FLineWidth[LineStyle] = FLineWidth[CellInfos[X - E, Y - 1].BottomLineStyle] then
if LineColor < CellInfos[X - E, Y - 1].BottomLineColor then
begin
LineStyle := CellInfos[X - E, Y - 1].BottomLineStyle;
LineColor := CellInfos[X - E, Y - 1].BottomLineColor;
end;
Inc(E);
until (X - E <= 0) or (FLineWidth[LineStyle] <> AWidth) or (LineColor3 <> LineColor);
E := E - 2;
end;
F := 0;
repeat
LineStyle := CellInfos[X, Y + F].LeftLineStyle;
LineColor := CellInfos[X, Y + F].LeftLineColor;
if FLineWidth[LineStyle] < FLineWidth[CellInfos[X - 1, Y + F].RightLineStyle] then
begin
LineStyle := CellInfos[X - 1, Y + F].RightLineStyle;
LineColor := CellInfos[X - 1, Y + F].RightLineColor;
end;
if FLineWidth[LineStyle] = FLineWidth[CellInfos[X - 1, Y + F].RightLineStyle] then
if LineColor < CellInfos[X - 1, Y + F].RightLineColor then
begin
LineStyle := CellInfos[X - 1, Y + F].RightLineStyle;
LineColor := CellInfos[X - 1, Y + F].RightLineColor;
end;
Inc(F);
until (Y + F >= RowCount) or (FLineWidth[LineStyle] <> AWidth) or (LineColor2 <> LineColor);
D := 0;
if E > F - 1 then
D := 1
else
if E < F - 1 then
D := 2
else
if (X - 1 > 0) and (LineColor2 > LineColor3) then
D := 2
else
D := 1;
if FLineCorner[LineStyle2] and not FLineCorner[LineStyle3] then
begin
LineStyle := LineStyle3;
LineColor := LineColor3;
Loc.Bottom := Loc.Top;
end
else
if not FLineCorner[LineStyle2] and FLineCorner[LineStyle3] then
begin
LineStyle := LineStyle2;
LineColor := LineColor2;
Loc.Right := Loc.Left;
end
else
if (D = 1) or FLineCorner[LineStyle2] then
begin
LineStyle := LineStyle3;
LineColor := LineColor3;
Loc.Bottom := Loc.Top;
end
else
begin
LineStyle := LineStyle2;
LineColor := LineColor2;
Loc.Right := Loc.Left;
end;
end;
9: begin
E := 1;
if X + E < ColCount then
begin
repeat
LineStyle := CellInfos[X + E, Y].TopLineStyle;
LineColor := CellInfos[X + E, Y].TopLineColor;
if FLineWidth[LineStyle] < FLineWidth[CellInfos[X + E, Y - 1].BottomLineStyle] then
begin
LineStyle := CellInfos[X + E, Y - 1].BottomLineStyle;
LineColor := CellInfos[X + E, Y - 1].BottomLineColor;
end;
if FLineWidth[LineStyle] = FLineWidth[CellInfos[X + E, Y - 1].BottomLineStyle] then
if LineColor < CellInfos[X + E, Y - 1].BottomLineColor then
begin
LineStyle := CellInfos[X + E, Y - 1].BottomLineStyle;
LineColor := CellInfos[X + E, Y - 1].BottomLineColor;
end;
Inc(E);
until (X + E >= ColCount) or (FLineWidth[LineStyle] <> AWidth) or (LineColor1 <> LineColor);
E := E - 1;
end;
F := 1;
if Y - F > 0 then
begin
repeat
LineStyle := CellInfos[X, Y - F].LeftLineStyle;
LineColor := CellInfos[X, Y - F].LeftLineColor;
if FLineWidth[LineStyle] < FLineWidth[CellInfos[X, Y - F].LeftLineStyle] then
begin
LineStyle := CellInfos[X, Y - F].LeftLineStyle;
LineColor := CellInfos[X, Y - F].LeftLineColor;
end;
if FLineWidth[LineStyle] = FLineWidth[CellInfos[X, Y - F].LeftLineStyle] then
if LineColor < CellInfos[X, Y - F].LeftLineColor then
begin
LineStyle := CellInfos[X, Y - F].LeftLineStyle;
LineColor := CellInfos[X, Y - F].LeftLineColor;
end;
Inc(F);
until (Y - F <= 0) or (FLineWidth[LineStyle] <> AWidth) or (LineColor4 <> LineColor);
F := F - 2;
end;
D := 0;
if E > F then
D := 1
else
if E < F then
D := 2
else
if (X - 1 > 0) and (LineColor4 > LineColor1) then
D := 2
else
D := 1;
if FLineCorner[LineStyle1] and not FLineCorner[LineStyle4] then
begin
LineStyle := LineStyle4;
LineColor := LineColor4;
Loc.Right := Loc.Left;
end
else
if not FLineCorner[LineStyle1] and FLineCorner[LineStyle4] then
begin
LineStyle := LineStyle1;
LineColor := LineColor1;
Loc.Bottom := Loc.Top;
end
else
if (D = 1) or FLineCorner[LineStyle4] then
begin
LineStyle := LineStyle1;
LineColor := LineColor1;
Loc.Bottom := Loc.Top;
end
else
begin
LineStyle := LineStyle4;
LineColor := LineColor4;
Loc.Right := Loc.Left;
end;
end;
12: begin
E := 1;
if X - E > 0 then
begin
repeat
LineStyle := CellInfos[X - E, Y].TopLineStyle;
LineColor := CellInfos[X - E, Y].TopLineColor;
if FLineWidth[LineStyle] < FLineWidth[CellInfos[X - E, Y - 1].BottomLineStyle] then
begin
LineStyle := CellInfos[X - E, Y - 1].BottomLineStyle;
LineColor := CellInfos[X - E, Y - 1].BottomLineColor;
end;
if FLineWidth[LineStyle] = FLineWidth[CellInfos[X - E, Y - 1].BottomLineStyle] then
if LineColor < CellInfos[X - E, Y - 1].BottomLineColor then
begin
LineStyle := CellInfos[X - E, Y - 1].BottomLineStyle;
LineColor := CellInfos[X - E, Y - 1].BottomLineColor;
end;
Inc(E);
until (X - E <= 0) or (FLineWidth[LineStyle] <> AWidth) or (LineColor3 <> LineColor);
E := E - 2;
end;
F := 1;
if Y - F >= 0 then
begin
repeat
LineStyle := CellInfos[X, Y - F].LeftLineStyle;
LineColor := CellInfos[X, Y - F].LeftLineColor;
if FLineWidth[LineStyle] < FLineWidth[CellInfos[X - 1, Y - F].RightLineStyle] then
begin
LineStyle := CellInfos[X - 1, Y - F].RightLineStyle;
LineColor := CellInfos[X - 1, Y - F].RightLineColor;
end;
if FLineWidth[LineStyle] = FLineWidth[CellInfos[X - 1, Y - F].RightLineStyle] then
if LineColor < CellInfos[X - 1, Y - F].RightLineColor then
begin
LineStyle := CellInfos[X - 1, Y - F].RightLineStyle;
LineColor := CellInfos[X - 1, Y - F].RightLineColor;
end;
Inc(F);
until (Y - F >= RowCount) or (FLineWidth[LineStyle] <> AWidth) or (LineColor4 <> LineColor);
F := F - 2;
end;
D := 0;
if E > F then
D := 1
else
if E < F then
D := 2
else
if (X - 1 > 0) and (LineColor4 > LineColor3) then
D := 2
else
D := 1;
if FLineCorner[LineStyle3] and not FLineCorner[LineStyle4] then
begin
LineStyle := LineStyle4;
LineColor := LineColor4;
Loc.Right := Loc.Left;
end
else
if not FLineCorner[LineStyle3] and FLineCorner[LineStyle4] then
begin
LineStyle := LineStyle3;
LineColor := LineColor3;
Loc.Bottom := Loc.Top;
end
else
if (D = 1) or FLineCorner[LineStyle4] then
begin
LineStyle := LineStyle3;
LineColor := LineColor3;
Loc.Bottom := Loc.Top;
end
else
begin
LineStyle := LineStyle4;
LineColor := LineColor4;
Loc.Right := Loc.Left;
end;
end;
15:
begin
if LineColor2 = LineColor4 then
begin
LineStyle := LineStyle2;
LineColor := LineColor2;
Loc.Right := Loc.Left;
end
else
if LineColor1 = LineColor3 then
begin
LineStyle := LineStyle1;
LineColor := LineStyle1;
Loc.Bottom := Loc.Top;
end
else
if LineColor1 = LineColor2 then
begin
LineStyle := LineStyle1;
LineColor := LineStyle1;
Loc.Bottom := Loc.Top;
end
else
if LineColor1 = LineColor4 then
begin
LineStyle := LineStyle4;
LineColor := LineStyle4;
Loc.Right := Loc.Left;
end
else
if LineColor2 = LineColor3 then
begin
LineStyle := LineStyle2;
LineColor := LineStyle2;
Loc.Right := Loc.Left;
end
else
if LineColor3 = LineColor4 then
begin
LineStyle := LineStyle4;
LineColor := LineStyle4;
Loc.Right := Loc.Left;
end
else
begin
LineStyle := LineStyle1;
LineColor := LineStyle1;
Loc.Bottom := Loc.Top;
end;
end;
end;
Canvas.Pen.Color := LineColor;
DrawLine(Loc.Left, Loc.Top, Loc.Right, Loc.Bottom, LineStyle);
result := True;
end;
end;
procedure DrawOtherCorner;
var
R: TRect;
H, W: Integer;
begin
R := EXBoxRect(X, Y, X, Y);
InflateRect(R, 1, 1);
Loc := Rect(R.Left - 1, R.Top - 1, R.Left - 1, R.Top - 1);
LineStyle := 0;
LineColor := 0;
H := 0;
W := 0;
if (FLineWidth[LineStyle1] = 3) or (FLineWidth[LineStyle3] = 3) then
begin
Loc.Bottom := R.Top + 3 - 1;
H := 3;
if (FLineWidth[LineStyle2] <> 3) and (FLineWidth[LineStyle2] <> 0) then
begin
LineStyle := LineStyle2;
LineColor := LineColor2;
W := FLineWidth[LineStyle2];
end
else
if (FLineWidth[LineStyle4] <> 3) and (FLineWidth[LineStyle4] <> 0) then
begin
LineStyle := LineStyle4;
LineColor := LineColor4;
W := FLineWidth[LineStyle4];
end;
end
else
if (FLineWidth[LineStyle2] = 3) or (FLineWidth[LineStyle4] = 3) then
begin
Loc.Right := R.Left + 2;
W := 3;
if (FLineWidth[LineStyle3] <> 3) and (FLineWidth[LineStyle3] <> 0) then
begin
LineStyle := LineStyle3;
LineColor := LineColor3;
H := FLineWidth[LineStyle3];
end
else
if (FLineWidth[LineStyle1] <> 3) and (FLineWidth[LineStyle1] <> 0) then
begin
LineStyle := LineStyle1;
LineColor := LineColor1;
H := FLineWidth[LineStyle1];
end;
end
else
if (FLineWidth[LineStyle1] = 2) or (FLineWidth[LineStyle3] = 2) then
begin
Loc.Bottom := R.Top + 2 - 1;
H := 2;
if (FLineWidth[LineStyle2] <> 2) and (FLineWidth[LineStyle2] <> 0) then
begin
LineStyle := LineStyle2;
LineColor := LineColor2;
W := FLineWidth[LineStyle2];
end
else
if (FLineWidth[LineStyle4] <> 2) and (FLineWidth[LineStyle4] <> 0) then
begin
LineStyle := LineStyle4;
LineColor := LineColor4;
W := FLineWidth[LineStyle4];
end;
end
else
if (FLineWidth[LineStyle2] = 2) or (FLineWidth[LineStyle4] = 2) then
begin
Loc.Right := R.Left + 1;
W := 2;
if (FLineWidth[LineStyle3] <> 2) and (FLineWidth[LineStyle3] <> 0) then
begin
LineStyle := LineStyle3;
LineColor := LineColor3;
H := FLineWidth[LineStyle3];
end
else
if (FLineWidth[LineStyle1] <> 2) and (FLineWidth[LineStyle1] <> 0) then
begin
LineStyle := LineStyle1;
LineColor := LineColor1;
H := FLineWidth[LineStyle1];
end;
end;
if W = 1 then
W := 2;
if H = 1 then
H := 2;
Canvas.Pen.Color := LineColor;
DrawLine(Loc.Left, Loc.Top, Loc.Right, Loc.Bottom, LineStyle);
end;
function DrawDoubleLineCorner: Boolean;
var
R: TRect;
begin
result := False;
T := 0;
if FLineCorner[LineStyle1] then
T := 1;
if FLineCorner[LineStyle2] then
T := T + 2;
if FLineCorner[LineStyle3] then
T := T + 4;
if FLineCorner[LineStyle4] then
T := T + 8;
if (T <> 0) and (T <> 1) and (T <> 2) and (T <> 4) and (T <> 8) then
begin
Loc := EXBoxRect(X, Y, X, Y);
InflateRect(Loc, 1, 1);
R := Rect(Loc.Left - 1, Loc.Top - 1, Loc.Left + 3 - 1, Loc.Top + 3 - 1);
case T of
7: begin
if LineColor1 <> LineColor2 then
begin
Loc := R;
Loc.Bottom := Loc.Top;
Canvas.Pen.Color := LineColor1;
DrawLine(Loc.Left, Loc.Top, Loc.Right, Loc.Bottom, LineStyle1);
Loc := R;
Loc.Bottom := Loc.Top;
Canvas.Pen.Color := LineColor3;
DrawLine(Loc.Left, Loc.Top, Loc.Right, Loc.Bottom, LineStyle3);
end
else
begin
Loc := R;
Loc.Bottom := Loc.Top;
Canvas.Pen.Color := LineColor3;
DrawLine(Loc.Left, Loc.Top, Loc.Right, Loc.Bottom, LineStyle3);
Loc := R;
Loc.Bottom := Loc.Top;
Canvas.Pen.Color := LineColor1;
DrawLine(Loc.Left, Loc.Top, Loc.Right, Loc.Bottom, LineStyle1);
end;
Loc := R;
Loc.Right := Loc.Left;
Canvas.Pen.Color := LineColor2;
DrawLine(Loc.Left, Loc.Top + 2, Loc.Right, Loc.Bottom, LineStyle2);
end;
13: begin
if LineColor1 <> LineColor4 then
begin
Loc := R;
Loc.Bottom := Loc.Top;
Canvas.Pen.Color := LineColor1;
DrawLine(Loc.Left, Loc.Top, Loc.Right, Loc.Bottom, LineStyle1);
Loc := R;
Loc.Bottom := Loc.Top;
Canvas.Pen.Color := LineColor3;
DrawLine(Loc.Left, Loc.Top, Loc.Right, Loc.Bottom, LineStyle3);
end
else
begin
Loc := R;
Loc.Bottom := Loc.Top;
Canvas.Pen.Color := LineColor3;
DrawLine(Loc.Left, Loc.Top, Loc.Right, Loc.Bottom, LineStyle3);
Loc := R;
Loc.Bottom := Loc.Top;
Canvas.Pen.Color := LineColor1;
DrawLine(Loc.Left, Loc.Top, Loc.Right, Loc.Bottom, LineStyle1);
end;
Loc := R;
Loc.Right := Loc.Left;
Canvas.Pen.Color := LineColor4;
DrawLine(Loc.Left, Loc.Top, Loc.Right, Loc.Bottom - 2, LineStyle4);
end;
5:
begin
Loc := R;
Loc.Bottom := Loc.Top;
Canvas.Pen.Color := LineColor3;
DrawLine(Loc.Left, Loc.Top, Loc.Right - 1, Loc.Bottom, LineStyle3);
Loc := R;
Loc.Bottom := Loc.Top;
Canvas.Pen.Color := LineColor1;
DrawLine(Loc.Left + 1, Loc.Top, Loc.Right, Loc.Bottom, LineStyle1);
end;
11:
begin
if LineColor1 <> LineColor2 then
begin
Loc := R;
Loc.Right := Loc.Left;
Canvas.Pen.Color := LineColor2;
DrawLine(Loc.Left, Loc.Top, Loc.Right, Loc.Bottom, LineStyle2);
Loc := R;
Loc.Right := Loc.Left;
Canvas.Pen.Color := LineColor4;
DrawLine(Loc.Left, Loc.Top, Loc.Right, Loc.Bottom, LineStyle4);
end
else
begin
Loc := R;
Loc.Right := Loc.Left;
Canvas.Pen.Color := LineColor4;
DrawLine(Loc.Left, Loc.Top, Loc.Right, Loc.Bottom, LineStyle4);
Loc := R;
Loc.Right := Loc.Left;
Canvas.Pen.Color := LineColor2;
DrawLine(Loc.Left, Loc.Top, Loc.Right, Loc.Bottom, LineStyle2);
end;
Loc := R;
Loc.Bottom := Loc.Top;
Canvas.Pen.Color := LineColor1;
DrawLine(Loc.Left + 2, Loc.Top, Loc.Right, Loc.Bottom, LineStyle1);
end;
14:
begin
if LineColor2 <> LineColor3 then
begin
Loc := R;
Loc.Right := Loc.Left;
Canvas.Pen.Color := LineColor2;
DrawLine(Loc.Left, Loc.Top, Loc.Right, Loc.Bottom, LineStyle2);
Loc := R;
Loc.Right := Loc.Left;
Canvas.Pen.Color := LineColor4;
DrawLine(Loc.Left, Loc.Top, Loc.Right, Loc.Bottom, LineStyle4);
end
else
begin
Loc := R;
Loc.Right := Loc.Left;
Canvas.Pen.Color := LineColor4;
DrawLine(Loc.Left, Loc.Top, Loc.Right, Loc.Bottom, LineStyle4);
Loc := R;
Loc.Right := Loc.Left;
Canvas.Pen.Color := LineColor2;
DrawLine(Loc.Left, Loc.Top, Loc.Right, Loc.Bottom, LineStyle2);
end;
Loc := R;
Loc.Bottom := Loc.Top;
Canvas.Pen.Color := LineColor3;
DrawLine(Loc.Left, Loc.Top, Loc.Right - 2, Loc.Bottom, LineStyle3);
end;
10:
begin
Loc := R;
Loc.Right := Loc.Left;
Canvas.Pen.Color := LineColor4;
DrawLine(Loc.Left, Loc.Top, Loc.Right, Loc.Bottom - 2, LineStyle4);
Loc := R;
Loc.Right := Loc.Left;
Canvas.Pen.Color := LineColor2;
DrawLine(Loc.Left, Loc.Top + 1, Loc.Right, Loc.Bottom, LineStyle2);
end;
3: begin
E := 1;
if X + E < ColCount then
repeat
LineStyle := CellInfos[X + E, Y].TopLineStyle;
LineColor := CellInfos[X + E, Y].TopLineColor;
if FLineWidth[LineStyle] < FLineWidth[CellInfos[X + E, Y].BottomLineStyle] then
begin
LineStyle := CellInfos[X + E, Y].BottomLineStyle;
LineColor := CellInfos[X + E, Y].BottomLineColor;
end;
if FLineWidth[LineStyle] = FLineWidth[CellInfos[X + E, Y].BottomLineStyle] then
if LineColor < CellInfos[X + E, Y].BottomLineColor then
begin
LineStyle := CellInfos[X + E, Y].BottomLineStyle;
LineColor := CellInfos[X + E, Y].BottomLineColor;
end;
Inc(E);
until (X + E >= ColCount) or (FLineWidth[LineStyle] <> 3) or (LineColor1 <> LineColor);
F := 0;
repeat
LineStyle := CellInfos[X, Y + F].LeftLineStyle;
LineColor := CellInfos[X, Y + F].LeftLineColor;
if FLineWidth[LineStyle] < FLineWidth[CellInfos[X - 1, Y + F].RightLineStyle] then
begin
LineStyle := CellInfos[X - 1, Y + F].RightLineStyle;
LineColor := CellInfos[X - 1, Y + F].RightLineColor;
end;
if FLineWidth[LineStyle] = FLineWidth[CellInfos[X - 1, Y + F].RightLineStyle] then
if LineColor < CellInfos[X - 1, Y + F].RightLineColor then
begin
LineStyle := CellInfos[X - 1, Y + F].RightLineStyle;
LineColor := CellInfos[X - 1, Y + F].RightLineColor;
end;
Inc(F);
until (Y + F >= RowCount) or (FLineWidth[LineStyle] <> 3) or (LineColor2 <> LineColor);
D := 0;
if E > F then
D := 1
else
if E < F then
D := 2
else
if LineColor2 > LineColor1 then
D := 2
else
D := 1;
Loc := R;
Loc.Right := Loc.Left;
Canvas.Pen.Color := LineColor2;
DrawLine(Loc.Left, Loc.Top, Loc.Right, Loc.Bottom, LineStyle2);
Loc := R;
Loc.Bottom := Loc.Top;
Canvas.Pen.Color := LineColor1;
if D = 1 then
DrawLine(Loc.Left, Loc.Top, Loc.Right, Loc.Bottom, LineStyle1, 1)
else
DrawLine(Loc.Left + 1, Loc.Top, Loc.Right, Loc.Bottom, LineStyle1, 1);
end;
6: begin
E := 1;
if X - E > 0 then
begin
repeat
LineStyle := CellInfos[X - E, Y].TopLineStyle;
LineColor := CellInfos[X - E, Y].TopLineColor;
if FLineWidth[LineStyle] < FLineWidth[CellInfos[X - E, Y - 1].BottomLineStyle] then
begin
LineStyle := CellInfos[X - E, Y - 1].BottomLineStyle;
LineColor := CellInfos[X - E, Y - 1].BottomLineColor;
end;
if FLineWidth[LineStyle] = FLineWidth[CellInfos[X - E, Y - 1].BottomLineStyle] then
if LineColor < CellInfos[X - E, Y - 1].BottomLineColor then
begin
LineStyle := CellInfos[X - E, Y - 1].BottomLineStyle;
LineColor := CellInfos[X - E, Y - 1].BottomLineColor;
end;
Inc(E);
until (X - E <= 0) or (FLineWidth[LineStyle] <> 3) or (LineColor3 <> LineColor);
E := E - 2;
end;
F := 0;
repeat
LineStyle := CellInfos[X, Y + F].LeftLineStyle;
LineColor := CellInfos[X, Y + F].LeftLineColor;
if FLineWidth[LineStyle] < FLineWidth[CellInfos[X - 1, Y + F].RightLineStyle] then
begin
LineStyle := CellInfos[X - 1, Y + F].RightLineStyle;
LineColor := CellInfos[X - 1, Y + F].RightLineColor;
end;
if FLineWidth[LineStyle] = FLineWidth[CellInfos[X - 1, Y + F].RightLineStyle] then
if LineColor < CellInfos[X - 1, Y + F].RightLineColor then
begin
LineStyle := CellInfos[X - 1, Y + F].RightLineStyle;
LineColor := CellInfos[X - 1, Y + F].RightLineColor;
end;
Inc(F);
until (Y + F >= RowCount) or (FLineWidth[LineStyle] <> 3) or (LineColor2 <> LineColor);
D := 0;
if E > F - 1 then
D := 1
else
if E < F - 1 then
D := 2
else
if (X - 1 > 0) and (LineColor2 > LineColor3) then
D := 2
else
D := 1;
Loc := R;
Loc.Right := Loc.Left;
Canvas.Pen.Color := LineColor2;
DrawLine(Loc.Left, Loc.Top, Loc.Right, Loc.Bottom, LineStyle2);
Loc := R;
Loc.Bottom := Loc.Top;
Canvas.Pen.Color := LineColor3;
if D = 1 then
DrawLine(Loc.Left, Loc.Top, Loc.Right, Loc.Bottom, LineStyle3, 3)
else
DrawLine(Loc.Left, Loc.Top, Loc.Right - 1, Loc.Bottom, LineStyle3, 3);
end;
9: begin
E := 1;
if X + E < ColCount then
begin
repeat
LineStyle := CellInfos[X + E, Y].TopLineStyle;
LineColor := CellInfos[X + E, Y].TopLineColor;
if FLineWidth[LineStyle] < FLineWidth[CellInfos[X + E, Y - 1].BottomLineStyle] then
begin
LineStyle := CellInfos[X + E, Y - 1].BottomLineStyle;
LineColor := CellInfos[X + E, Y - 1].BottomLineColor;
end;
if FLineWidth[LineStyle] = FLineWidth[CellInfos[X + E, Y - 1].BottomLineStyle] then
if LineColor < CellInfos[X + E, Y - 1].BottomLineColor then
begin
LineStyle := CellInfos[X + E, Y - 1].BottomLineStyle;
LineColor := CellInfos[X + E, Y - 1].BottomLineColor;
end;
Inc(E);
until (X + E >= ColCount) or (FLineWidth[LineStyle] <> 3) or (LineColor1 <> LineColor);
E := E - 1;
end;
F := 1;
if Y - F > 0 then
begin
repeat
LineStyle := CellInfos[X, Y - F].LeftLineStyle;
LineColor := CellInfos[X, Y - F].LeftLineColor;
if FLineWidth[LineStyle] < FLineWidth[CellInfos[X, Y - F].LeftLineStyle] then
begin
LineStyle := CellInfos[X, Y - F].LeftLineStyle;
LineColor := CellInfos[X, Y - F].LeftLineColor;
end;
if FLineWidth[LineStyle] = FLineWidth[CellInfos[X, Y - F].LeftLineStyle] then
if LineColor < CellInfos[X, Y - F].LeftLineColor then
begin
LineStyle := CellInfos[X, Y - F].LeftLineStyle;
LineColor := CellInfos[X, Y - F].LeftLineColor;
end;
Inc(F);
until (Y - F <= 0) or (FLineWidth[LineStyle] <> 3) or (LineColor4 <> LineColor);
F := F - 2;
end;
D := 0;
if E > F then
D := 1
else
if E < F then
D := 2
else
if (X - 1 > 0) and (LineColor4 > LineColor1) then
D := 2
else
D := 1;
Loc := R;
Loc.Right := Loc.Left;
Canvas.Pen.Color := LineColor4;
DrawLine(Loc.Left, Loc.Top, Loc.Right, Loc.Bottom, LineStyle4);
Loc := R;
Loc.Bottom := Loc.Top;
Canvas.Pen.Color := LineColor1;
if D = 1 then
DrawLine(Loc.Left, Loc.Top, Loc.Right, Loc.Bottom, LineStyle1, 2)
else
DrawLine(Loc.Left + 1, Loc.Top, Loc.Right, Loc.Bottom, LineStyle1, 2);
end;
12: begin
E := 1;
if X - E > 0 then
begin
repeat
LineStyle := CellInfos[X - E, Y].TopLineStyle;
LineColor := CellInfos[X - E, Y].TopLineColor;
if FLineWidth[LineStyle] < FLineWidth[CellInfos[X - E, Y - 1].BottomLineStyle] then
begin
LineStyle := CellInfos[X - E, Y - 1].BottomLineStyle;
LineColor := CellInfos[X - E, Y - 1].BottomLineColor;
end;
if FLineWidth[LineStyle] = FLineWidth[CellInfos[X - E, Y - 1].BottomLineStyle] then
if LineColor < CellInfos[X - E, Y - 1].BottomLineColor then
begin
LineStyle := CellInfos[X - E, Y - 1].BottomLineStyle;
LineColor := CellInfos[X - E, Y - 1].BottomLineColor;
end;
Inc(E);
until (X - E <= 0) or (FLineWidth[LineStyle] <> 3) or (LineColor3 <> LineColor);
E := E - 2;
end;
F := 1;
if Y - F >= 0 then
begin
repeat
LineStyle := CellInfos[X, Y - F].LeftLineStyle;
LineColor := CellInfos[X, Y - F].LeftLineColor;
if FLineWidth[LineStyle] < FLineWidth[CellInfos[X - 1, Y - F].RightLineStyle] then
begin
LineStyle := CellInfos[X - 1, Y - F].RightLineStyle;
LineColor := CellInfos[X - 1, Y - F].RightLineColor;
end;
if FLineWidth[LineStyle] = FLineWidth[CellInfos[X - 1, Y - F].RightLineStyle] then
if LineColor < CellInfos[X - 1, Y - F].RightLineColor then
begin
LineStyle := CellInfos[X - 1, Y - F].RightLineStyle;
LineColor := CellInfos[X - 1, Y - F].RightLineColor;
end;
Inc(F);
until (Y - F >= RowCount) or (FLineWidth[LineStyle] <> 3) or (LineColor4 <> LineColor);
F := F - 2;
end;
D := 0;
if E > F then
D := 1
else
if E < F then
D := 2
else
if (X - 1 > 0) and (LineColor4 > LineColor3) then
D := 2
else
D := 1;
Loc := R;
Loc.Right := Loc.Left;
Canvas.Pen.Color := LineColor4;
DrawLine(Loc.Left, Loc.Top, Loc.Right, Loc.Bottom, LineStyle4);
Loc := R;
Loc.Bottom := Loc.Top;
Canvas.Pen.Color := LineColor3;
if D = 1 then
DrawLine(Loc.Left, Loc.Top, Loc.Right, Loc.Bottom, LineStyle3, 4)
else
DrawLine(Loc.Left, Loc.Top, Loc.Right - 1, Loc.Bottom, LineStyle3, 4);
end;
15:
begin
Loc := R;
Loc.Bottom := Loc.Top;
Canvas.Pen.Color := LineColor1;
DrawLine(Loc.Left + 2, Loc.Top, Loc.Right, Loc.Bottom, LineStyle1);
Loc := R;
Loc.Right := Loc.Left;
Canvas.Pen.Color := LineColor2;
DrawLine(Loc.Left, Loc.Top + 2, Loc.Right, Loc.Bottom, LineStyle2);
Loc := R;
Loc.Right := Loc.Left;
Canvas.Pen.Color := LineColor4;
DrawLine(Loc.Left, Loc.Top, Loc.Right, Loc.Bottom - 2, LineStyle4);
end;
end;
result := True;
end;
end;
begin
GetLineStyles;
if DrawDoubleLineCorner = False then
if DrawQuadrateCorner(3) = False then
if DrawQuadrateCorner(2) = False then
DrawOtherCorner;
end;
procedure DefLine(ARect: TRect;
LeftTop: Boolean;
Horz: Boolean = True);
begin
with Canvas, ARectdo
begin
if Horz then
begin
Pen.Color := clSilver;
if ShowColumnTitle and (ARow = 0) then
Pen.Color := clGray;
if ShowIndicator and (ACol = 0) then
Pen.Color := clGray;
if (ACol = FixedCols - 1) then
Pen.Color := $00888888;
if LeftTop then
Polyline([Point(Left - 1, Top), Point(Left - 1, Bottom + 1)])
else
Polyline([Point(Right, Top), Point(Right, Bottom + 1)]);
end
else
begin
Pen.Color := clSilver;
if ShowIndicator and (ACol = 0) then
Pen.Color := clGray;
if ShowColumnTitle and (ARow = 0) then
Pen.Color := clGray;
if (ARow = FixedRows - 1) then
Pen.Color := $00888888;
if LeftTop then
Polyline([Point(Left, Top - 1), Point(Right + 1, Top - 1)])
else
Polyline([Point(Left, Bottom), Point(Right + 1, Bottom)]);
end;
end;
end;
procedure DrawBorderLine(ARect: TRect;
CellRect: TRect);
var
X, Y, Z: Integer;
R, Loc, G: TRect;
LineStyle: Integer;
LineColor: TColor;
begin
G := ARect;
InflateRect(G, 1, 1);
R := CellRect;
CheckLine(R.Left, R.Top);
X := CellRect.Left;
for Y := R.Top to R.Bottomdo
begin
LineStyle := CellInfos[X, Y].LeftLineStyle;
LineColor := CellInfos[X, Y].LeftLineColor;
if X - 1 >= 0 then
if (FLineWidth[LineStyle] < FLineWidth[CellInfos[X - 1, Y].RightLineStyle])
or ((LineStyle = 0) and (CellInfos[X - 1, Y].RightLineStyle = 1))
or ((FLineWidth[LineStyle] = FLineWidth[CellInfos[X - 1, Y].RightLineStyle])
and (LineColor < CellInfos[X - 1, Y].RightLineColor)) then
begin
LineStyle := CellInfos[X - 1, Y].RightLineStyle;
LineColor := CellInfos[X - 1, Y].RightLineColor;
end;
if ExtCell then
begin
LineStyle:=1;
LineColor:=1;
end;
Loc := EXBoxRect(X, Y, X, Y);
if LineStyle = 0 then
begin
DefLine(Loc, True);
InflateRect(Loc, 1, 1);
end
else
begin
InflateRect(Loc, 1, 1);
Z := FLineWidth[LineStyle];
if Z >= 1 then
begin
Canvas.Pen.Color := LineColor;
DrawLine(Loc.Left - 1, Loc.Top, Loc.Left - 1, Loc.Bottom, LineStyle);
end;
end;
end;
Y := CellRect.Top;
for X := R.Left to R.Rightdo
begin
LineStyle := CellInfos[X, Y].TopLineStyle;
LineColor := CellInfos[X, Y].TopLineColor;
if Y - 1 >= 0 then
if (FLineWidth[LineStyle] < FLineWidth[CellInfos[X, Y - 1].BottomLineStyle])
or ((LineStyle = 0) and (CellInfos[X, Y - 1].BottomLineStyle = 1))
or ((FLineWidth[LineStyle] = FLineWidth[CellInfos[X, Y - 1].BottomLineStyle])
and (LineColor < CellInfos[X, Y - 1].BottomLineColor))
then
begin
LineStyle := CellInfos[X, Y - 1].BottomLineStyle;
LineColor := CellInfos[X, Y - 1].BottomLineColor;
end;
Loc := EXBoxRect(X, Y, X, Y);
if LineStyle = 0 then
begin
DefLine(Loc, True, False);
InflateRect(Loc, 1, 1);
end
else
begin
InflateRect(Loc, 1, 1);
Z := FLineWidth[LineStyle];
if Z >= 1 then
begin
Canvas.Pen.Color := LineColor;
DrawLine(Loc.Left, Loc.Top - 1, Loc.Right, Loc.Top - 1, LineStyle);
end;
end;
end;
X := CellRect.Right;
for Y := R.Top to R.Bottomdo
begin
LineStyle := CellInfos[X, Y].RightLineStyle;
LineColor := CellInfos[X, Y].RightLineColor;
if X < ColCount - 1 then
if (FLineWidth[LineStyle] < FLineWidth[CellInfos[X + 1, Y].LeftLineStyle])
or ((LineStyle = 0) and (CellInfos[X + 1, Y].LeftLineStyle = 1))
or ((FLineWidth[LineStyle] = FLineWidth[CellInfos[X + 1, Y].LeftLineStyle]) and
(LineColor < CellInfos[X + 1, Y].LeftLineColor)) then
begin
LineStyle := CellInfos[X + 1, Y].LeftLineStyle;
LineColor := CellInfos[X + 1, Y].LeftLineColor;
end;
if ExtCell then
begin
LineStyle:=1;
LineColor:=1;
end;
Loc := EXBoxRect(X, Y, X, Y);
if LineStyle = 0 then
begin
DefLine(Loc, False);
InflateRect(Loc, 1, 1);
end
else
begin
InflateRect(Loc, 1, 1);
Z := FLineWidth[LineStyle];
if Z >= 1 then
begin
if (R.Right <> FixedCols - 1) or (LeftCol = FixedCols) then
if R.Right = ColCount - 1 then
begin
Canvas.Pen.Color := LineColor;
DrawLine(Loc.Right - 2, Loc.Top, Loc.Right - 2, Loc.Bottom, LineStyle);
end;
end;
end;
end;
Y := CellRect.Bottom;
for X := R.Left to R.Rightdo
begin
LineStyle := CellInfos[X, Y].BottomLineStyle;
LineColor := CellInfos[X, Y].BottomLineColor;
if Y < RowCount - 1 then
if (FLineWidth[LineStyle] < FLineWidth[CellInfos[X, Y + 1].TopLineStyle])
or ((LineStyle = 0) and (CellInfos[X, Y + 1].TopLineStyle = 1))
or ((FLineWidth[LineStyle] = FLineWidth[CellInfos[X, Y + 1].TopLineStyle]) and
(LineColor < CellInfos[X, Y + 1].TopLineColor)) then
begin
LineStyle := CellInfos[X, Y + 1].TopLineStyle;
LineColor := CellInfos[X, Y + 1].TopLineColor;
end;
Loc := EXBoxRect(X, Y, X, Y);
if LineStyle = 0 then
begin
DefLine(Loc, False, False);
InflateRect(Loc, 1, 1);
end
else
begin
InflateRect(Loc, 1, 1);
Z := FLineWidth[LineStyle];
if Z >= 1 then
begin
if (R.Bottom <> FixedRows - 1) or (TopRow = FixedRows) then
if R.Bottom = RowCount - 1 then
begin
Canvas.Pen.Color := LineColor;
DrawLine(Loc.Left + T, Loc.Bottom - 2, Loc.Right, Loc.Bottom - 2, LineStyle);
end;
end;
end;
end;