Peter Kiers
asked on
Canvas resize
Dear Experts,
I have a little programm with just a main-menu and my
own component. My component contains a black canvas
devided in 80 columns and 25 rows with a white cursor
draw on it. When I choose menu-item Fillbuf, the whole
canvas will be filled with characters. I don't know how to
make a resize procedure!!!
I know I have asked this question before, but then I used
a TImage-canvas. Now I have a component that uses a
TCustomControl. This is what i received when i used a
TImage:
procedure TScreenf.FormResize(Sender : TObject);
var lf: LOGFONT;
begin
ScrImage1.Picture.Bitmap.W idth:= ClientWidth;
ScrImage1.Picture.Bitmap.H eight:= ClientHeight;
GetObject(ScrImage1.Canvas .Font.Hand le, SizeOf(lf), @lf);
lf.lfWidth:= ClientWidth div 80;
lf.lfHeight:= ClientHeight div 25;
ScrImage1.Canvas.Font.hand le:= CreateFontIndirect(lf);
FontWidthPix:= lf.lfWidth;
FontHeightPix:= lf.lfHeight;
ShowBuf;
end;
I hope someone helps me.
I have put the little example on my site:
http://members.home.nl/peterkiers/
You see 2 floppy-disks download the Canvas2.zip
I hope someone can help me with this problem
I know I have asked this question more than once
But I can't do this on my own.
Peter K.
I have a little programm with just a main-menu and my
own component. My component contains a black canvas
devided in 80 columns and 25 rows with a white cursor
draw on it. When I choose menu-item Fillbuf, the whole
canvas will be filled with characters. I don't know how to
make a resize procedure!!!
I know I have asked this question before, but then I used
a TImage-canvas. Now I have a component that uses a
TCustomControl. This is what i received when i used a
TImage:
procedure TScreenf.FormResize(Sender
var lf: LOGFONT;
begin
ScrImage1.Picture.Bitmap.W
ScrImage1.Picture.Bitmap.H
GetObject(ScrImage1.Canvas
lf.lfWidth:= ClientWidth div 80;
lf.lfHeight:= ClientHeight div 25;
ScrImage1.Canvas.Font.hand
FontWidthPix:= lf.lfWidth;
FontHeightPix:= lf.lfHeight;
ShowBuf;
end;
I hope someone helps me.
I have put the little example on my site:
http://members.home.nl/peterkiers/
You see 2 floppy-disks download the Canvas2.zip
I hope someone can help me with this problem
I know I have asked this question more than once
But I can't do this on my own.
Peter K.
try like this
(*------------------------ ---------- ---------- ---*)
procedure TMyDrawingPanelX.Paint;
var
TxMetric: TTextMetric;
begin
Canvas.Font.Size := FontSize;
Canvas.Font.Name := FontName;
// GetTextMetrics(Canvas.Hand le, TxMetric);
// FontWidthPix := TxMetric.tmAveCharWidth;
// FontHeightPix := TxMetric.tmHeight;
Showbuf;
end;
(*------------------------ ---------- ---------- ---*)
procedure TMainForm.FormResize(Sende r: TObject);
var lf: LOGFONT;
FFont:TFont;
begin
try
FFont:=TFont.Create;
GetObject(MyDrawingPanelx1 .Font.Hand le, SizeOf(lf), @lf);
lf.lfWidth:= MyDrawingPanelx1.ClientWid th div 80;
lf.lfHeight:= MyDrawingPanelx1.ClientHei ght div 25;
FFont.handle:= CreateFontIndirect(lf);
MyDrawingPanelx1.FontSize :=FFont.Size;
MyDrawingPanelx1.FontWidth Pix:= lf.lfWidth;
MyDrawingPanelx1.FontHeigh tPix:= lf.lfHeight;
finally
FFont.Free;
end;
end;
(*------------------------
procedure TMyDrawingPanelX.Paint;
var
TxMetric: TTextMetric;
begin
Canvas.Font.Size := FontSize;
Canvas.Font.Name := FontName;
// GetTextMetrics(Canvas.Hand
// FontWidthPix := TxMetric.tmAveCharWidth;
// FontHeightPix := TxMetric.tmHeight;
Showbuf;
end;
(*------------------------
procedure TMainForm.FormResize(Sende
var lf: LOGFONT;
FFont:TFont;
begin
try
FFont:=TFont.Create;
GetObject(MyDrawingPanelx1
lf.lfWidth:= MyDrawingPanelx1.ClientWid
lf.lfHeight:= MyDrawingPanelx1.ClientHei
FFont.handle:= CreateFontIndirect(lf);
MyDrawingPanelx1.FontSize :=FFont.Size;
MyDrawingPanelx1.FontWidth
MyDrawingPanelx1.FontHeigh
finally
FFont.Free;
end;
end;
ASKER
I get 2 error messages:
"GetObject(MyDrawingPanelx 1.Font.Han dle, SizeOf(lf), @lf);"
[Error] Main.pas(91): Undeclared identifier: 'Font'
And the other:
[Error] Main.pas(91): EXCEPT or FINALLY expected
Gr,
PK
"GetObject(MyDrawingPanelx
[Error] Main.pas(91): Undeclared identifier: 'Font'
And the other:
[Error] Main.pas(91): EXCEPT or FINALLY expected
Gr,
PK
ASKER
I have change it like this and now it works:
procedure TMainForm.FormResize(Sende r: TObject);
var lf: LOGFONT;
FFont:TFont;
begin
try
FFont:=TFont.Create;
GetObject(canvas.Font.Hand le, SizeOf(lf), @lf);
lf.lfWidth:= MyDrawingPanelx1.ClientWid th div 80;
lf.lfHeight:= MyDrawingPanelx1.ClientHei ght div 25;
FFont.handle:= CreateFontIndirect(lf);
MyDrawingPanelx1.FontSize :=FFont.Size;
MyDrawingPanelx1.FontWidth Pix:= lf.lfWidth;
MyDrawingPanelx1.FontHeigh tPix:= lf.lfHeight;
finally
FFont.Free;
end;
end;
How can i make the mainform itself adjust to the component's canvas?
Peter
procedure TMainForm.FormResize(Sende
var lf: LOGFONT;
FFont:TFont;
begin
try
FFont:=TFont.Create;
GetObject(canvas.Font.Hand
lf.lfWidth:= MyDrawingPanelx1.ClientWid
lf.lfHeight:= MyDrawingPanelx1.ClientHei
FFont.handle:= CreateFontIndirect(lf);
MyDrawingPanelx1.FontSize :=FFont.Size;
MyDrawingPanelx1.FontWidth
MyDrawingPanelx1.FontHeigh
finally
FFont.Free;
end;
end;
How can i make the mainform itself adjust to the component's canvas?
Peter
type
TMyDrawingPanelX = class(TCustomControl)
private
fCursorVisible: boolean;
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
FontName: string;
FontSize: integer;
SCRROWS: integer;
SCRCOLS: integer;
FontWidthPix: integer;
FontHeightPix: integer;
CsrCol: integer;
CsrRow: integer;
ColorRed: TColor;
ColorGreen: TColor;
ColorBlue: TColor;
ColorYellow: TColor;
ColorPink: TColor;
ColorTurq: TColor;
ColorWhite: TColor;
ColorBlack: TColor;
CsrShape: integer;
CurCellColor: char;
CurCellHilite: char;
socOpen: boolean;
ScrBuf: TScrBuf;
CursorFlashTimer: TTImer;
LastcursorX, LastcursorY: integer;
Blinking: boolean;
CursorShape: boolean;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Paint; override;
procedure ShowBuf;
procedure DispCell(x: integer; y: integer; PaintBlanks: boolean);
procedure DrawCursor(x: integer; y: integer);
function ColorMapI2W(ic: char): TColor;
Procedure FillBuf;
procedure ClearCursor;
procedure SetCursorVisible(const Value: boolean);
property CursorVisible: boolean read fCursorVisible write SetCursorVisible;
procedure CursorFlashTimer_OnTImer(s ender: TObject);
procedure CursorUnderlined;
procedure CursorEmptybox;
procedure AlterCursor;
//test
procedure Copy;
procedure Paste;
procedure SelectAll;
function IsTextSelected: Boolean;
published
{ Published declarations }
property Align;
property Font; //<===== Add this line
end;
TMyDrawingPanelX = class(TCustomControl)
private
fCursorVisible: boolean;
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
FontName: string;
FontSize: integer;
SCRROWS: integer;
SCRCOLS: integer;
FontWidthPix: integer;
FontHeightPix: integer;
CsrCol: integer;
CsrRow: integer;
ColorRed: TColor;
ColorGreen: TColor;
ColorBlue: TColor;
ColorYellow: TColor;
ColorPink: TColor;
ColorTurq: TColor;
ColorWhite: TColor;
ColorBlack: TColor;
CsrShape: integer;
CurCellColor: char;
CurCellHilite: char;
socOpen: boolean;
ScrBuf: TScrBuf;
CursorFlashTimer: TTImer;
LastcursorX, LastcursorY: integer;
Blinking: boolean;
CursorShape: boolean;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Paint; override;
procedure ShowBuf;
procedure DispCell(x: integer; y: integer; PaintBlanks: boolean);
procedure DrawCursor(x: integer; y: integer);
function ColorMapI2W(ic: char): TColor;
Procedure FillBuf;
procedure ClearCursor;
procedure SetCursorVisible(const Value: boolean);
property CursorVisible: boolean read fCursorVisible write SetCursorVisible;
procedure CursorFlashTimer_OnTImer(s
procedure CursorUnderlined;
procedure CursorEmptybox;
procedure AlterCursor;
//test
procedure Copy;
procedure Paste;
procedure SelectAll;
function IsTextSelected: Boolean;
published
{ Published declarations }
property Align;
property Font; //<===== Add this line
end;
ASKER
Oke, I got it.
Do you know how can i make the mainform resize with the component's canvas?
PK
Do you know how can i make the mainform resize with the component's canvas?
PK
Sorry i didn't get you
ASKER
My English isn't very good, so i try to explain.
I want the main form adjust to the component's canvas.
The mainform has to resize with the text on the canvas.
P.
I want the main form adjust to the component's canvas.
The mainform has to resize with the text on the canvas.
P.
You mean,
if you change the contents of your component, the main form's size should change.
my english also very bad
if you change the contents of your component, the main form's size should change.
my english also very bad
ASKER
YIP
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Dinilud
500p. comming your way...
Greetings,
Peter Kiers
500p. comming your way...
Greetings,
Peter Kiers
ASKER