Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.