Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   OOP (https://www.clubdelphi.com/foros/forumdisplay.php?f=5)
-   -   Mostrar un globo informativo diferente en cada columna de un TStringGrid (https://www.clubdelphi.com/foros/showthread.php?t=84000)

TiammatMX 26-08-2013 19:57:39

Mostrar un globo informativo diferente en cada columna de un TStringGrid
 
Buen día/tarde/noche, jóvenes delphineros. Una vez más, yo con mis preguntas fáciles de hacer y difíciles de responder.

Resulta que tengo un TStringGrid coloreado, y ahora requiero ponerle un globo informativo (hint) cuando cambie el cursor de celda..., tarea que sería fácil si el TStringGrid contara con el evento OnMouseOver...

...pero como no lo tiene, ¿alguna manera de poder solucionar ésta inquietud o requerimiento? Especialmente, que sea completamente stándard.

TiammatMX 26-08-2013 20:55:10

Un compañero me proporcionó éste código:

Código Delphi [-]
procedure TForm1.StringGrid1MouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
var
  R, C: Integer;
begin
  StringGrid1.MouseToCell(X, Y, C, R);
  with StringGrid1 do
  begin
    if ((Row<>R)or(Col<>C)) then
    begin
      Row:=R;
      Col:=C;
      Application.CancelHint;
      StringGrid1.Hint:=IntToStr(R)+#32+IntToStr(C);
    end;
  end;
end;

El cual modifiqué así:
Código Delphi [-]
procedure TfrmPrescripcionDieteticaInicial.stgProcesarMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
var
  R, C: Integer;
  sHint : string;
begin
   if (Sender).ClassType = TStringGrid then
   begin
      stgProcesar.MouseToCell(X, Y, C, R);
      if (R > 2) and (C > 3) then
      begin
         with stgProcesar do
         begin
            if ((Row <> R) or (Col <> C)) then
            begin
               Row := R;
               Col := C;
               sHint := CapitalFirst(BuscaHint(Cells[C,2]));
               if Trim(sHint) > '' then
               begin
                  Application.CancelHint;
                  Hint := sHint;
               end;
            end;
         end;
      end;
   end;
end;

...y queda haciendo EXACTAMENTE lo que necesito.

ecfisa 26-08-2013 21:20:53

Hola tiammat.

Estaba terminando un ejemplo similar y aunque ya lo solucionaste lo agrego por si hay alguna parte que te pueda servir.
Código Delphi [-]
var
  vHints : array of array of string;

procedure TForm1.FormCreate(Sender: TObject);
var
  c,f: Integer;
begin
  Application.HintColor    := clRed;
  Screen.HintFont.Color    := clWhite;
  Screen.HintFont.Name     := 'Times New Roman';
  Screen.HintFont.Style    := [fsBold];
  Application.HintPause    := 300;
  Application.HintHidePause:= 3000;
  with StringGrid1 do
  begin
    // algunos datos...
    for c := 0 to ColCount - 1 do
      for f := 0 to RowCount -1 do
        Cells[c,f] := IntToStr(c+f);
    // algunos mensajes
    for c := 0 to ColCount -1 do
      for f := 0 to Rowcount -1 do
      begin
        SetLength(vHints, Length(vHints)+1, Length(vHints)+1);
        vHints[c,f] := Format(' Ud. está posicionado en: %s columna %d, fila %d ',
          [#10#13, c, f]);
      end;
    ShowHint := True;
  end;
end;

procedure TForm1.StringGrid1MouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
var
  aCol, aRow : integer;
begin
  with TStringGrid(Sender) do
  begin
    MouseToCell (X, Y, aCol, aRow);
    if(aCol >= 0) and (aRow >= 0) and (Hint <> StringGrid1.Cells[aCol,aRow]) then
    Hint := vHints[aCol,aRow];
  end
end;

Saludos. :)

Edito: Lo del hint es por que creí leer "Hint colorado" en lugar de "TStringGrid coloreado"... :o :D (no si ando mejor...)

TiammatMX 26-08-2013 21:34:59

Cita:

Empezado por ecfisa (Mensaje 466067)
Hola tiammat.
Estaba terminando un ejemplo similar y aunque ya lo solucionaste lo agrego por si hay alguna parte que te pueda servir....

Toda ayuda es bien recibida, ecfisa..., es más, hasta recibo muestras de apoyo y palmaditas en la espalda con el típico "¡Tú puedes, campeón!"... :D:D:D

Cita:

Empezado por ecfisa (Mensaje 466067)
...Edito: Lo del hint es por que creí leer "Hint colorado" en lugar de "TStringGrid coloreado"... :o :D (no si ando mejor...)

jajajajajajajaja Al mejor cazador se le va la liebre..., y de noche, todos los gatos son pardos.;)


La franja horaria es GMT +2. Ahora son las 09:13:44.

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