移除/隐藏 TTrackBar 的边框

huangapple go评论68阅读模式
英文:

Remove / Hide border of TTrackBar

问题

我在我的表单上有一个TTrackBar,但我希望它没有边框:

移除/隐藏 TTrackBar 的边框

也就是说,只有蓝色箭头应该可见 - 边框(以及内容,即箭头导航的区域)应该是不可见的(如果需要,可以通过将颜色设置为clBtnFace来解决)。

我尝试了许多方法来隐藏它(在覆盖的Create构造函数中):

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

但似乎没有任何效果。

有办法实现我的目标吗?

英文:

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

移除/隐藏 TTrackBar 的边框

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?

答案1

得分: 4

我相信你可以重写滑动条的CNNotify消息方法来处理NM_CUSTOMDRAW通知,当dwDrawStage = CDDS_ITEMPREPAINTdwItemSpec = TBCD_CHANNEL时,将结果设置为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;

不要忘记设置ShowSelRange = FalseTickStyle = tsNone

英文:

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;

移除/隐藏 TTrackBar 的边框

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

huangapple
  • 本文由 发表于 2023年2月23日 20:30:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/75544863.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定