• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 537
  • Last Modified:

Canvas Resizing

Dear Experts,

I want to make a telnet-programm.  I have put an TScollBox on the form and on
the TScrollbox I have put an TImage. I have devided the TImage in 80 columns and 25 rows.
I have a procedure that fills the canvas with characters and numbers. So far no problemo.

I want to resize the form and I want that the font resize with it. To show you exactly what
I mean I have put 3 pictures of another telnet-program on my site. In all the 3 pictures you
see the telnet-programm resized differently, and you see the font is still readable.

I want that to in my example, but I just don't know how to do that?
I have allready asked this question before, and I got some good responses
only there is one problem, I don't understand any of it.

http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_21952890.html


Can someone PLEASE help me with this.

I have put the 3 pictures and the canvas-example on my site.
The address is : http://members.home.nl/peterkiers/
click on the Demo-button.

Thank you in advanced,

Greetings,

peter Kiers





0
peterkiers
Asked:
peterkiers
  • 7
  • 6
1 Solution
 
ziolkoCommented:
well first of all why put image on scrollbox instead painting on form itself,
then you could write OnPaint event handler to draw letters\numbers
relative to forms clientheight, clientwidth.
you wrote that you need 80x25 "cells"
so what you need is method that fills single cell then to draw letter/number you'll
call this method with appropriate params (like cell coord) but before that
you can calculate cell dimensions (clientwidth div 80, clientheight div 25)

ziolko.
0
 
peterkiersAuthor Commented:
Can you help me by giving an example or change my example.

P.
0
 
ziolkoCommented:
i'll try but i can't promise that i'll paste some code within 15 or so minutes:)

ziolko.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
peterkiersAuthor Commented:
no rush
0
 
ziolkoCommented:
i've come up with something like this, it's not perfect as you would see a lot of flickering
but i hope it will point you in right direction

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    procedure FormCanResize(Sender: TObject; var NewWidth, NewHeight: Integer; var
        Resize: Boolean);
    procedure FormPaint(Sender: TObject);
  private
    FCellWidth: Integer;
    FCellHeight: Integer;
    procedure FillCell(ARowIdx, AColIdx: Integer);
    procedure DoPaint;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
const
      COL_COUNT = 80;
      ROW_COUNT = 25;

procedure TForm1.DoPaint;
var cnt: Integer;
begin
  Canvas.Lock;
  try
    Canvas.Brush.Color := Color;
    Canvas.FillRect(ClientRect);
    for cnt := 0 to ROW_COUNT do
      FillCell(cnt, 40);
  finally
    Canvas.Unlock;
  end;
end;

procedure TForm1.FillCell(ARowIdx, AColIdx: Integer);
var r: TRect;
begin
  r.Left := AColIdx * FCellWidth;
  r.Top := ARowIdx * FCellHeight;
  r.Right := r.Left + FCellWidth;
  r.Bottom := r.Top + FCellHeight;
  Canvas.Brush.Color := clBlack;
  Canvas.FillRect(r);
end;

procedure TForm1.FormCanResize(Sender: TObject; var NewWidth, NewHeight:
    Integer; var Resize: Boolean);
begin
  Canvas.Brush.Color := Color;
  Canvas.FillRect(ClientRect);
  FCellWidth := ClientWidth div COL_COUNT;
  FCellHeight := ClientHeight div ROW_COUNT;
  DoPaint;
end;

procedure TForm1.FormPaint(Sender: TObject);
begin
  DoPaint;
end;

end.


ziolko.
0
 
peterkiersAuthor Commented:
When I try your example and execute it I get
a big line in the middle of the canvas!

Or i am doing something wrong

Peter
0
 
peterkiersAuthor Commented:
But I like the resize
0
 
ziolkoCommented:
yup thats what it does, you can print letters/numbers by calling FillCell() with appropriate params
for example this will print huge + sign

procedure TForm1.DoPaint;
var cnt: Integer;
begin
  Canvas.Lock;
  try
    Canvas.Brush.Color := Color;
    Canvas.FillRect(ClientRect);
    for cnt := 0 to ROW_COUNT do
      FillCell(cnt, 40);
    for cnt := 0 to COL_COUNT do
      FillCell(12, cnt);
  finally
    Canvas.Unlock;
  end;
end;


ziolko.
0
 
peterkiersAuthor Commented:
Can't you change the code for me that i just
get a black canvas on my form that fills the whole
form.

Peter Kiers
0
 
peterkiersAuthor Commented:
and offcourse divided in 80 rows and 25 colums
and the cells must be empty

0
 
ziolkoCommented:
procedure TForm1.DoPaint;
var cnt: Integer;
begin
  Canvas.Lock;
  try
    Canvas.Brush.Color := clBlack; <-- here set any background color you want
    Canvas.FillRect(ClientRect);
    for cnt := 0 to ROW_COUNT do
      FillCell(cnt, 40);
    for cnt := 0 to COL_COUNT do
      FillCell(12, cnt);
  finally
    Canvas.Unlock;
  end;
end;

procedure TForm1.FillCell(ARowIdx, AColIdx: Integer);
var r: TRect;
begin
  r.Left := AColIdx * FCellWidth;
  r.Top := ARowIdx * FCellHeight;
  r.Right := r.Left + FCellWidth;
  r.Bottom := r.Top + FCellHeight;
  Canvas.Brush.Color := clBlack; <-- change this to custom color
  Canvas.FillRect(r);
end;

ziolko.
0
 
peterkiersAuthor Commented:
Thanks for the help.

500 p. comming your way

Greetings,

Peter Kiers
0
 
ziolkoCommented:
thanks:)

ziolko.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now