Home > Net >  Is there a way to determine which balloon I clicked on?
Is there a way to determine which balloon I clicked on?

Time:10-21

I am writing a program in Delphi that displays fresh information in balloons.

Is there a way to determine which balloon I clicked on?

Like this:

sendername := 'Gert'; 

TrayIcon1.Visible := True;
TrayIcon1.BalloonHint := 'You got a new message from ' sendername '!';
TrayIcon1.ShowBalloonHint;

...

sendername := 'Peter'; 

TrayIcon1.Visible := True;
TrayIcon1.BalloonHint := 'You got a new message from ' sendername '!';
TrayIcon1.ShowBalloonHint;

Now I would like to show the related letter in a BalloonClick event, but how can I determine which one was clicked?

CodePudding user response:

Your question seems to imply that multiple balloons can be displayed by a single TTrayIcon component. That is not the case. There is only one balloon, and the text of the balloon will contain whatever you last assigned to BalloonHint.

So in your case, the sendername variable will contain the name that is currently being shown in the balloon.

CodePudding user response:

There is only one Balloon per TrayIcon, so you can't tell which balloon was clicked.

You can achieve what you're asking by taking advantage of the Tag property that all VCL controls share.

sendername := 'Gert'; 
TrayIcon1.Tag := 1;
TrayIcon1.Visible := True;
TrayIcon1.BalloonHint := 'You got a new message from ' sendername '!';
TrayIcon1.ShowBalloonHint;

sendername := 'Peter'; 
TrayIcon1.Tag := 2;
TrayIcon1.Visible := True;
TrayIcon1.BalloonHint := 'You got a new message from ' sendername '!';
TrayIcon1.ShowBalloonHint;

Now in the TTrayIcon.OnBalloonClick event:

case TrayIcon1.Tag of
  1: // Gert was the sendername
  2: // Peter was the sendername
else
  // Catch any where you forgot to set the tag
  ShowMessage('Unknown sendername. BallooonHint: '   TrayIcon1.BalloonHint);
end;
TrayIcon1.Tag := 0;  // Reset tag to 0 when finished
  • Related