Making a TPageControl flat in Delphi 7

后端 未结 4 1405
小鲜肉
小鲜肉 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:49

    Drop two TPageControls, one with tabs as Tabs, with a global height equal to the tabs, and one with flatbuttons and Tabvisible properties set to false, which would be aligned under the first one. Then make sure the tab change on the first TPagecontrol makes the tabs also change in the second one.

    0 讨论(0)
  • 2021-02-15 16:53

    You could always use a commercial solution. I would strongly recommend Raize components, which support flat TPageControls with tabs. The component set is very easy to work with, and supports numerous visual enhancements which in my opinion give a better feel to any application.


    (source: raize.com)

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2021-02-15 16:55

    I'm using Delphi XE8 and the following seems to do the trick:

    ATabControl.Tabs.Clear;
    ATabControl.Style := TTabStyle.tsFlatButtons;
    ATabControl.Brush.Color := clWhite;
    
    0 讨论(0)
提交回复
热议问题