In a Delphi 10.4.2 32-bit Delphi VCL Application, I have a TLabel set on top of a TCard:
object lblColorTransparencyInfo: TLabel
AlignWithMargins = True
Left = 5
Top = 37
Width = 156
Height = 20
Margins.Left = 5
Margins.Top = 5
Margins.Right = 5
Margins.Bottom = 5
Align = alTop
Caption =
'Pick a color in the image to make that color transparent in the ' +
'whole image'
Color = clInfoBk
ParentColor = False
Transparent = False
WordWrap = True
ExplicitTop = 0
end
Label.Color is set to clInfoBk, so you can visually check the Label's size.
However, despite the Label.AutoSize is set to True, the Label's HEIGHT is much higher than its text height, despite Label.AutoSize = True:
Is this a bug in TLabel.AutoSize?
How can I set the Label Height to its correct text-height? (Please note that the Label's width could dynamically change during run-time which would also dynamically change the text-height at run-time).
This is taken from the documentation for the TCustomLabel.AutoSize property:
When AutoSize is False, the label is fixed in size. When AutoSize is True, the size of the label readjusts whenever the text changes. The size of the label is also readjusts [sic] when the Font property changes.
When WordWrap is True, the width of the label is fixed. If AutoSize is also True, changes to the text cause the label to change in height. When AutoSize is True and WordWrap is False, the font determines the height of the label, and changes to the text cause the label to change in width.
It only promises to change the size when the text or font is changed -- not when the label is resized due to its parent being resized. So one could argue that there is no bug here:
But in any case, one very quick and dirty solution is to tell the label to autosize when it is resized. Using an interposer class,
type
TLabel = class(Vcl.StdCtrls.TLabel)
protected
procedure Resize; override;
end;
implementation
{ TLabel }
procedure TLabel.Resize;
begin
inherited;
AdjustBounds;
end;
we can make it work (almost):
Of course, you could make your own TLabelEx control with this addition so you can use it as easily as the standard label.
Related
Now I am struggling to set the color of a child panel placed on another one.
The goal is to represent fractions of time with certain properties over the whole period, represented by a TPanel on the background(Lime Green).
I do not understand, the code I am using has already worked, but now the child panel keeps the same color of the parent panel.
int IntSize = SecondsBetween( CurrInterrup->TerminoInt, CurrInterrup->InicioInt );
int dura = SecondsBetween( Indisp->DtHoraFim, Indisp->DtHoraIni);
int left = SecondsBetween( Indisp->DtHoraIni, CurrInterrup->InicioInt);
int width = RoundTo(((double)dura /(double) IntSize) *(double) PnGreen->Width, 0);
left = RoundTo(((double)left/(double)IntSize) * (double)PnGreen->Width, 0);
TPanel *pn = new TPanel(this);
pn->ParentColor = false;
pn->BorderStyle = bsSingle;
pn->BevelKind = bkSoft;
pn->Color = clRed;
pn->Left = left;
pn->Width = width;
pn->Height = PnGreen->Height -5;
pn->Parent = PnGreen; // A Panel instantiated at design time of color clLime
pn->Update();
The panel "pn" is shown with the correct properties of left, height and width and position, but the color is clLime instead of clRed.
Is there any error on the code?
Thank you very much.
Kind Regards.
Try setting the panel's ParentBackground property to false.
If ParentBackground is True, the control uses the parent's theme background to draw its own background.
If ParentBackground is False, the control uses its own properties, such as Color, to draw its background.
I need to draw custom 120 x 120 thmbnails on a TListView in Viewstyle = vsIcon. without using LargeImages (I will paint on "OnCustomDrawItem").
The only way I could make this work is to specify a "dummy" TImageList for LargeImages with width/heigh = 120.
otherwise the item rect is undefined (also with OwnerDraw=True)
How to do this?
This question already has answers here:
Can Delphi themed toolbars have dividers that are centred between their tool buttons?
(3 answers)
Closed 8 years ago.
I'm using Delphi XE6 on top of Windows 2012 R2, and trying to create applications with toolbars. I'm however experiencing problems with the compiled application having a vertical superfluous bar at the left hand side of any Separators I might add.
This problem is described in both This Question and This Other Question, however I am not trying to use any other fancy controls - I am solely using the "New Button" and "New Separator" to add items. I have nonetheless tried the suggested fixes to no avail.
My sample application has been created as follows:
New VCL Forms Application
Add TToolBar
Select ToolBar1
Right Click, Select "New Button"
Right Click, Select "New Button"
Right Click, Select "New Separator"
Right Click, Select "New Button"
Run
This is what the application looks like
I have tried changing every potentially applicable property of the TToolBar itself (including setting Transparent to False), as well as the ToolBar3 (which is set to tbsSeparator), but I cannot seem to get rid of this vertical bar. I have also tried to add a TXPManifest to the form, but this made no difference.
The only thing that does seem to make a difference is if I set the Separator Visible property to False - the line disappears, but so does the Separator, so this isn't any help.
The issue I'm experiencing is also described in This thread, and I can assure the readers that I've not made any changes to the width of the Separator - it's all default.
Does anybody have any suggestions on how I can fix this?
For what it's worth - my Delphi Form is like this - you can see that I'm not using any fancy controls other than the supported ones:
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 112
ClientWidth = 382
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object ToolBar1: TToolBar
Left = 0
Top = 0
Width = 382
Height = 29
Caption = 'ToolBar1'
TabOrder = 0
Transparent = False
object ToolButton1: TToolButton
Left = 0
Top = 0
Caption = 'ToolButton1'
ImageIndex = 0
end
object ToolButton2: TToolButton
Left = 23
Top = 0
Caption = 'ToolButton2'
ImageIndex = 1
end
object ToolButton3: TToolButton
Left = 46
Top = 0
Width = 8
Caption = 'ToolButton3'
ImageIndex = 2
Style = tbsSeparator
end
object ToolButton4: TToolButton
Left = 54
Top = 0
Caption = 'ToolButton4'
ImageIndex = 3
end
end
object XPManifest1: TXPManifest
Left = 40
Top = 48
end
end
As the TToolbar is a wrapper of Microsoft Windows Rebar32 Control, it looks exactly the same as a normal Windows application does. Why not remove these separators, so that you will not see them anymore.
Which properties I must set in a TToolbar control in order to show a beveled line between the rows of the buttons when a toolbar is set to autosize.
on this image the toolbar only show one row with buttons
If I resize the parent form the toolbar redistribute the buttons on more rows and a beveled line is added at the bottom of each row.
I tried with many properties in the TToolbar control, but not beveled line is added when the toolbar is resize.
These are the current toolbar settings
object ToolBar1: TToolBar
AlignWithMargins = True
Left = 3
Top = 3
Width = 137
Height = 74
AutoSize = True
BorderWidth = 1
Caption = 'ToolBar1'
EdgeBorders = [ebLeft, ebTop, ebRight, ebBottom]
Images = ImageList1
TabOrder = 0
And this is how looks.
You should group tool buttons with separators. They can be added by right click on the toolbar and select "New Separator". In the first snapshot, there are several separators, so that line break will be shown.
I was experimenting with list view groups, and it turns out the control displays incorrectly when the application starts.
As soon as I resize the form it displays correctly:
I do not understand what is happening. Can anyone explain?
It's a bug in the Delphi control which I have reproduced. I'm not sure yet what causes the bug. I have submitted this to Quality Central as QC#101104.
I found a simple workaround by adding the following code to the form's OnShow event.
ListView1.Align := alNone;
ListView1.Align := alClient;
The following DFM file is enough to demonstrate the problem:
object MyForm: TMyForm
Left = 0
Top = 0
ClientHeight = 300
ClientWidth = 635
object ListView1: TListView
Left = 200
Top = 96
Width = 250
Height = 150
Align = alClient
Columns = <
item
Caption = 'Column'
end>
Groups = <
item
Header = 'Group header'
GroupID = 0
end>
Items.ItemData = {
052A0000000100000000000000FFFFFFFFFFFFFFFF0000000000000000000000
000854006800650020006900740065006D00}
GroupView = True
ViewStyle = vsReport
end
end
It turns out that another way to resolve the problem is to move the ViewStyle entry in the DFM file so that it appears before the Items entry. So yet another workaround for the problem would be to add the items at runtime. In fact this probably explains why this bug has not been found since I bet that the overwhelming majority of list view code adds the items at runtime.