?? asciifrm.pas
字號:
unit AsciiFrm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids, ComCtrls;
type
TAsciiForm = class(TForm)
StringGrid: TStringGrid;
StatusBar: TStatusBar;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure StringGridDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure StringGridSelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
AsciiForm: TAsciiForm;
procedure ShowAsciiForm;
implementation
{$R *.DFM}
procedure ShowAsciiForm;
begin
if AsciiForm <> nil then
begin
AsciiForm.WindowState := wsNormal;
AsciiForm.BringToFront;
Exit;
end;
AsciiForm := TAsciiForm.Create(Application);
AsciiForm.Show;
end;
procedure TAsciiForm.FormCreate(Sender: TObject);
var
TempCanSelect: Boolean;
begin
StringGrid.ClientWidth := StringGrid.ColCount * (StringGrid.DefaultColWidth + 1);
StringGrid.ClientHeight := StringGrid.RowCount * (StringGrid.DefaultRowHeight + 1);
StringGrid.Left := 0;
StringGrid.Top := 0;
ClientWidth := StringGrid.Width;
ClientHeight := StringGrid.Height + StatusBar.Height;
StringGridSelectCell(StringGrid, 1, 1, TempCanSelect);
end;
procedure TAsciiForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
AsciiForm := nil;
end;
procedure TAsciiForm.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = VK_ESCAPE then Close;
end;
procedure TAsciiForm.StringGridDrawCell(Sender: TObject; ACol,
ARow: Integer; Rect: TRect; State: TGridDrawState);
var
S: string;
W, H: Integer;
begin
W := Rect.Right - Rect.Left + 1;
H := Rect.Bottom - Rect.Top + 1;
with Sender as TStringGrid do
begin
if ARow = 0 then
begin
if ACol > 0 then
begin
S := IntToStr(ACol - 1);
Canvas.TextOut(Rect.Left + W div 2 + Canvas.TextWidth('0') - Canvas.TextWidth(S), Rect.Top + H div 2 - Canvas.TextHeight(S) div 2, S);
end;
end else
begin
if ACol = 0 then
begin
S := IntToStr((ARow-1) * 16);
Canvas.TextOut(Rect.Right - Canvas.TextWidth(S) - 3, Rect.Top + H div 2 - Canvas.TextHeight(S) div 2, S);
end else
begin
S := Chr((ARow - 1) * 16 + ACol - 1);
Canvas.TextOut(Rect.Left + W div 2 - Canvas.TextWidth(S) div 2, Rect.Top + H div 2 - Canvas.TextHeight(S) div 2, S);
end;
end;
end;
end;
procedure TAsciiForm.StringGridSelectCell(Sender: TObject; ACol,
ARow: Integer; var CanSelect: Boolean);
var
Dec: Integer;
begin
Dec := (ARow - 1) * 16 + ACol - 1;
StatusBar.SimpleText := '十進制數:' + Format('%3d', [Dec]) + ' ' +
'十六進制數:' + IntToHex(Dec, 2);
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -