Solved

Canvas Resizing

Posted on 2007-03-23
13
530 Views
Last Modified: 2012-05-05
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
Comment
Question by:peterkiers
  • 7
  • 6
13 Comments
 
LVL 21

Expert Comment

by:ziolko
ID: 18778502
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
 
LVL 1

Author Comment

by:peterkiers
ID: 18778548
Can you help me by giving an example or change my example.

P.
0
 
LVL 21

Expert Comment

by:ziolko
ID: 18778623
i'll try but i can't promise that i'll paste some code within 15 or so minutes:)

ziolko.
0
 
LVL 1

Author Comment

by:peterkiers
ID: 18778786
no rush
0
 
LVL 21

Expert Comment

by:ziolko
ID: 18778844
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
 
LVL 1

Author Comment

by:peterkiers
ID: 18778935
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:peterkiers
ID: 18778941
But I like the resize
0
 
LVL 21

Expert Comment

by:ziolko
ID: 18779137
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
 
LVL 1

Author Comment

by:peterkiers
ID: 18780479
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
 
LVL 1

Author Comment

by:peterkiers
ID: 18780549
and offcourse divided in 80 rows and 25 colums
and the cells must be empty

0
 
LVL 21

Accepted Solution

by:
ziolko earned 500 total points
ID: 18780784
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
 
LVL 1

Author Comment

by:peterkiers
ID: 18781064
Thanks for the help.

500 p. comming your way

Greetings,

Peter Kiers
0
 
LVL 21

Expert Comment

by:ziolko
ID: 18781098
thanks:)

ziolko.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
A short film showing how OnPage and Connectwise integration works.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

948 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now