Add pictures to TAdvSmoothMessageDialog at runtime

I would like to add a picture to a TAdvSmoothMessageDialog that I create at runtime.
I have not succeeded to do so until now.
- I have a TPictureContainer with my pictures, but I can't use that because here you use a TGDIPPictureContainer ??
- There is a property Images to use with an imagelist, but there is no ImageIndex value?
- There is a CaptionFill.Picture but I have not succeeded to connect a picture

I use PNG images in a TPictureContainer or in an ImageList, how do I connect them?

Hi, 


Can you provide the exact source code that you are using?

This is the code I have until now:


  FMD                   := TAdvSmoothMessageDialog.Create(AOwner);
  FMD.Position          := poScreenCenter;
  FMD.CaptionFont.Style := [fsBold];
  FMD.Buttons.Clear;
  FMD.Buttons.Add;
  FMD.Buttons[0].ButtonResult := mrOk;
  FMD.Buttons[0].Caption      := 'Ok';
  FMD.Buttons[0].Rounding     := 0;
  FMD.Caption                 := 'Testheader';
  FMD.HTMLText.Text := 'This is the body-text';
  FMD.SetComponentStyle(tsOffice2016White);
  FMD.Fill.RoundingType := rtNone;
  FMD.Fill.Opacity      := 250;
  FMD.Fill.OpacityTo    := 250;
  FMD.ButtonAreaFill.RoundingType := rtNone;


This works and gives me a Message with an Ok-button in the right style.
I'm planning to expand this and put it into an Interface/Implementation to get a consistent and easy lay-out throughout the program.
 I just want to add a PNG-picture from my TPictureContainer (which I use for other purposes).
If that is not possible, I want to read from a (temporary) ImageList with PNG-pictures. I do NOT want read a file from disc, my pictures are stored in the database.

Hi, 


You can use the following code and copy the images to the PictureContainer

var
  FMD: TAdvSmoothMessageDialog;
  I: Integer;
  p: TPictureItem;
  pi: PictureContainer.TPictureItem;
begin
  for I := 0 to PictureContainer1.Items.Count - 1 do
  begin
    pi := PictureContainer1.Items;
    p := GDIPPictureContainer1.Items.Add;
    p.Picture.Assign(PictureContainer1.Items[0].Picture);
    p.Name := pi.Name;
  end;


  FMD                   := TAdvSmoothMessageDialog.Create(Self);
  FMD.PictureContainer := GDIPPictureContainer1;
  FMD.Position          := poScreenCenter;
  FMD.CaptionFont.Style := [fsBold];
  FMD.Buttons.Clear;
  FMD.Buttons.Add;
  FMD.Buttons[0].ButtonResult := mrOk;
  FMD.Buttons[0].Caption      := 'Ok';
  FMD.Buttons[0].Rounding     := 0;
  FMD.Caption                 := 'Testheader';
  FMD.HTMLText.Text := '<img src="MyImage">This is the body-text';
  FMD.SetComponentStyle(tsOffice2016White);
  FMD.Fill.RoundingType := rtNone;
  FMD.Fill.Opacity      := 250;
  FMD.Fill.OpacityTo    := 250;
  FMD.ButtonAreaFill.RoundingType := rtNone;

  FMD.ExecuteDialog;
end;

So I will have to use an extra GDIPPictureContainer for that?
Maybe I could Create one along with the SmoothMessageDialog, copy 1 pictue into it the way you discribed it and then use it.
I guess it's possible to Create the GDIPPictureContainer at runtime?

What's the difference between those two containers? I guess it's not possible to use a GDIPPictureContainer instead of the 'normal' one? Why two formats?

That is correct. The reason is because in older Delphi versions only TImageList was supported, therefore we designed our own picture container, but there is actually no difference between the 2 other than supporting more types of images.

But it is not possible to only use a GDIPPictureContainer in the whole program and NOT use a TPictureContainer? In a TAdvTreeView for instance, I can only choose a TPictureContainer for PictureContainer, not a GDIPPictureContainer.

TAdvTreeView is a component that uses a different base. All smooth controls use a GDIPPictureContainer as they were initially designed as a separate set of components.

Yes, I get that. But that's not practical. To get a complete program, with all kinds of controls, one has to use different sets of components. Normally that's not a big problem, but it gets tricky when this sort of incompatibilities pop up. The same with styling. It's quite hard to keep everything consistent in one style (in our case tsOffice2016White) with all the different sets of components. There are components we used that had to be styled manually to mimic tsOffice2016White. So switching to a different theme is kind of impossible.

I have tried the code you supplied (after some corrections), but that does not work either. I don't get any picture.
The CaptionFill.Picture is the most important one for me.
I tried this:


  cIcon := 'MyPicture';
  FMD.HTMLText.Text := '<img src="' + cIcon + '">' + Tekst;
  FMD.CaptionFill.Picture.Assign(FGDIPPictureContainer.Items[0]);


No picture appears. Do I have to set extra settings?
I verified the picture (a PNG image) is in the container and that the name is right.
What do I do wrong?

Please provide us with a sample to investigate which properties are set, and how the picturecontainer is transfered and connected to the smooth message dialog.

I had to change your code a bit to get it to work.


var
  nFlags : Integer;
  nTeller: Integer;
  p      : GDIPPictureContainer.TPictureItem;
  cIcon  : string;
begin
  FMD                   := TAdvSmoothMessageDialog.Create(AOwner);
  FMD.Position          := poScreenCenter;
  FMD.CaptionFont.Style := [fsBold];
  FMD.Buttons.Clear;
  FMD.Buttons.Add;
  FMD.Buttons[0].ButtonResult := mrOk;
  FMD.Buttons[0].Caption      := rc_Ok;
  FMD.Buttons[0].Rounding     := 0;
  FMD.Caption                 := 'Testheader';
  FMD.SetComponentStyle(tsOffice2016White);
  FMD.Fill.RoundingType := rtNone;
  FMD.Fill.Opacity      := 250;
  FMD.Fill.OpacityTo    := 250;
  FMD.ButtonAreaFill.RoundingType := rtNone;
  cIcon := 'MyPicture';
  for nTeller := 0 to Container.Items.Count - 1 do
  begin
    if Container.Items[nTeller].Name = cIcon then
    begin
      p := FGDIPPictureContainer.Items.Add;
      p.Picture.Assign(Container.Items[nTeller]);
      p.Name := Container.Items[nTeller].Name;
      break;
    end;
  end;
  FMD.HTMLText.Text := '<img src="' + cIcon + '">This is the body-text';
  FMD.CaptionFill.Picture.Assign(FGDIPPictureContainer.Items[0]);
end;


Sorry, I forgot to add these two lines:


  FGDIPPictureContainer := TGDIPPictureContainer.Create(AOwner);
  FMD.PictureContainer  := FGDIPPictureContainer;


Directly after the first statement.

You should assign TPicture / TGraphic instead of TPictureItem


p.Picture.Assign(PictureContainer1.Items[nTeller].Picture);

instead of

p.Picture.Assign(PictureContainer1.Items[nTeller]);

and

FMD.CaptionFill.Picture.Assign(GDIPPictureContainer1.Items[0].Picture);

instead of

FMD.CaptionFill.Picture.Assign(GDIPPictureContainer1.Items[0]);

Of course :-)
That helped for the HTML-row, but I still don't see any picture in the Caption.

Please also set the pictureposition.


  FMD.CaptionFill.Picture.Assign(FGDIPPictureContainer.Items[0].Picture);
  FMD.CaptionFill.PictureHeight := 16;
  FMD.CaptionFill.PictureWidth  := 16;
  FMD.CaptionFill.PicturePosition := ppTopLeft;
  FMD.CaptionFill.PictureSize   := psOriginal;


I did that. Does not help.

It works as expected with the following code


procedure TForm10.Button1Click(Sender: TObject);
var
  nFlags : Integer;
  nTeller: Integer;
  p      : GDIPPictureContainer.TPictureItem;
  cIcon  : string;
  FMD: TAdvSmoothMessageDialog;
  FGDIPPictureContainer: TGDIPPictureContainer;
begin
  FGDIPPictureContainer := TGDIPPictureContainer.Create(Self);
  FMD                   := TAdvSmoothMessageDialog.Create(Self);
  FMD.PictureContainer  := FGDIPPictureContainer;
  FMD.Position          := poScreenCenter;
  FMD.CaptionFont.Style := [fsBold];
  FMD.Buttons.Clear;
  FMD.Buttons.Add;
  FMD.Buttons[0].ButtonResult := mrOk;
  FMD.Buttons[0].Caption      := 'OK';
  FMD.Buttons[0].Rounding     := 0;
  FMD.Caption                 := 'Testheader';
  FMD.SetComponentStyle(tsOffice2016White);
  FMD.Fill.RoundingType := rtNone;
  FMD.Fill.Opacity      := 250;
  FMD.Fill.OpacityTo    := 250;
  FMD.ButtonAreaFill.RoundingType := rtNone;
  cIcon := 'MyPicture';
  for nTeller := 0 to PictureContainer1.Items.Count - 1 do
  begin
    if PictureContainer1.Items[nTeller].Name = cIcon then
    begin
      p := FGDIPPictureContainer.Items.Add;
      p.Picture.Assign(PictureContainer1.Items[nTeller].Picture);
      p.Name := PictureContainer1.Items[nTeller].Name;
      break;
    end;
  end;
  FMD.HTMLText.Text := '<img src="' + cIcon + '">This is the body-text';
  FMD.CaptionFill.Picture.Assign(FGDIPPictureContainer.Items[0].Picture);
  FMD.ExecuteDialog;
end;

Yes, it works with my code too now. Still not sure why it didn't work in the first place though...
Thank you!