Ver Mensaje Individual
  #3  
Antiguo 29-12-2017
Unkger Unkger is offline
Miembro
NULL
 
Registrado: ago 2017
Posts: 13
Reputación: 0
Unkger Va por buen camino
¿Y como seria de forma horizontal?, en lugar de que me diga en que renglón esta, que me diga en que columnas se encontró, con el código que pusiste, si le cambio un poco, el mensaje que muestra en el label no corresponde al pixel que selecciono. Me muestra:
"Encontrado en columnas 0, 7", debería de ser "Encontrado en columnas 0, 1"
"Encontrado en columnas 2, 7", debería de ser "Encontrado en columnas 2, 3"
"Encontrado en columnas 4, 7", debería de ser "Encontrado en columnas 4, 5".
"Encontrado en columnas 6, 7", este si esta bien.

Código Delphi [-]
...

implementation  {$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
const
  VP: array[0..3] of string = ('156','183','214','238');
var
  sg: TStringGrid;
  cv: TCanvas;
  i : Integer;
  j, j2 : Integer;
begin
  image1.Canvas.FillRect(image1.Canvas.ClipRect);
  j := 0;
  j2 := 1;
  sg := StringGrid1;
  sg.FixedCols := 0;
  sg.FixedRows := 0;
  sg.ColCount  := 8;
  sg.RowCount  := 1;
  cv := Image1.Picture.Bitmap.Canvas;
  for i := 0 to 3 do
  begin
    cv.Pixels[StrToInt(VP[i]), 56] := clRed;
    sg.Cells[j, 0] := VP[i];
    sg.Cells[j2, 0] := '56';
    j := j+2;
    j2 := j2+2;
  end;
end;

procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  dx, dy, r : Integer;
  sg: TStringGrid;
  c, c2 : Integer;
begin
  sg := StringGrid1;
  for r := 0 to StringGrid1.RowCount - 1 do
  for c := 0 to StringGrid1.ColCount - 1 do
  for c2 := 1 to StringGrid1.ColCount -1 do
  begin
    dx := X - (StrToInt(StringGrid1.Cells[c, r]));
    dy := Y - (strToInt(StringGrid1.Cells[c2, r]));
    if (abs(dx) < 5) and (abs(dy) < 5) then
    begin
      sg.Selection := TGridRect(Rect(0, r, sg.ColCount, r));
      Label1.Caption := 'Encontrado en columnas ' + inttostr(c) + ', ' + inttostr(c2);
    end;
  end;
end;
...
Responder Con Cita