Technology Programming

Implementing "Contains Focus" for Delphi"s Container Controls: TPanel, TGroupBox

In complex form designs where you have dozens of controls contained in several containers it is sometimes necessary to find out whether the focused control (the one with the input focus) is a child of some overall parent of a group of controls.

Picture the next design: you are using frame objects to group controls together (or any other type of container control). You are dynamically instatiating the frame object(s) to be arranged on the form at run-time.


At some point in the life of the application you need to figure out if a specific frame has the input focus - or better to say - if the frame contains the control with the input focus.

TWinControl.Contains Focus?

The ContainsFocus focus function returns true if the control, or one of its child controls, currently has the input focus.
function ContainsFocus(control : TWinControl) : boolean; var   focusedHandle : HWND;   focusedControl : TWinControl; begin   focusedHandle := Windows.GetFocus() ;  focusedControl := FindControl(focusedHandle) ;  if focusedControl = nil then     result := false   else   begin     result := control.ContainsControl(focusedControl) ;   end; end; Let's say you have a few Edit boxes inside a Panel inside a GroupBox (GroupBox1). If you need to figure out whether the GroupBox contains the control with the input focus (active control) you can call the ContainsFocus, as in:
if ContainsFocus(GroupBox1) thenbegin // read from all edit boxes and   // store the values somewhereend;

Delphi tips navigator:
» Focus the First Entry Control in a Container
« Get Directory Creation, Modified, Last Accessed and Last Write Date and Time

SHARE
RELATED POSTS on "Technology"
WordPress - How to Set up a New Theme to WordPress 3.
WordPress - How to Set up a New Theme to WordPress 3.
Solution of Creative Web Design
Solution of Creative Web Design
The three disciplines of User Experience
The three disciplines of User Experience
Web Design Sheffield Options For Professional Enterprises
Web Design Sheffield Options For Professional Enterprises
Do you have what it takes?
Do you have what it takes?
Segway Cost
Segway Cost
Microsoft Access 2010: What's Coming with Office 2010?
Microsoft Access 2010: What's Coming with Office 2010?
Companies of Web Development in Ireland Provide Designs that Work
Companies of Web Development in Ireland Provide Designs that Work
Penguin Update to Put Red-Flags on Negative SEO
Penguin Update to Put Red-Flags on Negative SEO
Innovative web 2 design templates can make your business famous quickly
Innovative web 2 design templates can make your business famous quickly
Building A Search Engine Friendly Website
Building A Search Engine Friendly Website
Exceptional Advice To Build Up Your Internet Marketing
Exceptional Advice To Build Up Your Internet Marketing
The Benefits of Selecting The Right Hosting Company
The Benefits of Selecting The Right Hosting Company
Is There a Methodology for Making Successful Logos
Is There a Methodology for Making Successful Logos
Benefits of Ruby On Rails Development
Benefits of Ruby On Rails Development
The Power of Colour and Shapes in Your Infant's Life.
The Power of Colour and Shapes in Your Infant's Life.
Advantages of Hiring PSD To HTML Service Providers
Advantages of Hiring PSD To HTML Service Providers
How to Make Responsive Web Design Attractive?
How to Make Responsive Web Design Attractive?
Converting PSD to Responsive HTML
Converting PSD to Responsive HTML
Just a few realy really hints and tips when it comes to website design but look for.
Just a few realy really hints and tips when it comes to website design but look for.

Leave Your Reply

*