TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
eternauta109 eternauta109
NA
2
606
Some Problems with the event handler
May 6 2017 4:26 PM
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.
Reply
Answers (
0
)
C# coding issue
Can you install two issue vb 2010 and vb 2015 in same laptop