AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Nächstes Control zu einem Punkt finden

Ein Thema von argonix · begonnen am 24. Sep 2009 · letzter Beitrag vom 24. Sep 2009
 
Benutzerbild von Aphton
Aphton

Registriert seit: 31. Mai 2009
1.198 Beiträge
 
Turbo Delphi für Win32
 
#7

Re: Nächstes Control zu einem Punkt finden

  Alt 24. Sep 2009, 22:45
Probier mal Folgendes

Delphi-Quellcode:
//**
//** Gibt den am naheliegendsten Control zurück
//** - wobei die Distanz ausgehend vom Mittelpunkt
//** - der einzelnen Controls berechnet wird
//**
function NearestControl(const Position: TPoint; const MainControl: TControl): TControl;
var
  i, j: Integer;
  lDis, cDis: Single; // last distance, current distance
  function DistanceTo( Control: TControl ): Single;
  var
    x, y: Single;
  begin
    with Control do
    begin
      x := Left + ( Width div 2 ) - Position.X;
      y := Top + ( Height div 2 ) - Position.Y
    end;
    Result := SQRT( x*x + y*y );
  end;
begin
  Result := NIL;
  if MainControl.ComponentCount = 0 then
    Exit;
  j := -1;
  Result := TControl( MainControl.Components[0] );
  lDis := DistanceTo( Result );
  if MainControl.ComponentCount < 2 then
    Exit;
  for i := 1 to MainControl.ComponentCount - 1 do
  begin
    cDis := DistanceTo( TControl( MainControl.Components[i] ) );
    if cDis < lDis then
    begin
      lDis := cDis;
      j := i;
    end;
  end;
  if j > 0 then
    Result := TControl( MainControl.Components[j] );
end;

//**
//** Beispiel: Klatsch ein paar Controls auf die Form, und füge diesen Code in OnMouseDown() ein!
//**
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X,
  Y: Integer);
var
  c: TControl;
begin
  c := NearestControl( Point( X, Y ), Form1 );
  if Assigned( c ) then
    c.Enabled := not c.Enabled;
end;
das Erkennen beginnt, wenn der Erkennende vom zu Erkennenden Abstand nimmt
MfG
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 17:09 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz