Solved

Canvas Resizing

Posted on 2007-03-23
13
528 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
Comment Utility
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
Comment Utility
Can you help me by giving an example or change my example.

P.
0
 
LVL 21

Expert Comment

by:ziolko
Comment Utility
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
Comment Utility
no rush
0
 
LVL 21

Expert Comment

by:ziolko
Comment Utility
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
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 1

Author Comment

by:peterkiers
Comment Utility
But I like the resize
0
 
LVL 21

Expert Comment

by:ziolko
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks for the help.

500 p. comming your way

Greetings,

Peter Kiers
0
 
LVL 21

Expert Comment

by:ziolko
Comment Utility
thanks:)

ziolko.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

763 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

10 Experts available now in Live!

Get 1:1 Help Now