* * *

Author Topic: how can i set property Layout to Panel?  (Read 1145 times)

majid.ebru

  • Sr. Member
  • ****
  • Posts: 270
how can i set property Layout to Panel?
« on: August 13, 2017, 11:59:31 am »
Hi

Label component has Layout property and we can change it to tlBottom or tlTop or tlCenter.

but Panel component has not this (Layout) property.

caption of panel always is tlCenter ,is it possebile to  change Layout , caption of panel (panel.caption)?

i want to show caption of panel in Top(tlTop) or Bottom(tlBottom)  of panel.

how can i do that?

thankyou
« Last Edit: August 13, 2017, 12:02:26 pm by majid.ebru »

bytebites

  • Full Member
  • ***
  • Posts: 121
Re: how can i set property Layout to Panel?
« Reply #1 on: August 13, 2017, 01:11:45 pm »
Put then label on the panel
label.parent := panel
label.align:=alclient

howardpc

  • Hero Member
  • *****
  • Posts: 2424
Re: how can i set property Layout to Panel?
« Reply #2 on: August 13, 2017, 01:36:53 pm »
Or subclass a panel (see attached project).

majid.ebru

  • Sr. Member
  • ****
  • Posts: 270
Re: how can i set property Layout to Panel?
« Reply #3 on: August 13, 2017, 03:26:55 pm »
Put then label on the panel
label.parent := panel
label.align:=alclient

i can't do taht.

majid.ebru

  • Sr. Member
  • ****
  • Posts: 270
Re: how can i set property Layout to Panel?
« Reply #4 on: August 13, 2017, 03:31:57 pm »
Or subclass a panel (see attached project).


Error ?!?!

i just use PANEL no TradioGroup and no other element

thank you

howardpc

  • Hero Member
  • *****
  • Posts: 2424
Re: how can i set property Layout to Panel?
« Reply #5 on: August 13, 2017, 04:28:58 pm »
OK, you have an earlier Lazarus version than me, which lacks BevelColor and WordWrap properties.
Replace the Paint procedure with this:

Code: Pascal  [Select]
  1. procedure TLayoutPanel.Paint;
  2. var
  3.   ARect: TRect;
  4.   TS : TTextStyle;
  5.  
  6. begin
  7.   ARect := GetClientRect;
  8.   Canvas.Frame3d(ARect, BevelWidth, BevelOuter);
  9.   InflateRect(ARect, -BorderWidth, -BorderWidth);
  10.   Canvas.Frame3d(ARect, BevelWidth, BevelInner);
  11.   if Caption <> '' then
  12.   begin
  13.     TS := Canvas.TextStyle;
  14.     TS.Alignment := BidiFlipAlignment(Self.Alignment, UseRightToLeftAlignment);
  15.     if BiDiMode<>bdLeftToRight then
  16.       TS.RightToLeft:= True;
  17.     TS.Layout:=FLayout;
  18.     TS.Opaque:= False;
  19.     TS.Clipping:= false;
  20.     TS.SystemFont:=Canvas.Font.IsDefault;
  21.  
  22.     if not Enabled then
  23.       if ThemeServices.ThemesEnabled then
  24.         Canvas.Font.Color := clGrayText
  25.       else
  26.       begin
  27.         Canvas.Font.Color := clBtnHighlight;
  28.         OffsetRect(ARect, 1, 1);
  29.         Canvas.TextRect(ARect, ARect.Left, ARect.Top, Caption, TS);
  30.         Canvas.Font.Color := clBtnShadow;
  31.         OffsetRect(ARect, -1, -1);
  32.       end
  33.     else
  34.       Canvas.Font.Color := Font.Color;
  35.  
  36.     Canvas.TextRect(ARect, ARect.Left, ARect.Top, Caption, TS);
  37.   end;
  38. end;

majid.ebru

  • Sr. Member
  • ****
  • Posts: 270
Re: how can i set property Layout to Panel?
« Reply #6 on: August 13, 2017, 04:47:25 pm »
it works

thank you

but i ues more than 30 Panels in form :o

how can i use your code?

also i should able to change Align of panels.some Align panels are alClient and some Align panels are alRigth and some Align panels are alLeft.

how can i change Align property of panels?

also i should able to change Color and font of Panels :'( 8-)

lainz

  • Hero Member
  • *****
  • Posts: 2087
Re: how can i set property Layout to Panel?
« Reply #7 on: August 13, 2017, 04:51:46 pm »
it works

thank you

but i ues more than 30 Panels in form :o

how can i use your code?

Creating a reusable component?

majid.ebru

  • Sr. Member
  • ****
  • Posts: 270
Re: how can i set property Layout to Panel?
« Reply #8 on: August 13, 2017, 05:48:18 pm »
Creating a reusable component?

How can i create a reusable component?

what is reusable component ?

howardpc

  • Hero Member
  • *****
  • Posts: 2424
Re: how can i set property Layout to Panel?
« Reply #9 on: August 13, 2017, 07:25:16 pm »
but i ues more than 30 Panels in form :o

how can i use your code?

also i should able to change Align of panels.some Align panels are alClient and some Align panels are alRigth and some Align panels are alLeft.

how can i change Align property of panels?

also i should able to change Color and font of Panels :'( 8-)
Unzip the attached package somewhere, and install the .lpk file in Lazarus.
You'll find a new LayoutPanel control on the Standard page of the component palette (you can change the RegisterComponent line to place it on another page).
I haven't bothered to create an icon for it, so it will show with the default red/blue icon.
You can now drop layoutpanels on your form, and set Align, Font, Color etc. as well as Layout using the object inspector.
Note this is a deliberately crippled component which does not know about recent improvements to TPanel such as BevelColor and WordWrap, in order that you can install it on your non-trunk Lazarus version.
This is an almost completely untested control, written in an afternoon, so don't be surprised to discover bugs.

majid.ebru

  • Sr. Member
  • ****
  • Posts: 270
Re: how can i set property Layout to Panel?
« Reply #10 on: August 15, 2017, 08:31:08 am »
hi

your class component is TLayoutPanel and i should change all panels in my project

and

i do not want to use any component?!?!

i am beginner in lazarus and is it possebile to "overide" Panel or add "Layout" property to Panel or ...

howardpc

  • Hero Member
  • *****
  • Posts: 2424
Re: how can i set property Layout to Panel?
« Reply #11 on: August 15, 2017, 10:37:19 am »
i do not want to use any component?!?!
I am not sure why you are using Lazarus at all in that case. The entire LCL consists of components and code supporting them...

Quote
i am beginner in lazarus and is it possebile to "overide" Panel or add "Layout" property to Panel or ...
Only by subclassing TPanel, AFAIK. I think a class helper would be insufficient since a new property is needed and a virtual method also has to be overridden. Perhaps a class helper would do it. I haven't tried since helpers are basically a hack to get past situations where you have only closed source components. With FOSS Lazarus LCL helpers ae not really needed. It is far better to write the class you want, extending existing code whose source is freely available.

The best way to change a standard panel into a TLayoutPanel is to right-click on the panel on your form, and choose Change class... from the popup menu. From the dropdown list on the right of the dialog choose TLayoutPanel, and you are good to go. You can immediately use the Layout property of the changed panel in the object inspector. You have to do this right-click on every panel you want to change, of course.

If you have a huge number of panels you want to change, you can also use Find and Replace to change all TPanel instances in your project's .pas files to TLayoutPanel, and open the .lfm(s) and do the same there, making sure you also add LayoutPanel to the form's uses clause.

When changing .lfm text files it is best to close Lazarus and use a plain text editor (not a word processor). It can be done in Lazarus, but is tricky since the IDE guards .lfm files and sometimes strange effects happen if you try to use Lazarus to alter an .lfm currently in use without doing it via the Designer, which I think must cache the form data and so may ignore any 'external' changes you introduce.
« Last Edit: August 15, 2017, 11:00:56 am by howardpc »

majid.ebru

  • Sr. Member
  • ****
  • Posts: 270
Re: how can i set property Layout to Panel?
« Reply #12 on: August 15, 2017, 11:00:16 am »
i don't want to use any component (' external component ') without Lazarus component ?!?(sorray)
.
after unzip your component , size of folder is 405K :o ?
.
and  takes a (very very very )long time to install it ,it is unusual  (almost my computer almost Hanged ?!?!?!?!??!?!!??!)
.
Why?   i thinck ,it is very big for a component?
.
but thank you to answer :-*
« Last Edit: August 15, 2017, 11:12:29 am by majid.ebru »

howardpc

  • Hero Member
  • *****
  • Posts: 2424
Re: how can i set property Layout to Panel?
« Reply #13 on: August 15, 2017, 12:16:21 pm »
Yes I omitted to delete the lib subdirectory in the compressed .lpk, so the .lpk is unnecessarily large. Just delete that subdirectory of the package once uncompressed, and try reinstalling.

Installing any component in Lazarus requires recompiling the IDE. Depending on your hardware, OS and other installed packages this can take a few seconds. If it hangs there is either something wrong with one of the packages you are installing, or something wrong with the original Lazarus installation. Perhaps a 'foreign' .ppu in the lib subdirectory caused problems for you. I apologise for my oversight. Uninstall the component, delete the lib subdirectory and try reinstalling.

TLayoutPanel is not an official Lazarus component. But 99% of its code is from the LCL. I simply added a minor tweak.
« Last Edit: August 15, 2017, 12:18:42 pm by howardpc »

majid.ebru

  • Sr. Member
  • ****
  • Posts: 270
Re: how can i set property Layout to Panel?
« Reply #14 on: August 15, 2017, 03:35:33 pm »
thank you

i will try it

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus