Recent

Author Topic: How to draw a box.  (Read 3995 times)

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: How to draw a box.
« Reply #15 on: September 28, 2020, 02:14:29 am »
with

 
Code: Pascal  [Select][+][-]
  1.     With Canvas do
  2.         begin
  3.           TextOut (5,5,'One')
  4.           TextOut (5,25,'Two');
  5.           TextOut (5,65,' Four');
  6.         end;

I didn't get any lines.

@Jamie a PDF is attached. Just a few boxes will do. To big so it's at this link.

https://drive.google.com/file/d/1NF3Xft14bLi0raQKvhB2IfDm725-ym2Z/view?usp=sharing

@ winni

I tried the intro and the first try wouldn't compile,

@winni These are the instructions in the
ttp://www.pp4s.co.uk/main/tu-oop-canvas-intro.html

{In Lazarus, Project > New project, select Application.
   View Units and select Project1.  Copy this code into Project1
   and save the unit as unit1 (although it will not be needed).
   Save the project as CanvasDemo2.}

However the code is for a program not an application. I have tried it 4 times and can't get it to compile.
« Last Edit: September 28, 2020, 02:45:28 am by JLWest »
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

jamie

  • Hero Member
  • *****
  • Posts: 6077
Re: How to draw a box.
« Reply #16 on: September 28, 2020, 03:08:32 am »
I can not down load that PDF.. Every step I take its trying to get me to  install software I don't want and sign up for services that will cost me in the end..

  A simple PNG image which is small attached here would of been just fine..

  I just down loaded a 10-10EZ health benefit form.

 In any case If you are looking to use scattered layout then I guess  a Tgrid is out of the question I would think

 But if they are in a formatted arrangement then you can use the TStringGrid and select an editor for the cell..

 The grid lines can be set for thick lines, color etc.

 If you don't like that idea, then a bunch of panels with anchors to each other with the edit controls inside..

 how many boxes are going to be alive here ?


EDIT:
  have you considered using a Spread sheet component ?

  That will allow you to have enter fields, adjust your lines etc.

https://wiki.lazarus.freepascal.org/FPSpreadsheet

You only need to download and install it..
there are tutorials for you to look at too.
« Last Edit: September 28, 2020, 03:14:18 am by jamie »
The only true wisdom is knowing you know nothing

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: How to draw a box.
« Reply #17 on: September 28, 2020, 03:57:59 am »
Thanks I'll take a look.

Maybe I'll just give up on the idea.
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: How to draw a box.
« Reply #18 on: September 29, 2020, 11:30:20 am »
Hi!

Put the follwing code into your TForm1.
Connect it with the OnPaint event of TForm1.
Done.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormPaint(Sender: TObject);
  2. begin
  3. with Canvas do
  4.          begin
  5.           TextOut (5,5,'One')
  6.           TextOut (5,25,'Two');
  7.           TextOut (5,65,' Four');    
  8.         end; // with
  9. end;                

Winni

Handoko

  • Hero Member
  • *****
  • Posts: 5122
  • My goal: build my own game engine using Lazarus
Re: How to draw a box.
« Reply #19 on: September 29, 2020, 12:03:18 pm »
I can not down load that PDF.. Every step I take its trying to get me to  install software I don't want and sign up for services that will cost me in the end..

I did not have problem downloading the file from Google Drive. Below is the screenshot of the pdf viewing using Linux's Atril Document Viewer:

Handoko

  • Hero Member
  • *****
  • Posts: 5122
  • My goal: build my own game engine using Lazarus
Re: How to draw a box.
« Reply #20 on: September 29, 2020, 02:04:12 pm »
I didn't fully follow this thread. But, hey it is not difficult to write something like the pdf form using Pascal using TEdit, TCheckBox and TShape:

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, StdCtrls, ExtCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     CheckBox1: TCheckBox;
  16.     CheckBox2: TCheckBox;
  17.     CheckBox3: TCheckBox;
  18.     CheckBox4: TCheckBox;
  19.     CheckBox5: TCheckBox;
  20.     CheckBox6: TCheckBox;
  21.     Edit1: TEdit;
  22.     Label1: TLabel;
  23.     Label2: TLabel;
  24.     Label3: TLabel;
  25.     Shape1: TShape;
  26.     Shape2: TShape;
  27.     Shape3: TShape;
  28.     procedure FormCreate(Sender: TObject);
  29.   end;
  30.  
  31. var
  32.   Form1: TForm1;
  33.  
  34. implementation
  35.  
  36. {$R *.lfm}
  37.  
  38. { TForm1 }
  39.  
  40. procedure TForm1.FormCreate(Sender: TObject);
  41. begin
  42.   Edit1.Text        := '';
  43.   Edit1.Color       := clWhite;
  44.   Edit1.BorderStyle := bsNone;
  45. end;
  46.  
  47. end.

It works on Linux but it should works too on Windows with no or some modifications.

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: How to draw a box.
« Reply #21 on: September 29, 2020, 06:20:37 pm »
This is what I'm try to enhance with boxes or double borders around some controls. In the upper right of the form I would like to have borders or boxes around the items.

May seem like a  rather small item but actually I have been working on this for over two years (off and on of course).

It is a specialized editor which will allow a user to edit the Apt.Dat file(s) in X-Plane 11. The file has over 9 million variable length text records. There are two complete copies of the file on the system and a single purpose apt.dat  file for each Custom airports installation.  My system has 20 apt.dat's 18 custom airports, the global and Resource file.


 
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

Handoko

  • Hero Member
  • *****
  • Posts: 5122
  • My goal: build my own game engine using Lazarus
Re: How to draw a box.
« Reply #22 on: September 29, 2020, 06:34:33 pm »
This is what I'm try to enhance with boxes or double borders around some controls.

I personally think using background color is better than double-lined box, it catches attention and looks better. And it can be easily done by setting the TShape.Brush.Color property.
« Last Edit: September 29, 2020, 06:36:50 pm by Handoko »

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: How to draw a box.
« Reply #23 on: September 29, 2020, 06:52:32 pm »
@Handoko
Yea, you might be right.

@winni

I recoded and still don't get boxes. Maybe that's a operating thing.  I coded the Onpaint event of the Form.  I don't know.

@handoko

I think I can get a long way with TShape's.
« Last Edit: September 29, 2020, 07:03:45 pm by JLWest »
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: How to draw a box.
« Reply #24 on: September 30, 2020, 10:48:47 pm »
Hi!

I made you an example for a box.
And I made you an example for text - without a box.

I thought you could combine the two examples.
Obviously not .

You should read the introduction to the canvas.

Here is an example for a Turbo box  with text.
Result in the attachment.
Code: Pascal  [Select][+][-]
  1. procedure PaintImage(Img: TImage);
  2. var PMidleft, PMidRight : TPoint;
  3.     R : Trect;
  4. begin
  5. R := Rect(10,10,200,140);
  6. with Img.Canvas do
  7.          begin
  8.                   Brush.Color := clWhite;
  9.                   Fillrect (0,0,Img.Width, Img.Height);
  10.                   Pen.Color := clred;
  11.                   Rectangle(R);
  12.                   InflateRect(R,-2,-2);
  13.                   PMidLeft := Point(R.left,90);
  14.                   PMidRight :=Point(R.Right,90);
  15.                   Pen.Color := clBlue;
  16.                   Rectangle(R.left,R.Top,PMidRight.x, PMidRight.y+1);
  17.                   Rectangle(PMidLeft.x,PMidLeft.y,R.Right,R.Bottom);
  18.  
  19.  
  20.                   Font.Height := 14;
  21.                   TextOut(15,15,'The Doctor is in ');
  22.                   TextOut (15,30,'Fr - Su   22°° - 4°°');
  23.                   TextOut(15,100,'Dr. Hackenbush');
  24.          end; // with
  25. end;
  26.  
  27. procedure TForm1.Button1Click(Sender: TObject);
  28. begin
  29.    PaintImage(Image1);
  30. end;
  31.    

Winni

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: How to draw a box.
« Reply #25 on: October 01, 2020, 12:54:36 am »
@ winni - Thank You

Something came up and I'm just now getting back to this. I had stated the research on the
paint a box, but had to stop.

On your comment "Obviously not' that may in fact be true in the end. But I did make a little progress before having to stopping.

When I get an answer to a problem on the form I usually make a demo of the solution in a directory (CODLIB). There are 202 sub-directories in the CODLIB Soon to be 203.

You may say WOW what a lot of work. Bit I do it because I can then copy the Unit1.pas to a text file, load it into an editor and set the front to 22 and read the code. Plus I can return to the demo.

It is true that ctl and the wheel will enlarge most things but you get you forms all setup to code and test. Then you have to read some code and I would have to take the editor to full screen. Enlarge the code. Then go back to my working setup.

So I have two monitors. One where I write code in an editor with the font size 22. Then I copy and past.

Going to set up you code in a demo and see how it works.

Thanks again.
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

 

TinyPortal © 2005-2018