Solved

Canvas Resizing

Posted on 2007-03-23
13
531 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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
 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
error 1.1 400 Bad request idhttp delphi 18 87
SUM 2 INTEGER ARRAYS INTO 1 10 100
update joined tables 2 46
can i put an image from resource into image tag ? 6 25
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

776 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