?
Solved

Best way to draw a rectangle around a control (TShape hides behind)

Posted on 2009-05-04
7
Medium Priority
?
445 Views
Last Modified: 2013-11-22
When the user hovers the mouse over a TButton (OnMouseEnter) I want to draw a box around it (actually around a few buttons).
The problem with using a TShape is that it is not a TWinControl - so it will always appear BEHIND things like TPanels, TButtons etc.
I am busy working with another solution that draws on the "DeskTopWindow" canvas, but I'm sure there must be a more direct way (such as using the Form's Canvas) but I can't seem to get it right.

Some help would be appreciated.
0
Comment
Question by:rfwoolf
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 38

Assisted Solution

by:Geert Gruwez
Geert Gruwez earned 1000 total points
ID: 24302086
why not use a bevel control ?
and then just set the bevel visible property when hovering to true
0
 
LVL 38

Assisted Solution

by:Geert Gruwez
Geert Gruwez earned 1000 total points
ID: 24302168
0
 
LVL 38

Assisted Solution

by:Geert Gruwez
Geert Gruwez earned 1000 total points
ID: 24302192
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 38

Assisted Solution

by:Geert Gruwez
Geert Gruwez earned 1000 total points
ID: 24302521
i used that uHoverHook unit to create a sample with 2 bevels and 3 buttons ...
unit Unit1;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, uHoverHook, ComCtrls;
 
type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Bevel1: TBevel;
    Bevel2: TBevel;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    fHover: THoverHook;
    procedure HoverMouseOver(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure OnHoverEnter(Sender: TObject);
    procedure OnHoverLeave(Sender: TObject);
  protected
    procedure WndProc(var Message: TMessage); override;
  public
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.dfm}
 
procedure TForm1.FormCreate(Sender: TObject);
begin
  //fHover := THoverHook.Create(HoverMouseOver, True);
  fHover := THoverHook.Create;
  fHover.OnMouseMove := HoverMouseOver;
  fHover.StartHook;
  fHover.AddToHook(Button1);
  fHover.AddToHook(Button2);
  fHover.AddToHook(Button3);
end;
 
procedure TForm1.HoverMouseOver(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  Bevel1.Visible := (Sender = Button1) or (Sender = Button3);
  Bevel2.Visible := (Sender = Button2);
end;
 
procedure TForm1.FormDestroy(Sender: TObject);
begin
  FreeAndNil(fHover);
end;
 
procedure TForm1.WndProc(var Message: TMessage);
var X: TObject;
begin
  inherited WndProc(Message);
  if (Message.Msg = CM_MOUSEENTER) or (Message.Msg = CM_MOUSELEAVE) then
  begin
    X := ControlAtPos(Mouse.CursorPos, False, True);
    if Message.Msg = CM_MOUSEENTER then
      OnHoverEnter(X)
    else
      OnHoverLeave(X);
  end;
end;
 
procedure TForm1.OnHoverEnter(Sender: TObject);
begin
end;
 
procedure TForm1.OnHoverLeave(Sender: TObject);
begin
  Bevel1.Visible := False;
  Bevel2.Visible := False;
end;
 
end.

Open in new window

0
 
LVL 13

Accepted Solution

by:
rfwoolf earned 0 total points
ID: 24309268
Hi Geert

The bevel solution is unideal because Bevels are not transparent. Of course you could put the bevels behind the buttons, but that is unideal in my case because I have some buttons that fit exactly onto a panel.

I am not sure why everyone is obsessed with 'hovering' in those links you gave me - I can just use the MouseEnter and the MouseLeave events for buttons to detect when the mouse is hovering over the button and when it is not.

And so again it looks like my best solution is to draw on the form's canvas, but that is creating a huge headache because of the titlebar and border!!


Aurrrghh.
0
 
LVL 26

Assisted Solution

by:EddieShipman
EddieShipman earned 1000 total points
ID: 24549098
There is a set of controls written by an ex-colleague calle Res-cue controls. They have this capability and you can
learn how he does it and do it with your own controls. I can attach them if you'd like...
0
 
LVL 26

Assisted Solution

by:EddieShipman
EddieShipman earned 1000 total points
ID: 24549142
From his help file:
"The Focus Technology is a powerful programming technique that allows developers to give a visual cue when a control receives focus.  No more searching for the control that has focus, our Focus Technology draws a rectangle around the control that has focus and can even change the Font attributes of a label for the control.  Developers are given the flexibility to change the appearance of the rectangle by providing many properties that can be altered such as spacing, color, 3D, etc.  In addition, we provide events for when a focus rectangle and label are about to be painted or removed from the screen so that developers can provide other visual cues to the user as to which control has focus.

Another powerful feature of our Focus Technology is the ability to use this technology on any TWinControl.  Thats right, you dont have to replace your current controls in your application to use the great feature.  Simply place a TrscMasterFocus component on a form and select the controls that you want to have this capability.  It is as simple as that."

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question