Avatar of ClassPublishing
ClassPublishing

asked on 

Using a bubble hint in Delphi

I have found the code from Slick on how to create a bubble object for display hints. Could you give me an example of how you would use this object? I would just like an example of the create, setting up where it should appear on the form, its colour etc.
Delphi

Avatar of undefined
Last Comment
Geert G
ASKER CERTIFIED SOLUTION
Avatar of Geert G
Geert G
Flag of Belgium image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
not sure if that's what you looking for but take a look:

type

  TEditBalloonTip = packed record
    cbStruct: DWORD;
    pszTitle: PWideChar;
    pszText: PWideChar;
    ttiIcon: Integer;
  end;

const
  EM_SHOWBALLOONTIP = $1503;
  TTI_EMPTY = 0;
  TTI_INFO = 1;
  TTI_WARNING = 2;
  TTI_ERROR = 3;

procedure TForm1.Button1Click(Sender: TObject);
var baloon: TEditBalloonTip;
begin
  baloon.cbStruct := SizeOf(baloon);
  baloon.pszTitle := 'Hint title';
  baloon.pszText := 'warining message here';
  baloon.ttiIcon := TTI_WARNING;
  SendMessage(Edit1.Handle, EM_SHOWBALLOONTIP, 0, Integer(@baloon));
end;

ziolko.
Avatar of ClassPublishing
ClassPublishing

ASKER

Thanks,  Geert. I got the bubble working (and had to laugh at the caption you chose). I have tried changing the width and the height to fit more text in. This doesn't work, unless I comment out the code which hardcodes the width and height in. Can you see an easy way of making the bubble hold more text? Preferably with CR in the text?

Ziolko - your suggestion - am I right in thinking it is unrelated to the code supplied by Slick? I am having trouble getting it to work and from the look of it - it won't produce a 'bubble shape' hint?
I don't know Slick's code, the one I posted works on WinXP and you have to add manifest and looks like on pic

ziolko.
sample.jpg
Avatar of Geert G
Geert G
Flag of Belgium image

the problem with the TTextBubble is that the size is not dynamic

to alter it ... used TextExtent + 20px width and height
Description

Use TextExtent to determine the space a string will occupy in the image. Other elements in the image such as lines, boxes, or additional lines of text can be positioned to accommodate the size of the text. TextExtent returns the width and height of the rectangle that bounds the text on the canvas.

I didn't test this it, but may work


procedure TForm1.Button1Click(Sender: TObject);
var aBubble: TBubble;
 aExtent: TPoint;
 aSize: TSize;
begin
  aText := 'Ouch, you clicked me !!'#13#10'Twice !!!';
  aBubble := TBubble(FindComponent('BubblyButton'));
  if aBubble = nil then
    aBubble := TBubble.Create(Self);
  aBubble.Parent := Self;
  aBubble.Top := TButton(Sender).Top + 20;
  aBubble.Left := TButton(Sender).Left + 20;
  aSize := aBubble.Canvas.TextExtent(aText);
  aBubble.Width := aSize.cX + 20;
  aBubble.Height := aSize.cY + 20;
  aBubble.Text := aText;
  aBubble.Name := 'BubblyButton';
  aBubble.Invalidate;
end;

Open in new window

hello ClassPublishing, I'm guessing that you are looking at the TextBubble unit code, ,  It's been so long since I did that code , I don't remember much about it. But I have copied some code from the Form unit. This component uses the more or less standard windowed component methods, like
TextBub1 := TTextBubble.Create(self);
and the  Width, Height, Top, Left., ect, You do not give any code that you tried so I can see what you did wrong.
Here is some code from a TForm Unit
= = = = = = = = = = = = = = = = = =

interface

uses
    Usual stuff, TextBubble {add ,TextBubble to uses}


  TForm1 = class(TForm)
    sbut_DoSize: TSpeedButton;
    procedure sbut_DoSizeClick(Sender: TObject);

  private
    { Private declarations }
    TextBub1: TTextBubble;
    procedure BubbleClick(Sender: TObject);


var
  Form1: TForm1;

implementation

{$R *.DFM}


procedure TForm1.FormCreate(Sender: TObject);
begin
TextBub1 := TTextBubble.Create(self);
TextBub1.Parent := Self;
TextBub1.Left := 400;
TextBub1.Top := 420;
{uses the Default width and height, but
you could also change with
TextBub1.Width := 160;
TextBub1.Height := 122;}
TextBub1.Caption := 'Hello to &You All';
TextBub1.Color := $B6AAEA;
TextBub1.OnClick := BubbleClick;
end;

procedure TForm1.BubbleClick(Sender: TObject);
begin
ShowMessage('Bubble Click Event');
end;

procedure TForm1.sbut_DoSizeClick(Sender: TObject);
begin
TextBub1.Caption := 'New Text for TextBubble';
TextBub1.SetBounds(380, 400, 150, 100);
end;
Avatar of ClassPublishing

ASKER

Thank you for your help.
Avatar of Geert G
Geert G
Flag of Belgium image

a B ???
Delphi
Delphi

Delphi is the most powerful Object Pascal IDE and component library for cross-platform Native App Development with flexible Cloud services and broad IoT connectivity. It provides powerful VCL controls for Windows 10 and enables FMX development for Windows, Mac and Mobile. Delphi is your choice for ultrafast Enterprise Strong Development™. Look for increased memory for large projects, extended multi-monitor support, improved Object Inspector and much more. Delphi is 5x faster for development and deployment across multiple desktop, mobile, cloud and database platforms including 32-bit and 64-bit Windows 10.

60K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo