在Delphi 7中制作TPageControl

won*_*rer 8 delphi

我不知道这个问题是否可以在这里得到解答,但我希望它会.我在Delphi 7中编写了一个简单的文本编辑器,它是我在Windows下编写C代码的主要IDE.我在VM中运行Windows,我需要一些简单的东西.在任何情况下,它都使用TpageControl,只要您打开或创建新文件,它就会获得一个新选项卡.很标准.现在,Delphi下的TPageControl没有平面属性.

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

边框不能设置为"none",当您将文本编辑器添加到选项卡控件时,它看起来非常糟糕.

有没有办法让TpageControl保持平坦?

编辑:

在支持平板的开源页面控件上我发现了:

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;
Run Code Online (Sandbox Code Playgroud)

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

Rob*_*edy 12

当选项卡绘制为按钮时,显示区域周围不会绘制边框,因此将Style属性设置为tsButtonstsFlatButtons.(对于非VCL程序员,这相当于tcs_Buttons在选项卡控件上包含窗口样式.)

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

关于你找到的代码,如果你指出它为什么不编译,或者你给了你找到它的链接,那将会很有帮助,因为我认为编译错误是因为它引用了自定义类的字段或属性而不是股票.以下是您可以尝试将其放入自己的代码中,而无需编写自定义控件.

表单中创建两个新的声明,如下所示:

FOldTabProc: TWndMethod;
procedure TabWndProc(var Msg: TMessage);
Run Code Online (Sandbox Code Playgroud)

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

FOldTabProc := PageControl1.WindowProc;
PageControl1.WindowProc := TabWndProc;
Run Code Online (Sandbox Code Playgroud)

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

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;
Run Code Online (Sandbox Code Playgroud)

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

我怀疑这并不能阻止控件绘制边框.相反,它会使包含物TTabSheet变得更大并掩盖边界.