在Delphi 7中制作一个TPageControl平台 [英] Making a TPageControl flat in Delphi 7

查看:273
本文介绍了在Delphi 7中制作一个TPageControl平台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道这个问题是否可以在这里回答,但我希望会这样。
我在Delphi 7中编写了一个简单的文本编辑器,作为我在Windows下编写C代码的主要IDE。我在虚拟机中运行Windows,我需要一些光。
无论如何,只要您打开或创建新文件,它将使用一个TpageControl获取新的选项卡。漂亮的标准
现在,Delphi下的TPageControl没有平面属性。

I don't know whether this question can be answered here, but I hope it will. I wrote a simple text editor in Delphi 7 that serves as my primary IDE for writing C code under Windows. I run Windows in a VM and I needed something light. In any case, it uses a TpageControl that gets a new tab whenever you open or create a new file. Pretty standard. Now, the TPageControl under Delphi has no flat property.

不,我不是指将标签样式设置为tsButtons或tsFlatButtons

边框不能设置为无,并且当您在标签控件中添加文本编辑器时,它看起来很糟糕。

the borders cannot be set to "none" and it looks pretty bad when you add a text editor into the tab control.

有没有办法使TpageControl平?

Is there any way to make a TpageControl flat?

编辑

在开源的PageControl中,我发现:

On an open source PageControl that supports flat here's what I found:

procedure TCustomTabExtControl.WndProc(var Message: TMessage);
begin
  if(Message.Msg=TCM_ADJUSTRECT) and (FFlat) then
   begin
    Inherited WndProc(Message);
    Case TAbPosition of
    tpTop : begin
    PRect(Message.LParam)^.Left:=0;
    PRect(Message.LParam)^.Right:=ClientWidth;
    PRect(Message.LParam)^.Top:=PRect(Message.LParam)^.Top-4;
    PRect(Message.LParam)^.Bottom:=ClientHeight;
  end;
    tpLeft : begin
    PRect(Message.LParam)^.Top:=0;
    PRect(Message.LParam)^.Right:=ClientWidth;
    PRect(Message.LParam)^.Left:=PRect(Message.LParam)^.Left-4;
    PRect(Message.LParam)^.Bottom:=ClientHeight;
  end;
    tpBottom : begin
    PRect(Message.LParam)^.Left:=0;
    PRect(Message.LParam)^.Right:=ClientWidth;
    PRect(Message.LParam)^.Bottom:=PRect(Message.LParam)^.Bottom-4;
    PRect(Message.LParam)^.Top:=0;
  end;
    tpRight : begin
    PRect(Message.LParam)^.Top:=0;
    PRect(Message.LParam)^.Left:=0;
    PRect(Message.LParam)^.Right:=PRect(Message.LParam)^.Right-4;
    PRect(Message.LParam)^.Bottom:=ClientHeight;
    end;
  end;
 end else Inherited WndProc(Message);

end;

事情是当我在主应用程序上尝试类似的东西,它将无法工作。它甚至不会编译。

The thing is when I tried something similar on the main application it won't work. It won't even compile.

推荐答案

当标签绘制为按钮时,显示区域周围没有绘制边框,因此设置 Style property to tsButtons tsFlatButtons 。 (对于非VCL程序员,这相当于包括 tcs_Buttons 选项卡控件上的窗口样式。)

When the tabs are drawn as buttons, no border is drawn around the display area, so set the Style property to tsButtons or tsFlatButtons. (For non-VCL programmers, this is equivalent to including the tcs_Buttons window style on the tab control.)

另一种方法是使用 TNotebook 。它拥有页面,但它根本不做任何绘画。您必须自己提供标签,例如通过将标签控件的高度设置为等于制表符的高度,或使用 TTabSet 。 ( TTabSet 在Delphi 2005中可用;我不知道Delphi 7。)

An alternative is to use a TNotebook. It holds pages, but it doesn't do any painting at all. You'd have to provide the tabs yourself, such as by setting the tab control's height equal to the height of the tabs, or by using a TTabSet. (TTabSet is available in Delphi 2005; I'm not sure about Delphi 7.)

关于代码发现,如果您指出为什么它不编译,或者如果您链接到您发现的位置,那么这是有帮助的,因为我认为编译错误是因为它引用了定制类的字段或属性,而不是库存一。以下是您可以尝试将其放在自己的代码中,而无需编写自定义控件。

Regarding the code you found, it would be helpful if you indicated why it doesn't compile, or if you gave a link to where you found it, since I suppose the compilation error was because it refers to fields or properties of the custom class rather than the stock one. Here's what you can try to put it in your own code, without having to write a custom control.

在您的表单中创建两个新的声明像这样:

FOldTabProc: TWndMethod;
procedure TabWndProc(var Msg: TMessage);

在窗体的 OnCreate 事件处理程序中,该方法到页面控件的 WindowProc 属性:

In the form's OnCreate event handler, assign that method to the page control's WindowProc property:

FOldTabProc := PageControl1.WindowProc;
PageControl1.WindowProc := TabWndProc;

现在实现该方法并处理 tcm_AdjustRect 消息:

Now implement that method and handle the tcm_AdjustRect messsage:

procedure TForm1.TabWndProc(var Msg: TMessage);
begin
  FOldTabProc(Msg);
  if Msg.Msg = tcm_AdjustRect then begin
    case PageControl1.TabPosition of
      tpTop: begin
        PRect(Msg.LParam)^.Left := 0;
        PRect(Msg.LParam)^.Right := PageControl1.ClientWidth;
        Dec(PRect(Msg.LParam)^.Top, 4);
        PRect(Msg.LParam)^.Bottom := PageControl1.ClientHeight;
      end;
    end;
  end;
end;

如果需要,您可以填写其他三种情况。 Tcm_AdjustRect 是在 CommCtrl 单元中声明的消息标识符。如果您在该单元中没有该消息,请自己声明;它的值是4904。

You can fill in the other three cases if you need them. Tcm_AdjustRect is a message identifier declared in the CommCtrl unit. If you don't have that message in that unit, declare it yourself; its value is 4904.

我怀疑这不会阻止控件绘制其边框。相反,它导致包含的 TTabSheet 增长一点,覆盖边界。

I suspect this doesn't stop the control from drawing its borders. Rather, it causes the contained TTabSheet to grow a little bigger and cover up the borders.

这篇关于在Delphi 7中制作一个TPageControl平台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆