Показать сообщение отдельно
  #3  
Старый 07.10.2007, 02:52
Аватар для Karsh
Karsh Karsh вне форума
Активный
 
Регистрация: 22.09.2007
Адрес: SPb
Сообщения: 228
Версия Delphi: 7, 2009, XE2
Репутация: 70
По умолчанию

Код:
procedure TForm1.Button1Click(Sender: TObject);
var x: integer;
begin
x:= Form1.Left + Button1.Left + (Button1.Width div 2) +
    Form1.BorderWidth + (Form1.Width - Form1.ClientWidth) div 2;
x:= Mouse.CursorPos.X - x;
Label1.Caption:= IntToStr(x);
end;
Результат получишь в пикселях, а там делай че хошь, хоть в километры переводи но учти, что на разных мониторах пиксели разного размера (зависит от размера кинескопа).

З.Ы. Для визуального контроля создай Button2 и пропиши код:
Код:
procedure TForm1.Button2Click(Sender: TObject);
var TMP: TBitmap; x, y: integer;
begin
  x:= Button1.Left;
  y:= Button1.Top + Button1.Height;
  TMP:= TBitmap.Create;
  TMP.Height:= 10;
  TMP.Width:= Button1.Width;
  with TMP.Canvas do
    begin
    Brush.Style:= bsSolid;
    Brush.Color:= clRed;
    FillRect(Bounds(0,0,TMP.Width div 2,TMP.Height));
    Brush.Style:= bsSolid;
    Brush.Color:= clLime;
    FillRect(Bounds(TMP.Width div 2,0,TMP.Width,TMP.Height));
    end;
  Form1.Canvas.Draw(x,y,TMP);
  TMP.Free;
end;
Ответить с цитированием