为什么我无法在启用主题的 Delphi 7 中的 TSpeedButtons 上设置字体?

发布于 2024-09-27 18:54:00 字数 1666 浏览 3 评论 0原文

发生了非常奇怪的事情:

我有一大堆 TFrame(可能是 TCustomFrame,不记得了,因为我在 40 个奇数帧和父级之间创建了一个中间类),我继承了它们来构成 '非常酷的 HL7 公式编辑器。奇怪但不是重点的是,框架上的 DFM 不断向 DFM 添加 OldCreateOrder、PixelsPerInch 和 TextHeight,即使我从未在基类中实现这些属性。

不管怎样,即使我不想,我也必须将这些属性放入我的子类中,否则它不会让我编译,所以很好。然后我将其中一个颜色选择器控件添加到我的一个框架中,直到上周它才开始给我带来无法找到父级的麻烦。

所以...我摆脱了所有 DFM,将所有框架更改为面板,它工作正常(在我的计算机上,在没有主题的 VM 中运行 XP),但是对于我左边的同事对我来说(本地运行 Windows 7),我在这些面板上使用 TSpeedButtons 做什么并不重要,它们总是具有相同的 Sans 10pt Bold 字体,这可以工作,但我有一些用于设置操作的奇怪符号,我'我想保留,但 CalcTextWidth 完全失败。

我试过:

  • ParentFont := true and false;
  • Flat := true and false;
  • Parent.Font := What;

就足够了说吧,我已经尝试了所有的老招数。唯一有效的就是删除 XP Manifest(我是否提到过这是 Delphi 7)。这不是一个选择,因为今年的某个时候我们会将所有内容移植到 D2009,而那......不会是一个选择!

编辑

真正奇怪的是,使用 TFrame 和 DFM,它可以工作(即使使用古老的编译器)。使用 TPanel 不起作用。

TPanel(或 TCustomPanel,两者都不起作用)上的主题与 TFrame 上的主题之间肯定存在一些差异。

另外,我在按钮和 TPanel 之间有一个 TGroupBox。也许这就是问题所在。我可以很容易地改变这一点。

编辑2

使用按钮、extctrls、stdctrls

(对于Delphi 7,将XPManifest放在表单上)

procedure TForm1.FormCreate(Sender: TObject);
var
  Panel : TPanel;
  Grp : TGroupBox;
  Btn : TSpeedButton;
begin
  Panel := TPanel.Create(Self);
  Panel.Parent := self;
  Panel.Align := alClient;

  Grp := TGroupBox.Create(Panel);
  Grp.Parent := Panel;
  Grp.Align := alClient;

  Btn := TSpeedButton.Create(Grp);
  Btn.Parent := Grp;

  Btn.Width := 117;
  Btn.Font.Name := 'Symbol';
  Btn.Caption := 'Here is some text';


end;

在Windows XP中很好,在2008 Server R2上尝试过,只显示粗体无字体。

我在没有中间组框的情况下尝试了这个,但它似乎有效。

(用框架来做,但是代码太多,无法发布)

Very strange thing happening:

I had a whole bunch of TFrame's (might have been TCustomFrame, don't remember because I made an intermediate class between the 40 odd frames and the parent) that I was inheriting to make up the configuration part of a 'really cool' HL7 formula editor. What was weird, but not to the point, was that the DFM on the frame kept on adding OldCreateOrder, PixelsPerInch and TextHeight to the DFM, even though I never implemented those properties in the base class.

Anyway, I had to put those properties in my subclass even though I didn't want to, or else it wouldn't let me compile, so fine. Then I added one of those Color Chooser controls to one of my frames, and that worked until last week when it started giving me the business about not being able to find the parent.

So... I got rid of all my DFM's I changed all the Frames to Panels and it works fine (on my computer, running XP in VM with no themes), but for my colleague to the left of me (running Windows 7 natively) it doesn't matter what I do with TSpeedButtons on these Panels, they always have the same Sans 10pt Bold font, which would work, but I've got some weird symbols for set operations which I'd like to retain and CalcTextWidth totally fails.

I've tried:

  • ParentFont := true and false;
  • Flat := true and false;
  • Parent.Font := Whatever;

Suffice it to say, I've tried all the old tricks. The only thing that works is just removing the XP Manifest (did I mention this is Delphi 7). And that's not an option because sometime this year we're going to port everything over to D2009 and that... won't be an option!

Edit

The really strange thing is that using TFrame and a DFM, it works (even with an ancient compiler). Using TPanel it doesn't work.

There must be some difference between themes on a TPanel (or TCustomPanel, neither worked) and themes on a TFrame.

Also, I've got a TGroupBox between the buttons and the TPanel. Maybe that's causing the problem. I could change that pretty easy.

Edit 2

uses buttons, extctrls, stdctrls

(for Delphi 7, put XPManifest on your form)

procedure TForm1.FormCreate(Sender: TObject);
var
  Panel : TPanel;
  Grp : TGroupBox;
  Btn : TSpeedButton;
begin
  Panel := TPanel.Create(Self);
  Panel.Parent := self;
  Panel.Align := alClient;

  Grp := TGroupBox.Create(Panel);
  Grp.Parent := Panel;
  Grp.Align := alClient;

  Btn := TSpeedButton.Create(Grp);
  Btn.Parent := Grp;

  Btn.Width := 117;
  Btn.Font.Name := 'Symbol';
  Btn.Caption := 'Here is some text';


end;

In windows XP fine, tried on 2008 Server R2 and just shows bold sans font.

I tried this without the Group Box in between and it seems to work though.

(doing it with the frame works, but is too much code to post)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

娇妻 2024-10-04 18:54:00

Delphi 7 于 2002 年 8 月发布。Vista 于 2007 年发布,Windows 7 于 2009 年发布。我认为期望 2002 年的编译器和开发系统能够与 Vista/7 中的所有新功能一起工作有点太令人期待了。升级后您可能会看到一切正常。

当然,升级编译器,尤其是大型应用程序的编译器,绝非易事。

我确实同情你,但我不会称其为 VCL 中的错误。

Delphi 7 was released in August of 2002. Vista came out in 2007 and Windows 7 in 2009. I think to expect a compiler and dev system from 2002 to work with all the new stuff in Vista/7 is a bit much to expect. Upgrade and you will probably see things work.

Of course, upgrading a compiler, particularly for a large application, is never easy.

I do feel for you, but I would not call it a bug in the VCL.

甜警司 2024-10-04 18:54:00

我先尝试为你回答这个问题:

有什么奇怪的,但不是重点,
是框架上的 DFM 保持开启状态
添加 OldCreateOrder、PixelsPerInch
和 TextHeight 到 DFM,即使
我从未实现过这些属性
在基类中。

这可能与

Frame 继承有关

  1. (您的 DFM 文件包含错误的关键字:object 而不是 inherited,请参阅 此博客文章)

  2. 您的 .DPR 文件,其中 Frame 单元后面的注释是错误的( comment 实际上不是注释,它是 Delphi IDE 的一个提示,告诉它需要选择哪个框架、表单或数据模块设计器)

让我们知道这是否有帮助;然后重点关注TSpeedButton问题。

——杰罗恩

I'll try to answer this question for you first:

What was weird, but not to the point,
was that the DFM on the frame kept on
adding OldCreateOrder, PixelsPerInch
and TextHeight to the DFM, even though
I never implemented those properties
in the base class.

This might have to do with either

  1. Frame inheritance (your DFM file contains the wrong keyword: object in stead if inherited, see this blog posting)

  2. Your .DPR file where the comment behind your Frame unit is wrong (the comment actually is not a comment, it is a hint to the Delphi IDE to tell it which frame, form or datamodule designer it needs to choose)

Let us know if that helps; then focus on the TSpeedButton problem.

--jeroen

顾忌 2024-10-04 18:54:00

好的,这是有效的答案:

groupbox.ParentBackground := false

不确定为什么组框的背景会改变速度按钮的前景。

OK, here's the answer that worked:

groupbox.ParentBackground := false

Not sure why the background of the group box changes the foreground of the speed button.

凉宸 2024-10-04 18:54:00

好吧,我会写一个我自己的问题的答案,因为今天的答案不是升级。

只需重写 TSpeedButton 中的 Paint 函数即可,无论如何您都不会在表单上使用它。

然后,当您最终将所有 1200 万行代码更新到 D2009 时,如果问题再次出现,那么如果您不想要子类 TSpeedButton,则可以将该代码保留为那些奇特的帮助器类函数之一。

Well, I'll write an answer to my own question, because today's answer isn't upgrade.

Just override the Paint function in the TSpeedButton, you're not using it on the form anyway.

Then, when you finally do update all 12 million lines of code to D2009, if is problem occurs again, then you can keep that code as one of those fancy helper class functions if you don't want subclass TSpeedButton.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文