3

I have a TTrackBar on my form, but would like it to not have the border around it:

Trackbar with Outline Border

ie. only the blue arrow should be visible - the border (and the content, ie the area that the arrow navigates in) should be invisible (could be solved by setting the color to clBtnFace if need be).

I have tried many things to hide this (in an overridden Create CONSTRUCTOR):

BevelEdges:=[];
BevelInner:=TBevelCut.bvNone;
BevelOuter:=TBevelCut.bvNone;
BevelKind:=TBevelKind.bkNone;
BorderWidth:=0;
Brush.Color:=clBtnFace;
ParentCtl3D:=FALSE;
Ctl3D:=FALSE;

but it doesn't appear to make any difference.

Is there a way to achieve my goal?

HeartWare
  • 7,464
  • 2
  • 26
  • 30
  • It looks like it's using a Windows control, so not everything can be changed. Have a look [here](https://learn.microsoft.com/en-us/windows/win32/controls/bumper-trackbar-control-reference-messages) for messages. Read each one and try anything that looks promising. Otherwise you will have to find a 3rd party control or roll your own. – Rohit Gupta Feb 23 '23 at 13:05
  • 2
    Look at TTrackBar.CNNotify method under TBCD_CHANNEL. Modifying size of R rectangle should have the desired effect. I never tried to completely remove it, I am just painting it 2 pixels in width. I would post the code, but it is entangled with some other custom things and I don't have time now to clear the parts and test. – Dalija Prasnikar Feb 23 '23 at 15:10
  • 2
    @DalijaPrasnikar: I tried setting the rect to the empty rect, and it seems to work. – Andreas Rejbrand Feb 23 '23 at 16:55
  • @AndreasRejbrand if you have working example you can post as answer. – Dalija Prasnikar Feb 23 '23 at 18:46
  • 1
    @DalijaPrasnikar: It seems to me like it is better to simply set `Message.Result := CDRF_SKIPDEFAULT` when you are about to draw the channel, isn't it? – Andreas Rejbrand Feb 23 '23 at 19:39

1 Answers1

4

I believe you can override the track bar's CNNotify message method to handle the NM_CUSTOMDRAW notification when dwDrawStage = CDDS_ITEMPREPAINT and dwItemSpec = TBCD_CHANNEL, setting the result to CDRF_SKIPDEFAULT:

procedure TTrackBar.CNNotify(var Message: TWMNotifyTRB);
begin

  if
    (Message.NMHdr.code = NM_CUSTOMDRAW)
      and
    (Message.NMCustomDraw.dwDrawStage = CDDS_ITEMPREPAINT)
      and
    (Message.NMCustomDraw.dwItemSpec = TBCD_CHANNEL)
  then
    Message.Result := CDRF_SKIPDEFAULT
  else
    inherited;

end;

Screenshot of channel-less track bar control.

Don't forget to set ShowSelRange = False and TickStyle = tsNone.

Andreas Rejbrand
  • 105,602
  • 8
  • 282
  • 384