Link to home
Start Free TrialLog in
Avatar of gspears060598
gspears060598

asked on

How to sublass...

I am reasonly new at the object side of Delphi.  Using D3.  I have purchased a 3rd party toolset with source, InfoPower.  They have a class, TwwDBEdit that I wish to make a similar class, but with an underline for a field instead of a complete border.  When I asked InfoPower about this, they said "I suppose you could subclass the component, and set the borderstyle to none, and have the wmpaint method paint the line the way you want..".

This is all fine and well, if I knew what I was doing... <g>. Can someone give me a shove in the right direction.  
-- Code fragments greatly appreciated --

Also, how do I get my new control to show up on the VCL controls panel.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of viktornet
viktornet
Flag of United States of America image

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
Avatar of gspears060598
gspears060598

ASKER

hi,

Your answer is just about complete.  Can you give me a little help with the wm_paint.  I was told this is what I need to use to draw the line.  I'd like it to be 3D, but I'll take what I can get.  I've tried to look up information, but haven't had a whole lot of luck yet...

Here is a code I've tried with the TLabel component.....It is not finished yet, but it will show you how to draw a 3D underlining under the caption of the label....
----------------
unit Label1;

interface

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

type
  TLabel1 = class(TLabel)
  private
    { Private declarations }
  protected
    { Protected declarations }
  public
    procedure Paint;override;
    Constructor Create(AOwner : TComponent);override;
  published
    { Published declarations }
  end;

procedure Register;

implementation
Constructor TLabel1.Create(AOwner : TComponent);
begin
  Inherited Create(AOwner);
end;

procedure TLabel1.Paint;
var
  High : Integer;
begin
  Inherited Paint;
  High := Canvas.TextHeight(Caption) + 1;
  Canvas.Pen.Color := clBtnShadow;
  Canvas.MoveTo(0, High - 1);
  Canvas.LineTo(Canvas.TextWidth(Caption),High - 1);

  Canvas.Pen.Color := clBtnHighLight;
  Canvas.MoveTo(0, High + 1);
  Canvas.LineTo(Canvas.TextWidth(Caption),High + 1);

  Canvas.Pen.Color := Font.Color;
  Canvas.MoveTo(0, High);
  Canvas.LineTo(Canvas.TextWidth(Caption),High);
end;

procedure Register;
begin
  RegisterComponents('Samples', [TLabel1]);
end;

end.
-------------
Hope this helps =)

Regards,
Viktor Ivanov