472,353 Members | 1,880 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

How to Prevent Mouse Movement and Clicks From Reaching Control

Sorry for reposting this question, but I did not get a single answer last
time, and I'm sure you guys must have some thoughts on the matter.

I have a user control which can be dragged and dropped onto a form in my
application when it is running. I allow it to be clicked and dragged to a
new location on the form. However, the user control has a check box on it,
and if the user clicks over the checkbox to drag the user control, the check
box changes state.

Is there a way that I can simulate the design mode effect of the VS IDE,
such that whilst designing a form controls do not behave in the normal way?
The same problem occurs if clicking over a dropdown list: the list drops
down and then the control can be dragged away from under it. It doesn't look
very good.

It would be nice to stop all mouse effects on the member controls of my user
control, for example, checkboxes with the popup style change their
appearance when the mouse moves over them, but I would like to suppress this
whilst my user control is in 'design mode'.

Just to clarify, although I use the term 'design mode' my application is
actually running. I am just referring to the state in which it is running,
that is I allow users to design a simple form and then turn design mode off,
whereupon the form should behave normally.

TIA

Charles
Nov 20 '05 #1
5 3540
Me.Capture = True

This will keep all of your controls from receiving any mouse messages.
You'll have to move any controls in the Forms mouse move events.

Charles Law wrote:
Sorry for reposting this question, but I did not get a single answer last
time, and I'm sure you guys must have some thoughts on the matter.

I have a user control which can be dragged and dropped onto a form in my
application when it is running. I allow it to be clicked and dragged to a
new location on the form. However, the user control has a check box on it,
and if the user clicks over the checkbox to drag the user control, the check
box changes state.

Is there a way that I can simulate the design mode effect of the VS IDE,
such that whilst designing a form controls do not behave in the normal way?
The same problem occurs if clicking over a dropdown list: the list drops
down and then the control can be dragged away from under it. It doesn't look
very good.

It would be nice to stop all mouse effects on the member controls of my user
control, for example, checkboxes with the popup style change their
appearance when the mouse moves over them, but I would like to suppress this
whilst my user control is in 'design mode'.

Just to clarify, although I use the term 'design mode' my application is
actually running. I am just referring to the state in which it is running,
that is I allow users to design a simple form and then turn design mode off,
whereupon the form should behave normally.

TIA

Charles

Nov 20 '05 #2
Hi yEaH rIgHt

Thanks for the idea. I have just tried it and it all behaves the same, but
the concept seems to be pointing the way. I will read up on it.

I put the Capture = True in the base class of my user controls so that it is
set automatically for anything that inherits from it, unless I have missed
something and I need to put it somewhere else?

Charles
"yEaH rIgHt" <no******@haha.com> wrote in message
news:10*************@corp.supernews.com...
Me.Capture = True

This will keep all of your controls from receiving any mouse messages.
You'll have to move any controls in the Forms mouse move events.

Charles Law wrote:
Sorry for reposting this question, but I did not get a single answer last time, and I'm sure you guys must have some thoughts on the matter.

I have a user control which can be dragged and dropped onto a form in my
application when it is running. I allow it to be clicked and dragged to a new location on the form. However, the user control has a check box on it, and if the user clicks over the checkbox to drag the user control, the check box changes state.

Is there a way that I can simulate the design mode effect of the VS IDE,
such that whilst designing a form controls do not behave in the normal way? The same problem occurs if clicking over a dropdown list: the list drops
down and then the control can be dragged away from under it. It doesn't look very good.

It would be nice to stop all mouse effects on the member controls of my user control, for example, checkboxes with the popup style change their
appearance when the mouse moves over them, but I would like to suppress this whilst my user control is in 'design mode'.

Just to clarify, although I use the term 'design mode' my application is
actually running. I am just referring to the state in which it is running, that is I allow users to design a simple form and then turn design mode off, whereupon the form should behave normally.

TIA

Charles

Nov 20 '05 #3
Try this out (this will do what you want):

Option Explicit On
Option Strict On

Public Class UserControl1
Inherits System.Windows.Forms.UserControl

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'UserControl1 overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents CheckBox1 As System.Windows.Forms.CheckBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.CheckBox1 = New System.Windows.Forms.CheckBox()
Me.SuspendLayout()
'
'CheckBox1
'
Me.CheckBox1.Location = New System.Drawing.Point(72, 56)
Me.CheckBox1.Name = "CheckBox1"
Me.CheckBox1.TabIndex = 1
Me.CheckBox1.Text = "CheckBox1"
'
'UserControl1
'
Me.Controls.AddRange(New System.Windows.Forms.Control()
{Me.CheckBox1})
Me.Name = "UserControl1"
Me.Size = New System.Drawing.Size(288, 160)
Me.ResumeLayout(False)

End Sub

#End Region
Dim drag As Boolean
Private Sub UserControl1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp
If drag Then
drag = False
Me.Capture = False
End If
End Sub

Private Sub UserControl1_MouseMove(ByVal sender As Object, ByVal e
As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
If drag Then
CheckBox1.Location = New Point(e.X, e.Y)
End If

End Sub

Private Sub CheckBox1_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles CheckBox1.MouseMove
If e.Button = MouseButtons.Left Then
Me.Capture = True
drag = True
End If
End Sub
End Class



Charles Law wrote:
Hi yEaH rIgHt

Thanks for the idea. I have just tried it and it all behaves the same, but
the concept seems to be pointing the way. I will read up on it.

I put the Capture = True in the base class of my user controls so that it is
set automatically for anything that inherits from it, unless I have missed
something and I need to put it somewhere else?

Charles
"yEaH rIgHt" <no******@haha.com> wrote in message
news:10*************@corp.supernews.com...
Me.Capture = True

This will keep all of your controls from receiving any mouse messages.
You'll have to move any controls in the Forms mouse move events.

Charles Law wrote:
Sorry for reposting this question, but I did not get a single answer
last
time, and I'm sure you guys must have some thoughts on the matter.

I have a user control which can be dragged and dropped onto a form in my
application when it is running. I allow it to be clicked and dragged to
a
new location on the form. However, the user control has a check box on
it,
and if the user clicks over the checkbox to drag the user control, the
check
box changes state.

Is there a way that I can simulate the design mode effect of the VS IDE,
such that whilst designing a form controls do not behave in the normal
way?
The same problem occurs if clicking over a dropdown list: the list drops
down and then the control can be dragged away from under it. It doesn't
look
very good.

It would be nice to stop all mouse effects on the member controls of my
user
control, for example, checkboxes with the popup style change their
appearance when the mouse moves over them, but I would like to suppress
this
whilst my user control is in 'design mode'.

Just to clarify, although I use the term 'design mode' my application is
actually running. I am just referring to the state in which it is
running,
that is I allow users to design a simple form and then turn design mode
off,
whereupon the form should behave normally.

TIA

Charles


Nov 20 '05 #4
Thanks for the example. I have tried it and it certainly prevents the mouse
click from changing the state of the checkbox.

I then changed the FlatStyle to Popup. If you try this you will see that
when you wave the mouse over the checkbox the appearance changes. This is
also an effect that I am trying to avoid. If I stop the application and open
the user control designer I do not get this effect, so it makes me think
that there is something else that the IDE is doing to achieve this. Any
ideas?

Cheers

Charles
"yEaH rIgHt" <no******@haha.com> wrote in message
news:10*************@corp.supernews.com...
Try this out (this will do what you want):

Option Explicit On
Option Strict On

Public Class UserControl1
Inherits System.Windows.Forms.UserControl

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'UserControl1 overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents CheckBox1 As System.Windows.Forms.CheckBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.CheckBox1 = New System.Windows.Forms.CheckBox()
Me.SuspendLayout()
'
'CheckBox1
'
Me.CheckBox1.Location = New System.Drawing.Point(72, 56)
Me.CheckBox1.Name = "CheckBox1"
Me.CheckBox1.TabIndex = 1
Me.CheckBox1.Text = "CheckBox1"
'
'UserControl1
'
Me.Controls.AddRange(New System.Windows.Forms.Control()
{Me.CheckBox1})
Me.Name = "UserControl1"
Me.Size = New System.Drawing.Size(288, 160)
Me.ResumeLayout(False)

End Sub

#End Region
Dim drag As Boolean
Private Sub UserControl1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp
If drag Then
drag = False
Me.Capture = False
End If
End Sub

Private Sub UserControl1_MouseMove(ByVal sender As Object, ByVal e
As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
If drag Then
CheckBox1.Location = New Point(e.X, e.Y)
End If

End Sub

Private Sub CheckBox1_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles CheckBox1.MouseMove
If e.Button = MouseButtons.Left Then
Me.Capture = True
drag = True
End If
End Sub
End Class



Charles Law wrote:
Hi yEaH rIgHt

Thanks for the idea. I have just tried it and it all behaves the same, but the concept seems to be pointing the way. I will read up on it.

I put the Capture = True in the base class of my user controls so that it is set automatically for anything that inherits from it, unless I have missed something and I need to put it somewhere else?

Charles
"yEaH rIgHt" <no******@haha.com> wrote in message
news:10*************@corp.supernews.com...
Me.Capture = True

This will keep all of your controls from receiving any mouse messages.
You'll have to move any controls in the Forms mouse move events.

Charles Law wrote:

Sorry for reposting this question, but I did not get a single answer


last
time, and I'm sure you guys must have some thoughts on the matter.

I have a user control which can be dragged and dropped onto a form in myapplication when it is running. I allow it to be clicked and dragged to


a
new location on the form. However, the user control has a check box on


it,
and if the user clicks over the checkbox to drag the user control, the


check
box changes state.

Is there a way that I can simulate the design mode effect of the VS IDE,such that whilst designing a form controls do not behave in the normal


way?
The same problem occurs if clicking over a dropdown list: the list dropsdown and then the control can be dragged away from under it. It doesn't


look
very good.

It would be nice to stop all mouse effects on the member controls of my


user
control, for example, checkboxes with the popup style change their
appearance when the mouse moves over them, but I would like to suppress


this
whilst my user control is in 'design mode'.

Just to clarify, although I use the term 'design mode' my application isactually running. I am just referring to the state in which it is


running,
that is I allow users to design a simple form and then turn design mode


off,
whereupon the form should behave normally.

TIA

Charles


Nov 20 '05 #5
That's because the controls on the designer aren't running. When you run
your program they are. There's nothing you can do about it.

Charles Law wrote:
Thanks for the example. I have tried it and it certainly prevents the mouse
click from changing the state of the checkbox.

I then changed the FlatStyle to Popup. If you try this you will see that
when you wave the mouse over the checkbox the appearance changes. This is
also an effect that I am trying to avoid. If I stop the application and open
the user control designer I do not get this effect, so it makes me think
that there is something else that the IDE is doing to achieve this. Any
ideas?

Cheers

Charles
"yEaH rIgHt" <no******@haha.com> wrote in message
news:10*************@corp.supernews.com...
Try this out (this will do what you want):

Option Explicit On
Option Strict On

Public Class UserControl1
Inherits System.Windows.Forms.UserControl

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'UserControl1 overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form


Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents CheckBox1 As System.Windows.Forms.CheckBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.CheckBox1 = New System.Windows.Forms.CheckBox()
Me.SuspendLayout()
'
'CheckBox1
'
Me.CheckBox1.Location = New System.Drawing.Point(72, 56)
Me.CheckBox1.Name = "CheckBox1"
Me.CheckBox1.TabIndex = 1
Me.CheckBox1.Text = "CheckBox1"
'
'UserControl1
'
Me.Controls.AddRange(New System.Windows.Forms.Control()
{Me.CheckBox1})
Me.Name = "UserControl1"
Me.Size = New System.Drawing.Size(288, 160)
Me.ResumeLayout(False)

End Sub

#End Region
Dim drag As Boolean
Private Sub UserControl1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp
If drag Then
drag = False
Me.Capture = False
End If
End Sub

Private Sub UserControl1_MouseMove(ByVal sender As Object, ByVal e
As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
If drag Then
CheckBox1.Location = New Point(e.X, e.Y)
End If

End Sub

Private Sub CheckBox1_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles CheckBox1.MouseMove
If e.Button = MouseButtons.Left Then
Me.Capture = True
drag = True
End If
End Sub
End Class



Charles Law wrote:
Hi yEaH rIgHt

Thanks for the idea. I have just tried it and it all behaves the same,
but
the concept seems to be pointing the way. I will read up on it.

I put the Capture = True in the base class of my user controls so that
it is
set automatically for anything that inherits from it, unless I have
missed
something and I need to put it somewhere else?

Charles
"yEaH rIgHt" <no******@haha.com> wrote in message
news:10*************@corp.supernews.com...
Me.Capture = True

This will keep all of your controls from receiving any mouse messages.
You'll have to move any controls in the Forms mouse move events.

Charles Law wrote:
>Sorry for reposting this question, but I did not get a single answer

last
>time, and I'm sure you guys must have some thoughts on the matter.
>
>I have a user control which can be dragged and dropped onto a form in
my
application when it is running. I allow it to be clicked and dragged to

a
>new location on the form. However, the user control has a check box on

it,
>and if the user clicks over the checkbox to drag the user control, the

check
>box changes state.
>
>Is there a way that I can simulate the design mode effect of the VS
IDE,
such that whilst designing a form controls do not behave in the normal

way?
>The same problem occurs if clicking over a dropdown list: the list
drops
down and then the control can be dragged away from under it. It doesn't

look
>very good.
>
>It would be nice to stop all mouse effects on the member controls of my

user
>control, for example, checkboxes with the popup style change their
>appearance when the mouse moves over them, but I would like to suppress

this
>whilst my user control is in 'design mode'.
>
>Just to clarify, although I use the term 'design mode' my application
is
actually running. I am just referring to the state in which it is

running,
>that is I allow users to design a simple form and then turn design mode

off,
>whereupon the form should behave normally.
>
>TIA
>
>Charles
>
>


Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: BadOmen | last post by:
I want my program to send a mouse click to the window at the current mouse position, how do I do that? Example: I have my mouse over a button in...
3
by: red | last post by:
mouse events when the mouse is on a "child control" hi everyone; my problem: I have a userControl in this usercontrol, I have a child control...
13
by: James Bond | last post by:
Hello. My 80+ year old father has recently decided to get his first computer. Due to his age (and I suspect lack of playing pong as a child like I...
3
by: Charles Law | last post by:
Sorry for reposting this question, but I did not get a single answer last time, and I'm sure you guys must have some thoughts on the matter. I...
24
by: Charles Law | last post by:
When I click a button I don't want the click event to fire. Is this possible? In fact, what I would really like is to be able to intercept the...
20
by: Charles Law | last post by:
This is actually a follow on from yesterday's post about masking mouse clicks in a user control. The solution I have implemented - from Herfried...
5
by: Vincent | last post by:
I have a bound listbox control on one of my forms that has an associated afterupdate event. When this event is invoked, I lock the control to...
5
by: nuhfeken | last post by:
We have a C# winform that uses the MVP design pattern for the user interface. For reasons I'd rather not explain we need to simulate a right mouse...
4
by: mike | last post by:
I have the opportunity to rescue a project that uses a mouse to sense the relative position of a machine. The hardware is built...just needs to be...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.