Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Canvas Resizing

Posted on 2007-03-23
13
Medium Priority
?
536 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

618 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