tags:

views:

644

answers:

3

Hi,

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.

NO I don't mean setting the tab style to tsButtons or tsFlatButtons

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

Is there any way to make a TpageControl flat?

EDIT:

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.

A: 

Setting borders of the sheets to 0 ? (borderwidth property)

Marco van de Voort
Nope. Tried that already. Thanks tho.
wonderer
+3  A: 

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:

FOldWndMethod := PageControl1.WindowProc;
PageControl1.WindowProc := TabWndProc;

Now implement that method and handle the tcm_AdjustRect messsage:

procedure TForm1.TabWndProc(var Msg: TMessage);
begin
  FOldWndProc(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.

Rob Kennedy
using flat buttons should do the trick. I use it often.
Hemant
Thanks, but as i mentioned on my question I don't want tsFlatButtons.
wonderer
Then use non-flat buttons. The point is that the page control goes flat when the tabs are buttons, whatever kind of buttons they are.
Rob Kennedy
OK, thanks everyone. But NO. I need to use tabs and no buttons.I was very specific in my question. I even wrote a snippet detailing how someone did it.
wonderer
and no, this is not a possible solution and i'd like to get the count back to zero on this comment but I can't.
wonderer
Well, no, you weren't specific in your question. You said that you weren't asking how to make the tabs flat. You were asking how to make the rest of the control flat. And the way you do that is by making the tabs be buttons. You didn't say that the tabs must remain looking like tabs.
Rob Kennedy
This is what I wrote:"Now, the TPageControl under Delphi has no flat property (no I don't mean setting the tabstyle to flat buttons) or the borders cannot be set to "none" and it looks pretty bad when you add a text editor into the tab control."No buttons, unless my english is not good, in which case i apologize
wonderer
Apology accepted. Set the style to tsButtons if you want. They're not flat, but they do make the rest of the control flat, and that's what you asked for.
Rob Kennedy
ok, thanks.I'm editing the question to be more specific
wonderer
Thanksthe code fails in tcm_AdjustRect what is that? and FOldTabProc: TWndMethod; should be FOldWndMethod: TWndMethod;
wonderer
ok, add CommCtrl to the units and that's it. this one works. thanks
wonderer
+1  A: 
skamradt
Thanks. But 1) I already found a solution and 2) since this is a personal program I don't see the need to pay for a compoment
wonderer