应用DevExpress里的气泡组件 cxHintStyleController

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxLookAndFeelPainters, StdCtrls, cxButtons, cxHint, cxControls,
  cxContainer, cxEdit, cxTextEdit, cxMaskEdit, ExtCtrls, cxLabel,
  cxDropDownEdit, cxImageComboBox, ComCtrls, cxColorComboBox,
  cxFontNameComboBox, cxListBox;

type
  TForm1 = class(TForm)
    cxButton1: TcxButton;
    cxHintStyleController1: TcxHintStyleController;
    cxButton2: TcxButton;
    StatusBar1: TStatusBar;
    cxCbHintIconType: TcxComboBox;
    Label11: TLabel;
    Label2: TLabel;
    cxFnHint: TcxFontNameComboBox;
    cxCcbHintFontColour: TcxColorComboBox;
    Label3: TLabel;
    Label4: TLabel;
    lblHintColour: TLabel;
    cxCcbHintColour: TcxColorComboBox;
    GroupBox1: TGroupBox;
    Label1: TLabel;
    cxLabel1: TcxLabel;
    Edit1: TEdit;
    cxTextEdit1: TcxTextEdit;
    Button1: TButton;
    cxButton3: TcxButton;
    GroupBox2: TGroupBox;
    Label5: TLabel;
    cxLabel2: TcxLabel;
    Edit2: TEdit;
    cxTextEdit2: TcxTextEdit;
    Button2: TButton;
    cxButton4: TcxButton;
    procedure cxButton1Click(Sender: TObject);
    procedure cxButton2Click(Sender: TObject);
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure cxCbHintIconTypeClick(Sender: TObject);
    procedure cxCcbHintColourPropertiesEditValueChanged(Sender: TObject);
    procedure cxCcbHintFontColourClick(Sender: TObject);
    procedure cxFnHintClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Edit2MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure GroupBox2MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Label5MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure cxLabel2MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure cxTextEdit2MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Button2MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure cxButton4MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses cxHintEditor;
var comidx:integer;

{$R *.dfm}

procedure TForm1.cxButton1Click(Sender: TObject);
begin
  cxHintStyleEditor:=TcxHintStyleEditor.Create(self);
  cxHintStyleEditor.cxHsc.HintStyle:=cxHintStyleController1.HintStyle;
  cxHintStyleEditor.ShowModal;
  cxHintStyleEditor.SetHintController(cxHintStyleController1);
  cxHintStyleEditor.Free;
end;

procedure TForm1.cxButton2Click(Sender: TObject);
var x,y:integer;
    s:string;
begin
  cxHintStyleController1.HintStyle.CallOutPosition:=cxbpBottomRight;
  cxHintStyleController1.HintStyle.Font.Size:=16;
  x:=GroupBox1.Controls[comidx].ClientOrigin.X+GroupBox1.Controls[comidx].Width div 2;
  y:=GroupBox1.Controls[comidx].ClientOrigin.Y+GroupBox1.Controls[comidx].Height +GroupBox1.Top;
  if pos('cx',GroupBox1.Controls[comidx].ClassName)=0 then
  begin
    s:='标准组件';
    cxHintStyleController1.HintStyle.IconType := cxhiQuestion;
  end
  else
  begin
    s:='DevExpress组件';
    cxHintStyleController1.HintStyle.IconType:=cxhiInformation;
  end;
  cxHintStyleController1.ShowHint(x,y,s+GroupBox1.Controls[comidx].ClassName,GroupBox1.Controls[comidx].Hint);
  comidx:=(comidx+1) mod GroupBox1.ControlCount;
end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  cxHintStyleController1.HideHint;
  cxHintStyleController1.HintStyle.Font.Size:=8;
  cxHintStyleController1.HintStyle.IconType:=TcxHintIconType(cxCbHintIconType.ItemIndex);
end;

procedure TForm1.cxCbHintIconTypeClick(Sender: TObject);
begin
  cxHintStyleController1.HintStyle.IconType := TcxHintIconType(cxCbHintIconType.ItemIndex);
end;

procedure TForm1.cxCcbHintColourPropertiesEditValueChanged(
  Sender: TObject);
begin
  cxHintStyleController1.HintStyle.Color := cxCcbHintColour.ColorValue;
end;

procedure TForm1.cxCcbHintFontColourClick(Sender: TObject);
begin
  cxHintStyleController1.HintStyle.Font.Color := cxCcbHintFontColour.ColorValue;
end;

procedure TForm1.cxFnHintClick(Sender: TObject);
begin
  cxHintStyleController1.HintStyle.Font.Name := cxFnHint.FontName;
end;

procedure TForm1.FormShow(Sender: TObject);
begin
  cxFnHint.FontName:=cxHintStyleController1.HintStyle.Font.Name;
  cxCcbHintFontColour.ColorValue:=cxHintStyleController1.HintStyle.Font.Color;
  cxCcbHintColour.ColorValue:=cxHintStyleController1.HintStyle.Color;
  cxCbHintIconType.ItemIndex := Ord(cxHintStyleController1.HintStyle.IconType);
end;

procedure TForm1.Edit2MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  cxHintStyleController1.ShowHint(Edit2.ClientOrigin.X,Edit2.ClientOrigin.Y,'TEdit',Edit2.Hint);
end;

procedure TForm1.GroupBox2MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  cxHintStyleController1.HideHint;
  cxHintStyleController1.HintStyle.CallOutPosition:=cxbpTopRight;
end;

procedure TForm1.Label5MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  cxHintStyleController1.ShowHint(Label5.ClientOrigin.X,Label5.ClientOrigin.Y,'TLabel',Label5.Hint);
end;

procedure TForm1.cxLabel2MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  cxHintStyleController1.ShowHint(cxLabel2.ClientOrigin.X,cxLabel2.ClientOrigin.Y,'TcxLabel',cxLabel2.Hint);
end;

procedure TForm1.cxTextEdit2MouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
begin
  cxHintStyleController1.ShowHint(cxTextEdit2.ClientOrigin.X,cxTextEdit2.ClientOrigin.Y,'TcxTextEdit',cxTextEdit2.Hint);
end;

procedure TForm1.Button2MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  cxHintStyleController1.ShowHint(Button2.ClientOrigin.X,Button2.ClientOrigin.Y,'TButton',Button2.Hint);
end;

procedure TForm1.cxButton4MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  cxHintStyleController1.ShowHint(cxButton4.ClientOrigin.X,cxButton4.ClientOrigin.Y,'TcxButton',cxButton4.Hint);
end;

end.

//原来 群 122058606  广州佬 (把最上面图片另存到本地,修改后缀为 rar 后,可解压例子)

添加新评论

纯文本

  • 不允许使用HTML标签。
  • 自动断行和分段。
  • 网页和电子邮件地址自动转换为链接。
请输入图片中的字符,不区分大小写