Forum > General
Separating event calls depending on where the mouse is.
OC DelGuy:
I created a form and put a TMemo and a TEdit on it. I then clicked on the "OnMouseWheelDown" event and Lazarus created the procedure FormMouseWheelDown. In the procedure I wrote "Edit1.Text:='Mouse wheel down.';". I did the same with the "OnMouseWheelUp" event, replacing "down" with the word "up".
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.FormMouseWheelDown(Sender: TObject; Shift: TShiftState; MousePos: TPoint; var Handled: Boolean);begin Edit1.Text:='Mouse wheel down.';end; procedure TForm1.FormMouseWheelUp(Sender: TObject; Shift: TShiftState; MousePos: TPoint; var Handled: Boolean);begin Edit1.Text:='Mouse wheel up.';end;When I run the application, and I roll the mouse wheel outside the Memo box, but inside the form, this code executes (as it should).
How can I prevent this code from running when I roll the mouse wheel up and down inside the memo? I realize that while the mouse pointer is in the memo box, it is ALSO in the form. But I don't want it to run this code while "wheeling" in the memo box. Just in the remainder of the form.
I tried making events in the Memo, "OnMouseWheelUp" and "OnMouseWheelDown", and putting in different strings.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Memo1MouseWheelDown(Sender: TObject; Shift: TShiftState; MousePos: TPoint; var Handled: Boolean);begin Edit1.Text:='From Memo1, down.';end; procedure TForm1.Memo1MouseWheelUp(Sender: TObject; Shift: TShiftState; MousePos: TPoint; var Handled: Boolean);begin Edit1.Text:='From Memo1, up.';end;But these don't execute when the mouse pointer is in the memo box.
I'm writing this as I'm coding, so this is quite literally all I have coded.
Thanks in advance for any help Y'all can give me.
Josh:
You could try using FindDragTarget
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Memo1MouseWheelDown(Sender: TObject; Shift: TShiftState; MousePos: TPoint; var Handled: Boolean);var cntrl:tcontrol;begin cntrl:=tcontrol(FindDragTarget(Mouse.CursorPos,true)); if cntrl is tmemo then begin if cntrl.Name='Memo1' then begin memolab.caption:='Memo1 MouseWheelDown MousePos X:= '+inttostr(mousepos.X); end; end;end;
example proj attahed
Thaddy:
PtInRect.
https://www.freepascal.org/docs-html/rtl/types/ptinrect.html
jamie:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.FormMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);begin Handled := (Self.ControlAtPos(ScreenToClient(Mouse.CurSorPos),true,True) <> nil);end;
There appears to be to be an issue with the "ControlAtPos"? whereas if you only use the simplest version to allow disabled controls, it sets the Window controls to false? Does that really make any sense to you?
Basically, what that means is, it only finds the disabled and enabled Non-Window Controls.
Maybe it's my old version I used but that is the case here.
Using the two Boolean overloaded version allows to indicate to also include the windows controls.
I also noticed that the MousePos always reports the child control client position if over a child, which is why I had to not use that. Seems strange to be that way since there is no way with input parameters to know that. Sender is always the form.
jamie:
Hmm.
Checking the trunk, it appears that problem with MousePos within those events over child controls verses Parent (From) has been fixed.
Navigation
[0] Message Index
[#] Next page