Hwau
Hwau

Reputation: 880

How to bring label over edit control

I'm trying to set up a TEdit that will be used for research, so, it would be great to have a label displaying "current" / "count" over it, as observed by pressing CTRL + F in Google Chrome: enter image description here

It seems that the TLabel control's always placed behind the TEdit control. enter image description here

I also tried label1.BringToFront (Both at designtime and runtime), but it had no effect. Is there a way to place a label over an edit control?

Upvotes: 2

Views: 1524

Answers (1)

Craig
Craig

Reputation: 1956

TLabel inherits from TGraphicControl which cannot be shown on top of windowed controls, no matter how many times you try to use BringToFront it's just not going to happen.

However, you can use a container control such as a TPanel that can be used to contain your TEdit and TLabel controls, see this image as an example:

enter image description here

That is a quick and dirty way, it's simply a TPanel containing a TEdit and TLabel as child controls

The preferred way however is to create your own control which would give you full flexibility. Often trying to piece together multiple VCL controls to appear and function how you want is not usually ideal, and so by doing it the custom way gives you more freedom and possibilities.

Upvotes: 2

Related Questions