Tip always knowing the mouse location of a click in your application

Ken Wanlass

New member
Joined
Nov 12, 2014
Messages
2
Programming Experience
1-3
In the .NET programming environment, some controls opt out on the programmer's experience, and disable detailed mouse events. If a library control is enforcing that you don't know the mouse location on a click, then you have added a control to you application that refuses to let you add your own plugins to it. Why would you ever program for a company's library that refuses to let you add plugins to it? Let me ask a second question in response: Am I supposed to admit to Adobe that background processes are more important than to make available a pause button to long lasting threads? The answer is we should have easy access to the controls so that when we are being charged for a service that we could improve, then the experience is greater when the glitch has been solved and the satisfaction sets in.


The point is supposedly that if you opt in to constant upgrades, then you don't have a free choice for the book you bought, you have to buy another month of access, you don't have clipboard access to important parts of the text, so you can't listen to those segments, or can't easily research the term in the browser, the current process is hogging the resources and can't be instantly paused even though if you had access to the library code you could easily add a feature to halt all tcp requesting process and force any .exe to an idle state without crashing the machine. This should be required at the least. All of this should be required AM I WRONG?


Its either your favorite application or Adobe, if you want to read a pdf, then you can't have both.


Finally my point is, if you can do more for your computer for free than a company that charges for software then take your advantage even if their code is running at the same time.


Always have control of the clicks in your application. Its your computer, you can program it as you wish for you own educational purpose.


Say you are working on a VB.NET project and you are trying to land a coding job with it for a company of your preference. Suppose you have compiled a good deal of code so much that you have your proposed interface and features where the user can access everything useful. Now you want to be able to make something more useful out of the cloud data that the company you want to work for typically offers, but you are losing out on the webbrowser or some other control's lack of mouse event handlers! You want to be able to prove to the company that you are worth their time with your coding style and functionality, but you can't even process new threads that can interact with the webbrowser, or control's mouse event, even though with your coding ability and mathematical prowess, you would create additional functionality if you could only catch the mouse event location. Then you need some way to access the mouse event for a control that doesn't have that option.


We can use a transparent control to give us "transparent" mouse events.
VB.NET:
      Public Class TransparentRichTextBox
            Inherits RichTextBox




            <DllImport("kernel32.dll", CharSet:=CharSet.Auto)> _
            Private Shared Function LoadLibrary(ByVal lpFileName As String) As IntPtr
            End Function




            Protected Overrides ReadOnly Property CreateParams() As CreateParams
                Get
                    Dim params As CreateParams = MyBase.CreateParams
                    If LoadLibrary("msftedit.dll") <> IntPtr.Zero Then
                        params.ExStyle = params.ExStyle Or &H20
                        params.ClassName = "RICHEDIT50W"
                    End If
                    Return params
                End Get
            End Property




        End Class


VB.NET:
dim transparentrichtextbox1 as transparentrichtextbox


The transparentrichtextbox mouse event should not block the control's features behind it, nor buttons or html links, it should simply allow you to add more of your own related threads to any already built in feature.




VB.NET:
With transparentrichtextbox1
.Location = New Point(WebBrowser1.Location.X, WebBrowser1.Location.Y)
.Width = WebBrowser1.width 
.Height = WebBrowser1.Height
AddHandler transparentrichtextbox1.MouseDown, AddressOf transparentrichtextbox1_Mousedown
End With

Webbrowser1.visible = true
transparentrichtextbox.bringtofront
transparentrichtextbox.visible = true


Make sure you add the sub for transparentrichtextbox1.mousedown And you now have gotten the mouse event with coordinates for any control! Record the coordinates, make the transparentrichtextbox invisible after a click, add a low interval timer to click at a time when the webbrowser or control is finally in focus and make subsequent tick cases call your application threads that are relevant to that click location's feature.
VB.NET:
dim transparent_e as point
 Sub transparentrichtextbox1_Mousedown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)




        transparent_e = New Point(e.X + Me.Location.X + transparentrichtextbox1.Location.X + 10, e.Y + Me.Location.Y + transparentrichtextbox1.Location.Y + 30)




        transparentrichtextbox1.Visible = False
        transparentrichtextbox1.Update()
        transparentrichtextbox1.Refresh()








        timer101 = New DispatcherTimer
        timer101.Interval = New TimeSpan(0, 0, 0, 0, 100)
        AddHandler timer101.Tick, AddressOf timer101tick
        timer101.Start()
    End Sub


The tick sub should click the webbrowser where the event took place, and use following tick cases to add the functionality that you implied, to take place with the cloud or control feature at that mouse location.


VB.NET:
dim tickcase = 0
Sub timer101tick()
 If tickcase = 0 Then
            SetCursorPos(transparentpoint.X, transparentpoint.Y) 
        ElseIf tickcase = 1 Then
            mouse_event(MOUSEEVENTF_LEFTDOWN, transparentpoint.X, transparentpoint.Y, 0, 0)
            mouse_event(MOUSEEVENTF_LEFTUP, transparentpoint.X, transparentpoint.Y, 0, 0)
        Elseif tickcase = 2 Then
           ' if transparentpoint.x and transparentpoint.y is in known function region
           'run your own thread related to that region's click's original function
        Elseif tickcase = 3 then
           'finalize, stop tick and remove handler "timer101tick.stop" and "removehandler timer101.tick, addressof timer101tick"
tickcase +=1


That's all there is to it. You can keep those mouse event locations if you can really make it add to the functionality of the original control.
 

Latest posts

Back
Top