473,408 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 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 3666
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 Word and then my program is sending the left...
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 (a button) when the mouse moves over the...
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 did) he lacks the manual dexterity to use a mouse...
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 have a user control which can be dragged and dropped...
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 click event, perform some action, and then prevent...
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 - places a transparent window over the entire...
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 prevent the user from clicking on it more than once....
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 click on a specific control to deactivate the...
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 programmed. Stop snickering!!! I didn't do it...I...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.