Link to home
Start Free TrialLog in
Avatar of fadyg
fadyg

asked on

adding context help for labels ?

Is there a way to add a contextID to a label and have it react to context help request (help by pressing the ? button in form title) ?

of course without rewriting tcustomLabel as a subclass of tWinControl
Avatar of mullet_attack
mullet_attack

It would seem not. It looks like the Windoze help system uses:
"The GetWindowContextHelpId function retrieves the help context identifier, if any, associated with the specified window." Seeing as only descendants of TWincontrol are windows, that explains why only they have HelpContextIDs. Bummer.

You could use a Tedit with BorderStyle = none, readonly = true, and colour = background to look like a label. Be OK I think if you only had a couple...
ASKER CERTIFIED SOLUTION
Avatar of rwilson032697
rwilson032697

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I love those simple answers !

cheers to _you_, Raymond :-)
I do what I can :o)
Avatar of fadyg

ASKER

yes but then I will lose two features that I use in my Tlabel subclass: WordWrap and multiline.

This implies that I will have to rewrite the paint of staticlabel to regain those features.

Any simpler solution ?
Yep !

Since Raymond pointed me at the TStaticText control, and it's a window control, all you need to do is add ES_MULTILINE and remove ES_AUTOHSCROLL from the windows style and recreate the handle. Code below...

I changed the TEXT property to be CAPTION to look more like a label, but unfortunately the text in the control doesn't change when you edit the CAPTION property in the property editor. If you don't like that, just remove the caption property, and publish the text property.

That's all there is to it.

-----------------------------------
unit MyLabel;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TMyLabel = class(TCustomEdit)
  private
    FWordWrap: boolean;
    procedure SetWordWrap(const Value: boolean);
    procedure SetCaption(const Value: string);
    function GetCaption : string;
    { Private declarations }
  protected
    procedure CreateParams(var Params: TCreateParams); override;
  public
    Constructor Create(AOwner : TComponent);override;
    { Public declarations }
  published
    property WordWrap : boolean read FWordWrap write SetWordWrap;
    property Caption : string read GetCaption write SetCaption;
    property Anchors;
    property AutoSelect;
    property AutoSize;
    property BiDiMode;
    property CharCase;
    property Color;
    property Constraints;
    property Ctl3D;
    property DragCursor;
    property DragKind;
    property DragMode;
    property Enabled;
    property Font;
    property HideSelection;
    property ImeMode;
    property ImeName;
    property MaxLength;
    property OEMConvert;
    property ParentBiDiMode;
    property ParentColor;
    property ParentCtl3D;
    property ParentFont;
    property ParentShowHint;
    property PasswordChar;
    property PopupMenu;
    property ShowHint;
    property TabOrder;
    property TabStop;
    property Visible;
    property OnChange;
    property OnClick;
    property OnContextPopup;
    property OnDblClick;
    property OnDragDrop;
    property OnDragOver;
    property OnEndDock;
    property OnEndDrag;
    property OnEnter;
    property OnExit;
    property OnKeyDown;
    property OnKeyPress;
    property OnKeyUp;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
    property OnStartDock;
    property OnStartDrag;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Planetech', [TMyLabel]);
end;

{ TMyLabel }

constructor TMyLabel.Create(AOwner: TComponent);
begin
  inherited;
  BorderStyle := bsNone;
  Readonly := true;
  ParentColor := True;
end;

procedure TMyLabel.CreateParams(var Params: TCreateParams);
const
  WordWraps: array[Boolean] of DWORD = (0, ES_AUTOHSCROLL);
begin
  inherited CreateParams(Params);
  with Params do
    Style := Style and not WordWraps[FWordWrap] or ES_MULTILINE;
end;

function TMyLabel.GetCaption: string;
begin
  result := inherited Text;
end;

procedure TMyLabel.SetCaption(const Value: string);
begin
  inherited Text := Value;
end;

procedure TMyLabel.SetWordWrap(const Value: boolean);
begin
  FWordWrap := Value;
  ReCreateWnd;
end;

end.
Avatar of fadyg

ASKER

Ok, great! now where do we stand with the points ? You both deserve them..

I've never dealt with 2 experts solving one problem. How is it usually solved guys?

anyway thanks to both of you.

Fady
Raymond, you're the 'senior expert' !
What's the answer? :-)
Avatar of fadyg

ASKER

Hey guys, still alive ?
I'm alive ! (well mostly :-))

Raymond?
Fady: Well, its usually up to you! If you feel one expert solved the problem in the best way for you then you can reward that expert (regardless of whether another expert has posted an answer).

Alternatively, if you want to share points you need to create 'dummy' Q's with the appropriate point sharing for the experts you want to reward. You can then delete this Q to reclaim the points.

Cheers,

Raymond.
Avatar of fadyg

ASKER

I will Actually accept this one (after all it solved my problem) and ask another dummy question (50 pts) to Mullet Attack who helped me in a different way (I used his advice for another component)

thanks to both again
thanks!
Your welcome!

Raymond.