Making a TPageControl flat in Delphi 7

后端 未结 4 1406
小鲜肉
小鲜肉 2021-02-15 16:19

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 Win

4条回答
  •  鱼传尺愫
    2021-02-15 16:55

    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.)

    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.

    Make two new declarations in your form like this:

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

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

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

    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;
    

    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.

    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.

提交回复
热议问题