Delphi 工具按钮(TToolbutton)的剥离效果
我正在尝试从使用 Toolbar2000 切换到常规工具栏,因为似乎没有 Delphi XE2 版本,而且看起来它使用了一些程序集,如果我不这样做的话,我只是不想处理它必须。 (我真的很喜欢 Delphi 工具栏的淡入效果)
但是,我不喜欢的是按钮的背景得到了常规的蓝色按钮处理。我知道如何更改颜色,但是我可以不更改颜色并且不在按钮周围绘制边框吗?
我已经实现了“OnAdvancedCustomDrawButton”,但可用的标志似乎无法正常工作,我不确定它们如何与渐变颜色和热轨道颜色交互,最终我得到了一些奇怪的闪烁或奇怪的黑色背景。
这是我创建工具栏的方式
ToolBar1 := TToolBar.Create(Self);
ToolBar1.DoubleBuffered := true;
ToolBar1.OnAdvancedCustomDrawButton := Toolbar1CustomDrawButton;
ToolBar1.Transparent := false;
ToolBar1.Parent := Self;
ToolBar1.GradientEndColor := $7ca0c2; //RGB(194, 160, 124);
ToolBar1.GradientStartColor := $edeeed; //RGB(237, 238, 124);
ToolBar1.Indent := 5;
ToolBar1.Images := Normal;
ToolBar1.DrawingStyle := dsGradient;
ToolBar1.HotImages := Over;
ToolBar1.AutoSize := True;
ToolBar1.Visible := False;
,这是我创建按钮的方式(循环):
ToolButton := TToolButton.Create(ToolBar1);
ToolButton.Parent := ToolBar1;
ToolButton.ImageIndex := ToolButtonImages[Index].ImageIndex;
ToolButton.OnClick := ToolButtonClick;
这是我的 AdvancedCustomDrawButton 函数
procedure TMyForm.Toolbar1CustomDrawButton(Sender: TToolBar; Button: TToolButton;
State: TCustomDrawState; Stage: TCustomDrawStage;
var Flags: TTBCustomDrawFlags; var DefaultDraw: Boolean);
begin
Flags := [tbNoEdges, tbNoOffset];
DefaultDraw := True;
end;
I'm attempting to switch from using Toolbar2000 to the regular toolbar because there doesn't seem to be a Delphi XE2 version and it looks like it uses some Assembly and I just don't really want to deal with it if I don't have to. (and I really like the fade-in effect with the Delphi Toolbar)
But, what I don't like is that the background of the button gets the regular blueish button treatment. I know how to change the color, but can I just not make the color change and not have a border painted around the button?
I've implemented the 'OnAdvancedCustomDrawButton' but the flags available don't seem to work right and I'm not sure how they interact with the gradient color and the hot track color and I wind up having some weird flashing or weird black backgrounds.
Here's how I'm creating the Toolbar
ToolBar1 := TToolBar.Create(Self);
ToolBar1.DoubleBuffered := true;
ToolBar1.OnAdvancedCustomDrawButton := Toolbar1CustomDrawButton;
ToolBar1.Transparent := false;
ToolBar1.Parent := Self;
ToolBar1.GradientEndColor := $7ca0c2; //RGB(194, 160, 124);
ToolBar1.GradientStartColor := $edeeed; //RGB(237, 238, 124);
ToolBar1.Indent := 5;
ToolBar1.Images := Normal;
ToolBar1.DrawingStyle := dsGradient;
ToolBar1.HotImages := Over;
ToolBar1.AutoSize := True;
ToolBar1.Visible := False;
and here's how I'm creating the buttons (in a loop):
ToolButton := TToolButton.Create(ToolBar1);
ToolButton.Parent := ToolBar1;
ToolButton.ImageIndex := ToolButtonImages[Index].ImageIndex;
ToolButton.OnClick := ToolButtonClick;
and here's my AdvancedCustomDrawButton function
procedure TMyForm.Toolbar1CustomDrawButton(Sender: TToolBar; Button: TToolButton;
State: TCustomDrawState; Stage: TCustomDrawStage;
var Flags: TTBCustomDrawFlags; var DefaultDraw: Boolean);
begin
Flags := [tbNoEdges, tbNoOffset];
DefaultDraw := True;
end;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在自定义绘制处理程序中将工具栏的绘制样式设置为 dsNormal 并将
Flags
设置为 [tbNoEdges]。更新:
虽然上述方法适用于 2K 和 XP,但 Vista 和 7 在未绘制按钮背景时似乎不会绘制边框。不幸的是,使用 VCL 提供的 TTBCustomDrawFlags 来实现这一点是不可能的,因此我们无法消除自定义绘图处理程序中的边框。
如果工具栏位于表单本身上,我们可以为
WM_NOTIFY
放置一个处理程序,因为通知消息被发送到父窗口:如果工具栏是另一个窗口(如面板)的父窗口,那么我们需要子类化工具栏:(
请注意,绘图样式仍然需要为
dsNormal
。)使用此解决方案,您不需要为自定义绘图放置处理程序。但如果你需要/想要,你可能需要将
Msg.Result
与一个 VCL 的窗口过程返回进行“或”,即“case”看起来像:当我们处理时也是如此表单上的 WM_NOTIFY。
可能还有其他方法可以实现相同的目的,自定义绘图是一个广泛的主题。如果您想深入研究它,我建议您从以下链接开始解决手头的问题:
关于自定义绘制
NM_CUSTOMDRAW(工具栏)通知代码< br>
NMCUSTOMDRAW 结构
NMTBCUSTOMDRAW 结构
Set drawing style of the toolbar to
dsNormal
and setFlags
to [tbNoEdges] in custom draw handler.update:
While the above works for 2K and XP, Vista and 7 seem to not to draw the border when button background is not drawn. Unfortunately achieving this with the VCL supplied
TTBCustomDrawFlags
is impossible, so we cannot get rid of the borders in a custom drawing handler.If the toolbar is on the form itself we can put a handler for
WM_NOTIFY
since notification messages are sent to the parent window:If the toolbar is parented in another window, like a panel, then we need to subclass the toolbar:
(Note that drawing style still needs to be
dsNormal
.)With this solution you don't need to put a handler for custom drawing. But if you need/want to anyway, you might need to 'or' the
Msg.Result
with the one VCL's window procedure returns, i.e the 'case' would look like:same goes for when we handle WM_NOTIFY on the form.
There may be other ways to achieve the same, custom drawing is a broad topic. If you want to delve into it, I suggest you to start from the links below for the problem at hand:
About Custom Draw
NM_CUSTOMDRAW (toolbar) notification code
NMCUSTOMDRAW structure
NMTBCUSTOMDRAW structure