detect mousedown - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

detect mousedown

softmansoftman Posts: 157Member
Hi!

How can I detect, if the left mouse is down, and I'm in a mouseenter event where Shift : TShiftState parameter is not passed! I'v tried TMouse, but I couldn't do it.

Thank's
softman

Comments

  • zibadianzibadian Posts: 6,349Member
    : Hi!
    :
    : How can I detect, if the left mouse is down, and I'm in a mouseenter event where Shift : TShiftState parameter is not passed! I'v tried TMouse, but I couldn't do it.
    :
    : Thank's
    : softman
    :
    :
    I haven't been able to find a mouseenter event, only a CM_MouseEnter message.
    You need to create an OnMouseDown event in each control you want to detect it. Here is a small tested code, which catches the mouse downs in all edits and memos.
    [code]
    procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
    Shift: TShiftState; X, Y: Integer);
    begin
    // Display the mouse down to the user
    case Button of
    mbLeft: Label1.Caption := 'Left down';
    mbMiddle: Label1.Caption := 'Middle down';
    mbRight: Label1.Caption := 'Right down';
    end;
    end;

    procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
    Shift: TShiftState; X, Y: Integer);
    begin
    // Remove the mouse down display
    Label1.Caption := '';
    end;

    procedure TForm1.FormCreate(Sender: TObject);
    var
    i: integer;
    begin
    // Loop through all the controls and add the form's OnMouseDown to
    // each of them
    if ControlCount > 0 then
    for i := 0 to ControlCount-1 do
    if Controls[i] is TEdit then // Necessary to expose the event
    begin
    TEdit(Controls[i]).OnMouseDown := FormMouseDown;
    TEdit(Controls[i]).OnMouseUp := FormMouseUp;
    end else
    if Controls[i] is TMemo then // Necessary to expose the event
    begin
    TMemo(Controls[i]).OnMouseDown := FormMouseDown;
    TMemo(Controls[i]).OnMouseUp := FormMouseUp;
    end;
    end;
    [/code]
    If you create a test project with a single form, 1 label, and several edits and memos, you can see that if you depress a mouse button, the label shows which button you are holding.
  • softmansoftman Posts: 157Member
    Thank you, it seems to solving my problem. You are right about, that the TEdit has no OnMouseEnter event. I was confusing it with TLabel, where it exist in and above delpi7.

    Softman


    : : Hi!
    : :
    : : How can I detect, if the left mouse is down, and I'm in a mouseenter event where Shift : TShiftState parameter is not passed! I'v tried TMouse, but I couldn't do it.
    : :
    : : Thank's
    : : softman
    : :
    : :
    : I haven't been able to find a mouseenter event, only a CM_MouseEnter message.
    : You need to create an OnMouseDown event in each control you want to detect it. Here is a small tested code, which catches the mouse downs in all edits and memos.
    : [code]
    : procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
    : Shift: TShiftState; X, Y: Integer);
    : begin
    : // Display the mouse down to the user
    : case Button of
    : mbLeft: Label1.Caption := 'Left down';
    : mbMiddle: Label1.Caption := 'Middle down';
    : mbRight: Label1.Caption := 'Right down';
    : end;
    : end;
    :
    : procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
    : Shift: TShiftState; X, Y: Integer);
    : begin
    : // Remove the mouse down display
    : Label1.Caption := '';
    : end;
    :
    : procedure TForm1.FormCreate(Sender: TObject);
    : var
    : i: integer;
    : begin
    : // Loop through all the controls and add the form's OnMouseDown to
    : // each of them
    : if ControlCount > 0 then
    : for i := 0 to ControlCount-1 do
    : if Controls[i] is TEdit then // Necessary to expose the event
    : begin
    : TEdit(Controls[i]).OnMouseDown := FormMouseDown;
    : TEdit(Controls[i]).OnMouseUp := FormMouseUp;
    : end else
    : if Controls[i] is TMemo then // Necessary to expose the event
    : begin
    : TMemo(Controls[i]).OnMouseDown := FormMouseDown;
    : TMemo(Controls[i]).OnMouseUp := FormMouseUp;
    : end;
    : end;
    : [/code]
    : If you create a test project with a single form, 1 label, and several edits and memos, you can see that if you depress a mouse button, the label shows which button you are holding.
    :

Sign In or Register to comment.