德尔福玻璃上的Chrome浏览器风格标签 [英] Google Chrome style tabs on glass in Delphi

查看:223
本文介绍了德尔福玻璃上的Chrome浏览器风格标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试在Windows 7中,在Delphi应用程序中实现Google Chrome样式选项卡。




  • 标签可能会延伸到非Chrome客户端区域,就像在谷歌Chrome本身一样。

  • 在Vista和Windows 7上正确绘制当玻璃启用时

  • 选项卡的工作方式就像Google Chrome,并且像Google Chrome一样,在玻璃上。





我发现我必须克服的挑战是:




  • 如何获取控件(VCL控件)扩展到非客户区?
    (一个控件的一个很好的例子,这是一个功能区控件包含在VCL源中,但是我还没有看到任何人这样做,并且需要一些邪恶的黑客来使功能区起作用) li>
  • 如何在玻璃上正确绘制位图? (DWM API)。 相关问题已经回答了这个问题,在这里,我也问过这个问题。


解决方案

你不想要一个完整的玻璃窗口,但你必须自己绘制标签,因为没有一个控制,我知道,这将给你确切的外观寻找。如果您使用当前窗体的GlassFrame属性,请启用它并将顶部设置为要为选项卡设置的高度,在此区域上放置一个paintbox,并使用GDI +调用手动绘制选项卡。在EDN上可以使用一个适合此功能的图书馆( http://cc.embarcadero .com / Download.aspx?id = 26950 )。不用GDI +就可以画到画框,但黑色会变得透明。使用GDI +,您可以随意绘制任何颜色的玻璃。例如:





资料来源:

  unit Unit6; 

接口

使用
Windows,消息,SysUtils,变体,类,图形,控件,窗体,
对话框,GdiPlusHelpers,GdiPlus,StdCtrls, ExtCtrls;

type
TForm6 = class(TForm)
pb1:TPaintBox;
procedure pb1Paint(Sender:TObject);
private
{私人声明}
public
{公开声明}
end;

var
Form6:TForm6;

实现

{$ R * .dfm}

程序TForm6.pb1Paint(发件人:TObject);
var
图形:IGPGraphics;
画笔:IGPSolidBrush;
FontFamily:IGPFontFamily;
字体:IGPFont;
点:TGPPointF;
笔:IGPPen;
begin
图形:= Pb1.ToGPGraphics;
刷:= TGPSolidBrush.Create(TGPColor.Create(255,0,0,0));
FontFamily:= TGPFontFamily.Create('Consolas');
字体:= TGPFont.Create(FontFamily,12,FontStyleRegular,UnitPoint);
Point.Initialize(1,0);
Graphics.TextRenderingHint:= TextRenderingHintAntiAlias;
Graphics.DrawString('GDI + Black Text',Font,Point,Brush);
笔:= TGPPen.Create(TGPColor.Create(255,0,0,0));
Graphics.DrawLine(Pen,0,0,200,100);
结束

结束。

表单:

 code>对象Form6:TForm6 
Left = 0
顶部= 0
Caption ='Form6'
ClientHeight = 282
ClientWidth = 418
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name ='Tahoma'
Font.Style = []
GlassFrame.Enabled = True
GlassFrame.Top = 22
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
对象pb1:TPaintBox
Left = 0
顶部= 0
宽度= 313
高度= 105
OnPaint = pb1Paint
end
end

编辑已更新为反文字,以使其看起来更好。


I am trying to implement Google Chrome style tabs, in Windows 7, in a Delphi application.

The elements of this are:

  • tabs may extend into the non-client area as they do in google chrome itself.
  • draws properly on Vista and Windows 7 when glass is enabled
  • tabs work just like google chrome, and look like google chrome, over glass.

I have found that the challenges I have to overcome are:

  • How do I get a control (VCL control) to extend into the non-client area? (A good sample of a control that does this is the Ribbon control included in the VCL sources, but I haven't seen anybody else do it, and it takes some wicked hacking to get the Ribbon to function)
  • How to draw bitmaps properly over glass? (DWM API). A related question already answers that aspect, here, this question was also asked by me.

解决方案

You don't want a full glass window, but you will have to draw the tabs yourself as there isn't a control that I am aware of that will give you the exact look your looking for. If you use the GlassFrame properties of the current form, enable it and set the top to the height you will want for your tabs, drop a paintbox on this area and use GDI+ calls to draw your tabs manually. A good library that should work for this is available on the EDN (http://cc.embarcadero.com/Download.aspx?id=26950). Without using GDI+ you will be able to draw to the paint box, but black will become transparent. With GDI+ you can draw freely to the glass in any color. For example:

Source:

unit Unit6;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, GdiPlusHelpers, GdiPlus, StdCtrls, ExtCtrls;

type
  TForm6 = class(TForm)
    pb1: TPaintBox;
    procedure pb1Paint(Sender: TObject);
  private
    { Private declarations }
   public
    { Public declarations }
  end;

var
  Form6: TForm6;

implementation

{$R *.dfm}

procedure TForm6.pb1Paint(Sender: TObject);
var
  Graphics : IGPGraphics;
  Brush: IGPSolidBrush;
  FontFamily: IGPFontFamily;
  Font: IGPFont;
  Point: TGPPointF;
  Pen: IGPPen;
begin
  Graphics := Pb1.ToGPGraphics;
  Brush := TGPSolidBrush.Create(TGPColor.Create(255, 0, 0, 0));
  FontFamily := TGPFontFamily.Create('Consolas');
  Font := TGPFont.Create(FontFamily, 12, FontStyleRegular, UnitPoint);
  Point.Initialize(1, 0);
  Graphics.TextRenderingHint := TextRenderingHintAntiAlias;
  Graphics.DrawString('GDI+ Black Text', Font, Point, Brush);
  Pen := TGPPen.Create(TGPColor.Create(255, 0, 0, 0));
  Graphics.DrawLine(Pen, 0, 0, 200, 100);
end;

end.

Form:

object Form6: TForm6
  Left = 0
  Top = 0
  Caption = 'Form6'
  ClientHeight = 282
  ClientWidth = 418
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  GlassFrame.Enabled = True
  GlassFrame.Top = 22
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object pb1: TPaintBox
    Left = 0
    Top = 0
    Width = 313
    Height = 105
    OnPaint = pb1Paint
  end
end

EDIT Updated to anti-alias the text so it looks better.

这篇关于德尔福玻璃上的Chrome浏览器风格标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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