Take the 2-minute tour ×

I have two questions about KOL.

  1. I have a main form. As I see this placed on the TForm's position. I wanna put it to the screen center. How can I access it's coordinates, or the handle for "SetWindowPos"?

  2. I have 4 labels in the form. For 2 of them I want to use smaller fonts. But I don't found any Font Size property... How to do it then?

share|improve this question
It's better to ask just one question at a time, as per the faq –  David Heffernan Dec 11 '12 at 8:07
IF you use KOL then why don't you use MCK ? MCK should provide for specifying font in design-time. –  Arioch 'The Dec 11 '12 at 11:04
@durumdara You've asked 66 questions here now. Take a look at the effort TLama put into his excellent answer. You have voted once only. 66 questions, and 1 vote. That is poor. You should engage more. –  David Heffernan Dec 12 '12 at 7:25
Sorry for two questions at once. Very-very thanks for every info! –  durumdara Dec 12 '12 at 8:39
As well as saying thank you, please learn to vote and accept answers. –  David Heffernan Dec 12 '12 at 20:42
add comment

3 Answers

up vote 2 down vote accepted

1.1. How to center form on screen ?

Use the CenterOnForm method. As description says, if it's applied to a form, centers form on screen:


1.2. How to get form position ?

Just like in Delphi by the Left and Top properties or e.g. by the Position property. The following pseudo-code results to the same:

ShowMessage('Form pos.: [' +
  Int2Str(Form.Left) + '; ' +
  Int2Str(Form.Top) + ']'
ShowMessage('Form pos: [' +
  Int2Str(Form.Position.X) + '; ' +
  Int2Str(Form.Position.Y) + ']'

Note, that unless you change the form position by yourself or until the applet is running, both properties returns 0. The form position, if you didn't set it, is adjusted when the applet starts.

1.3. How to get form handle ?

Use either the Handle property or the GetWindowHandle method. The following pseudo-code results to the same:


2. How to change the font size ?

As @David already mentioned in his post, use the Font.FontHeight property. Just one sidenote, the default font when you create e.g. that label is set to System to which is not possible to change the size, so don't be surprised when the size changes won't be applied. Here's a quote from the source:

Value 0 (default) says to use system default value, negative values are to represent font height in "points", positive - in pixels. In XCL usually positive values (if not 0) are used to make appearance independent from different local settings.

And here's a sample usage shown on positioned label creation:

Label1 := NewLabel(Form, 'Label1').SetPosition(8, 8);
Label1.Font.FontName := 'Tahoma';
Label1.Font.FontHeight := -11;

3. Example project

program Project1;


  PForm1 = ^TForm1;
  TForm1 = object(TObj)
    Form, Label1, Label2, Label3, Label4: PControl;

  Form1: PForm1;

procedure CreateForm(var Result: PForm1; AParent: PControl);
  New(Result, Create);
  with Result^ do
    Form := NewForm(AParent, 'Caption').SetSize(320, 240);

    Label1.Font.FontName := 'Tahoma';
    Label1.Font.FontHeight := -11;
    Label2 := NewLabel(Form, 'Label2').SetPosition(72, 8);
    Label2.Font.FontName := 'Tahoma';
    Label2.Font.FontHeight := -11;
    Label3 := NewLabel(Form, 'Label3').SetPosition(136, 8);
    Label3.Font.FontName := 'Tahoma';
    Label3.Font.FontHeight := -15;
    Label4 := NewLabel(Form, 'Label4').SetPosition(200, 8);
    Label4.Font.FontName := 'Tahoma';
    Label4.Font.FontHeight := -15;

  Applet := NewApplet('Test');
  CreateForm(Form1, Applet);
share|improve this answer
Your answer is great! Very-very thanks for it! –  durumdara Dec 14 '12 at 15:59
You're welcome! –  TLama Dec 14 '12 at 16:08
add comment

Question 1

Call the SetPosition and SetSize methods on the form.


Question 2

Use Font.FontHeight.

MyControl.Font.FontHeight := ...;
share|improve this answer
add comment
  1. If you want to call SetWindowPos, you can retrieve the handle calling the GetWindowHandle method of the returned pointer.

  2. Please, don't ask more than 1 question per question.

share|improve this answer
add comment

Your Answer


