Link to home
Start Free TrialLog in
Avatar of Peter Kiers
Peter KiersFlag for Netherlands

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.Width:= ClientWidth;
  ScrImage1.Picture.Bitmap.Height:= ClientHeight;
  GetObject(ScrImage1.Canvas.Font.Handle, SizeOf(lf), @lf);
  lf.lfWidth:= ClientWidth div 80;
  lf.lfHeight:= ClientHeight div 25;
  ScrImage1.Canvas.Font.handle:= 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.


Avatar of Peter Kiers
Peter Kiers
Flag of Netherlands image

ASKER

HHHEEEEEEELLPPPP...
Avatar of dinilud
try like this

(*-----------------------------------------------*)
procedure TMyDrawingPanelX.Paint;
var
  TxMetric: TTextMetric;
begin
  Canvas.Font.Size := FontSize;
  Canvas.Font.Name := FontName;
//  GetTextMetrics(Canvas.Handle, TxMetric);
//  FontWidthPix := TxMetric.tmAveCharWidth;
//  FontHeightPix := TxMetric.tmHeight;
  Showbuf;
end;
(*-----------------------------------------------*)


procedure TMainForm.FormResize(Sender: TObject);
var lf: LOGFONT;
    FFont:TFont;
begin
 try
  FFont:=TFont.Create;
  GetObject(MyDrawingPanelx1.Font.Handle, SizeOf(lf), @lf);
  lf.lfWidth:= MyDrawingPanelx1.ClientWidth div 80;
  lf.lfHeight:= MyDrawingPanelx1.ClientHeight div 25;
  FFont.handle:= CreateFontIndirect(lf);
  MyDrawingPanelx1.FontSize :=FFont.Size;
  MyDrawingPanelx1.FontWidthPix:= lf.lfWidth;
  MyDrawingPanelx1.FontHeightPix:= lf.lfHeight;
 finally
  FFont.Free;
 end;
end;
I get 2 error messages:

"GetObject(MyDrawingPanelx1.Font.Handle, SizeOf(lf), @lf);"

 [Error] Main.pas(91): Undeclared identifier: 'Font'

 And the other:

[Error] Main.pas(91): EXCEPT or FINALLY expected

Gr,

PK
I have change it like this and now it works:

procedure TMainForm.FormResize(Sender: TObject);
var lf: LOGFONT;
    FFont:TFont;
begin
 try
  FFont:=TFont.Create;
  GetObject(canvas.Font.Handle, SizeOf(lf), @lf);
  lf.lfWidth:= MyDrawingPanelx1.ClientWidth div 80;
  lf.lfHeight:= MyDrawingPanelx1.ClientHeight div 25;
  FFont.handle:= CreateFontIndirect(lf);
  MyDrawingPanelx1.FontSize :=FFont.Size;
  MyDrawingPanelx1.FontWidthPix:= lf.lfWidth;
  MyDrawingPanelx1.FontHeightPix:= lf.lfHeight;
 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(sender: 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;
Oke, I got it.

Do you know how can i make the mainform resize with the component's canvas?

PK
Sorry i didn't get you
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.
You mean,
   if you change the contents of your component, the main form's size should change.

my english also very bad
YIP
ASKER CERTIFIED SOLUTION
Avatar of dinilud
dinilud
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Dinilud

500p. comming your way...

Greetings,

Peter Kiers