Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
0
Reply
Some Problems with the event handler
eternauta109 eternauta109
May 6 2017 4:26 PM
267
Reply
Hi guys,
I would to like build a user control, called Cluster, with a little simple feauture:
This must to change color if happen a mouse move on with the left click buttun pressed.
My achivment is to change color to some closed cluster when i go over it with the mouse while the left click is pressed.
So my problem is that when i leave a control and my left buttun is pressed, i can't intercept the new cluster and not to be abble to opertate on this one, because the event mousedown its still alive.
I hope to have explained it in some way.
i build all my cluster in the with this code:
private
void
Form1_Load(
object
sender, EventArgs e)
{
int
app = 0;
for
(
int
i = 0; i < panel1.Right; i += 15)
{
Cluster cluster =
new
Cluster();
app += 30;
cluster.Left = app;
cluster.Name =
"cluster"
+ i;
panel1.Controls.Add(cluster);
}
}
and this is my user control Cluster:
public
Cluster()
{
InitializeComponent();
}
private
void
Cluster_Load(
object
sender, EventArgs e)
{
this
.BackColor = Color.Gray;
}
private
void
Cluster_MouseDown(
object
sender, MouseEventArgs e)
{
switch
(Control.MouseButtons)
{
case
MouseButtons.Left:
this
.BackColor = Color.Green;
break
;
case
MouseButtons.Right:
this
.BackColor = Color.Gray;
break
;
}
}
private
void
Cluster_MouseMove(
object
sender, MouseEventArgs e)
{
if
(e.X <
this
.Width)
{
(Application.OpenForms[
"Form1"
]).Controls[
"txtProva"
].Text = Convert.ToString(e.X);
}
else
{
this
.MouseDown -
null
;
// i'll hope to lose the handler with this command
this
.MouseDown -= Cluster_MouseDown;
}
switch
(Control.MouseButtons)
{
case
MouseButtons.Left:
this
.BackColor = Color.Green;
break
;
case
MouseButtons.Right:
this
.BackColor = Color.Gray;
break
;
}
}
I really sorry for my English, thank you every body to read this post.
Et.
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
0
)
Next Recommended Forum
C# coding issue
Can you install two issue vb 2010 and vb 2015 in same laptop