[RESOLVED] Fire MouseDown and MouseUp in same Event
Hello,
I'm wondering if someone can help me.
I have a ToolStrip in top of a form and i use it as a Title Menu with a label for Title and a Button to close the form.
I use it because it's rendered with the aspect that i like.
I can move the form with MouseMove Event
What i can't do in same click is change the opacity of the Form when Mouse is Down and change again when Mouse is Up.
At this moment i need 2 clicks to this operation.
In MouseDown event i have me.opacity=0.5
In MouseUp event i have: me.opacity=1
When i press the mouse button the opacity is changed (50%), but when i release the mouse nothing happens. Clicking again and the opacity is changed to 100% again.
I don't know if this have something to do with DoubleClick but can't discover the solution.
Thanks in advanced and sorry my poor English.
Re: Fire MouseDown and MouseUp in same Event
Re: Fire MouseDown and MouseUp in same Event
Got to say it works absolutely fine for me without the extra comand suggested by db so I guess we need to see code to find what other factors may be affecting it.
Re: Fire MouseDown and MouseUp in same Event
Quote:
Originally Posted by
dunfiddlin
Got to say it works absolutely fine for me without the extra comand suggested by db so I guess we need to see code to find what other factors may be affecting it.
And i must say it works fine for me too...
I explaine. I didn't told you but i have an instruction to move the borderless form at MouseMove.
Disable this instruction at MouseMove, all works fine with MouseDown and MouseUp Events.
At this point my problem is to move the borderless form with opacity at 50% and make it available at 100% when stop moving the form.
My code in MouseMove Event is this:
Code:
If e.Button = MouseButtons.Left Then
ReleaseCapture()
SendMessage(varForm.Handle.ToInt32, WM_NCLBUTTONDOWN, HTCAPTION, 0&)
End If
You must first declare some stuff:
Code:
Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Declare Sub ReleaseCapture Lib "User32" ()
Const WM_NCLBUTTONDOWN As Integer = &HA1
Const HTCAPTION As Integer = 2
I can move the form with opacity at 50%, but releasing the mouse the form don't turn to 100% of the opacity!
Any Help!? Thank you both for your suggestions!
Re: Fire MouseDown and MouseUp in same Event
If e.Button = MouseButtons.Left Then
ReleaseCapture()
SendMessage(Me.Handle.ToInt32, WM_NCLBUTTONDOWN, HTCAPTION, 0&)
Else
Me.Opacity = 1
End If
Re: Fire MouseDown and MouseUp in same Event
@dunfiddlin, that will only restore the opacity if you right or middle click on the form.
The thing is that normally when a WM_NCLBUTTONDOWN message is sent it will be followed by a WM_NCLBUTTONUP message when you release the mouse button. However before that message is sent a WM_NCHITTEST message is sent and the UP message will only be sent if that results in HTCAPTION. Since you send the WM_NCLBUTTONDOWN, HTCAPTION while the mouse isn't over the caption area the WM_NCLBUTTONUP message will never be sent (unless you release the mouse button and move the cursor over the caption area). But the key here is that a WM_NCHITTEST message will always be sent and you can use that by overriding the default windows procedure.
Code:
Protected Overrides Sub DefWndProc(ByRef msg As Message)
Const WM_NCHITTEST As Integer = &H84
Const HTCLIENT As Integer = 1
If msg.Msg = WM_NCHITTEST Then
MyBase.DefWndProc(msg)
If msg.Result = HTCLIENT Then
Me.Opacity = 1.0
End If
Else
MyBase.DefWndProc(msg)
End If
End Sub
Re: Fire MouseDown and MouseUp in same Event
Quote:
Originally Posted by
aemule
I can move the form with opacity at 50%, but releasing the mouse the form don't turn to 100% of the opacity!
Any Help!? Thank you both for your suggestions!
Because you released the capture, when mouse is released any code after sendmessage then runs, example...
Code:
Private Sub Form1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
If e.Button = MouseButtons.Left Then
Me.Opacity = 0.5
ReleaseCapture()
SendMessage(Me.Handle.ToInt32, WM_NCLBUTTONDOWN, HTCAPTION, 0&)
Me.Opacity = 1.0
End If
End Sub
2 Attachment(s)
Re: Fire MouseDown and MouseUp in same Event
Thank you all for your help.
It's working now.
DECLARATIONS
Code:
Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Const WM_NCLBUTTONDOWN As Integer = &HA1
Const HTCAPTION As Integer = 2
CODE
Code:
Private Sub Form1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
If e.Button = MouseButtons.Left Then
Me.Opacity = 0.5
SendMessage(Me.Handle.ToInt32, WM_NCLBUTTONDOWN, HTCAPTION, 0&)
Me.Opacity = 1.0
End If
End Sub
I share the result with you!
Sample Image:
Attachment 95627
Sample Application With Code:
Attachment 95625