Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Redibujar un bitbtn en tiempo de ejecución (https://www.clubdelphi.com/foros/showthread.php?t=32443)

papulo 06-06-2006 11:27:48

Redibujar un bitbtn en tiempo de ejecución
 
Tengo un bitmapbutton que carga el bmp de un componente imageresource.

Al iniciar el programa, le cargo la imagen con el siguiente código:
Código Delphi [-]
  DataModule.imageResources.GetBitmap(0, bbAL.Glyph);
y no tengo ningún problema.

Pero al intentar cambiarlo en el evento
Código Delphi [-]
procedure TGraphForm.bbALClick(Sender: TObject);
begin
  if bAL then
    begin
      DataModule.imageResources.GetBitmap(4, bbAL.Glyph);
      bAL := False
    end
  else
    begin
      DataModule.imageResources.GetBitmap(0, bbAL.Glyph);
      bAL := True
    end
end;
Entra pero no hace nada. El booleano está declarado como variable global y esa condición la cumple sin problemas.

No se me ocurre como hacerlo, pero he encontrado este código que tampoco acabo de comprender completamente:
Código Delphi [-]
  var
    MyBtnGlyph: HBitmap;
    MyBtnBmp: TBitmap;
  begin
    MyBtnBmp := TBitmap.Create;
    MyBtnGlyph := LoadBitmap(HINSTANCE, 'MYBMP'); 
    {MYBMP is the name of the bitmap in the resource file.}
    MyBtnBmp.Handle := MyBtnGlyph;
    MyBtn.Glyph := MyBtnBmp;
    MyBtn.NumGlyphs := 1; {Obviously depends on the bitmap.}
    MyBtnBmp.Free;
  end;
Se que "MyBtn" ha de ser "bbAL", pero la linea de
"MyBtnGlyph := LoadBitmap(HINSTANCE, 'MYBMP');"
me tiene totalmente perdido, ya que no se a que hace referencia
"MYBMP"
ya que tengo las imagenes en el imagelist e indexadas.

Gracias por la ayuda y mientras sigo mirando.
Papulo.

papulo 06-06-2006 13:10:38

Solucion
 
Casimiro Notevi me ha dado la solución, que es bien sencilla.

Solamente tenía que añadir

Código Delphi [-]
  bbMA.Glyph := nil;
Antes de cargar la nueva imagen en el boton.

El código queda así:
Código Delphi [-]
procedure TGraphForm.bbALClick(Sender: TObject);
begin
  bbMA.Glyph := nil;
    if bAL then
       begin
        DataModule.imageResources.GetBitmap(4, bbAL.Glyph);
        bAL := False
      end
    else
      begin
        DataModule.imageResources.GetBitmap(0, bbAL.Glyph);
        bAL := True
      end
  end;


La franja horaria es GMT +2. Ahora son las 12:00:50.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi