📄 cledlbl.~pas
字号:
fPoints[3].x := fPoints[2].x - fSegmentThickness;
fPoints[3].y := fPoints[2].y - fSegmentThickness;
fPoints[4].x := fPoints[1].x - fSegmentThickness;
fPoints[4].y := fPoints[1].y + fSegmentThickness;
Canvas.Polygon(Slice(fPoints,4));
end;
7:
begin
fPoints[1].x := Rt;
fPoints[1].y := Tp+fVertMargine+VertCentre;
fPoints[2].x := fPoints[1].x;
fPoints[2].y := Tp+VertCentre-fVertMargine+VertCentre;
fPoints[3].x := fPoints[2].x - fSegmentThickness;
fPoints[3].y := fPoints[2].y - fSegmentThickness;
fPoints[4].x := fPoints[1].x - fSegmentThickness;
fPoints[4].y := fPoints[1].y + fSegmentThickness;
Canvas.Polygon(Slice(fPoints,4));
end;
1:
begin
fPoints[1].x := Lt+fHorzMargine;
fPoints[1].y := Tp+VertCentre;
fPoints[2].x := fPoints[1].x + SegHalf;
fPoints[2].y := Tp+VertCentre - SegHalf ; // 1 is Pen size
fPoints[3].x := Rt-fHorzMargine-SegHalf;
fPoints[3].y := fPoints[2].y;
fPoints[4].x := Rt-fHorzMargine;
fPoints[4].y := fPoints[1].y;
fPoints[5].x := Rt-fHorzMargine-SegHalf;
fPoints[5].y := Tp+VertCentre + SegHalf;
fPoints[6].x := fPoints[2].x;
fPoints[6].y := fPoints[5].y ;
Canvas.Polygon(fPoints);
end;
end;
end;
procedure TCLedLabel.DrawSegments(dSegment : TCharSegment;SegmentRect : TRect);
var
i : Byte;
begin
for i := 0{1} to 7 do
begin
if (byte(i) in dSegment) then
DrawSegment(i,TofOn,SegmentRect)
else
DrawSegment(i,TofOff,SegmentRect);
end;
end;
{
3
--
4| 1 |2
--
5| |7
-- * 0
6
}
procedure TCLedLabel.MakeSegments(dChar : Char;var dSegment : TCharSegment);
begin
dSegment := [];
case dChar of
'1': dSegment := [2,7];
'2': dSegment := [3,2,1,5,6];
'3': dSegment := [3,2,1,7,6];
'4': dSegment := [4,1,2,7];
'5': dSegment := [3,4,1,7,6];
'6': dSegment := [3,4,5,6,7,1];
'7': dSegment := [3,2,7];
'8': dSegment := [3,4,5,6,7,2,1];
'9': dSegment := [3,4,1,2,7];
'0': dSegment := [3,4,5,6,7,2];
'-': dSegment := [1];
'.': dSegment := [0];
end;
end;
procedure TCLedLabel.DispStr;
var
MySeg : TCharSegment;
xPos,
i : Integer;
MyRect : TRect;
NumDecimals,
csize : Integer;
s : String;
begin
cSize := ClientRect.Right div fNumChars;
// Pad String here... to make alignment
NumDecimals := 0;
if (FAllowDecimal) then begin
s := fText;
while (Pos('.', s) > 0) do begin
s := Copy(s, Pos('.', s) + 1, 255);
Inc(NumDecimals);
end;
end;
case fTextAlign of
TTALeft : s := Padr(fText,fNumChars + NumDecimals);
TTARight : s := Padl(fText,fNumChars + NumDecimals);
end;
xPos := 0;
for i := 1 to Length(s) do
begin
if ((s[i] = '.') and (FAllowDecimal)) then begin
DrawSegment(0, TofOn, MyRect);
end
else begin
MakeSegments(s[i],MySeg);
MyRect.Top := ClientRect.Top;
MyRect.Bottom := ClientRect.Bottom;
MyRect.Left := (xPos)*cSize;
MyRect.Right:= MyRect.Left+cSize;
DrawSegments(MySeg,MyRect);
Inc(xPos);
end;
end;
end;
procedure TCLedLabel.Paint;
begin
with Canvas do
begin
Brush.Color := fBackColor;
Brush.Style := bsSolid;
FillRect(ClientRect);
end;
DispStr;
end;
procedure TCLedLabel.SetBorderGap(dVal : Integer);
begin
fBorderGap := dVal;
Invalidate;
end;
procedure TCLedLabel.SetSegmentThickness(dVal : Integer);
begin
fSegmentThickness := dVal;
Invalidate;
end;
procedure TCLedLabel.SetHorzMargine(dVal : Integer);
begin
fHorzMargine := dVal;
Invalidate;
end;
procedure TCLedLabel.SetVertMargine(dVal : Integer);
begin
fVertMargine := dVal;
Invalidate;
end;
procedure TCLedLabel.SetOnColor(dVal : TColor);
begin
fOnColor := dVal;
Invalidate;
end;
procedure TCLedLabel.SetOffColor(dVal : TColor);
begin
fOffColor := dVal;
Invalidate;
end;
procedure TCLedLabel.SetPenColor(dVal : TColor);
begin
fPenColor := dVal;
Invalidate;
end;
procedure TCLedLabel.SetBackColor(dVal : TColor);
begin
fBackColor := dVal;
Invalidate;
end;
procedure TCLedLabel.SetText(dVal : String);
begin
fText := dVal;
Invalidate;
end;
procedure TCLedLabel.SetNumChars(dVal : Integer);
begin
fNumChars := dVal;
Invalidate;
end;
procedure TCLedLabel.SetTextAlign(dVal : TTextAlign);
begin
fTextAlign := dVal;
Invalidate;
end;
procedure TCLedLabel.SetAllowDecimal(dVal: bool);
begin
FAllowDecimal := dVal;
Invalidate;
end;
Function TCLedLabel.FloatFormat(thefloat : single) : string;
var
i : integer;
FormatSettings_For_currents : TFormatSettings;
str : string;
begin
FormatSettings_For_currents.DecimalSeparator := '.';
// 0 < thefloat < 10
if((thefloat < 10.00) and (thefloat >= 0.00)) then begin
str := AnsiLeftStr(FloatToStr(thefloat, FormatSettings_For_currents), 3); //hafif conversion problemi var
str := '0' + str;
if(str[3] <> '.') then
str := str + '.0';
end
// -10 < thefloat < 0
else if((thefloat > -10.00) and (thefloat < 0.00)) then begin
str := AnsiLeftStr(FloatToStr(thefloat, FormatSettings_For_currents), 4);
str := str + 's';
for i := length(str) - 1 downto 1 do
str[i+1] := str[i];
str[1] := '-';
str[2] := '0';
if(str[4] <> '.') then
str := str + '.0';
end
// thefloat > 10
else if(thefloat >= 10.00) then begin
str := AnsiLeftStr(FloatToStr(thefloat, FormatSettings_For_currents), 4);
if(str[3] <> '.') then
str := str + '.0';
end
// thefloat < -10
else if(thefloat <= -10.00) then begin
str := AnsiLeftStr(FloatToStr(thefloat, FormatSettings_For_currents), 5);
if(str[4] <> '.') then
str := str + '.0';
end;
SetText(str);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -