|
i used mouse enter event for set opacity=1 and mouse leaver event for set opacity=0.5 but when i used mouse enter event and mouse leaver event on my form it only works on particular form it does not work for button and lable for the same form please help me.. |
| roxcon Thursday, June 11, 2009 1:43 AM |
Well, the reason for this behavior is that when teh mouse moves over the button: it is a scenario of Form1_MouseLeave for the Form. The Form considers that the mouse has left focus from myself(Form). Since, now teh focus is on button and not form. One simple way to solve this could be to write the below mentioned codeon the MouseEnter events for the button and label also:
private void button1_MouseEnter(object sender, EventArgs e)
{
this.Opacity = 1;
}
And, similarlly for label also.
Regards,
Lakra :)
- If the post is helpful or answers your question, please mark it as such. - Marked As Answer byKira QianMSFT, ModeratorWednesday, June 17, 2009 6:12 AM
-
|
| Abhijeet Lakra Thursday, June 11, 2009 2:27 AM |
After a bit of thinking, here, comes my simpleand smart :) solution: Add that event for a button(button1) and then- Add the following code in your Form's constructor:
public Form1()
{
InitializeComponent();
foreach (Control cntrl in this.Controls)
{
cntrl.MouseEnter += new System.EventHandler(this.button1_MouseEnter);
}
}
The code is self explanatory. Would be glad to know if it works for your requirement.
Regards,
Lakra :)
- If the post is helpful or answers your question, please mark it as such. - Marked As Answer byKira QianMSFT, ModeratorWednesday, June 17, 2009 6:12 AM
-
|
| Abhijeet Lakra Thursday, June 11, 2009 4:41 AM |
http://social.msdn.microsoft.com/forums/en-US/Vsexpressvcs/thread/140a5498-9299-49dd-a0cb-294a2948eb92/ see this for the best solution u can solve it as i do :) - Marked As Answer byKira QianMSFT, ModeratorWednesday, June 17, 2009 6:12 AM
-
|
| roxcon Friday, June 12, 2009 6:38 AM |
There is another problem atleast when i ran the code. If the mouse moves out of the client area of the form i.e. if i move the mouse to the title bar it changes the opacity again.
Kavitesh Singh.
i think u hv 2 add mouseleaver event to solve that problem - Marked As Answer byKira QianMSFT, ModeratorWednesday, June 17, 2009 6:12 AM
-
|
| roxcon Thursday, June 11, 2009 7:51 AM |
Can you share: 1. For which controls does it work? 2. Code sample would be good. Regards,
Lakra :)
- If the post is helpful or answers your question, please mark it as such. |
| Abhijeet Lakra Thursday, June 11, 2009 1:53 AM |
only form for it does work. but button,lable does not work for the same form
private void Form1_MouseEnter(object sender, EventArgs e)
{
this.Opacity = 1;
}
private void Form1_MouseLeave(object sender, EventArgs e)
{
this.Opacity = 0.5;
} |
| roxcon Thursday, June 11, 2009 1:59 AM |
Well, the reason for this behavior is that when teh mouse moves over the button: it is a scenario of Form1_MouseLeave for the Form. The Form considers that the mouse has left focus from myself(Form). Since, now teh focus is on button and not form. One simple way to solve this could be to write the below mentioned codeon the MouseEnter events for the button and label also:
private void button1_MouseEnter(object sender, EventArgs e)
{
this.Opacity = 1;
}
And, similarlly for label also.
Regards,
Lakra :)
- If the post is helpful or answers your question, please mark it as such. - Marked As Answer byKira QianMSFT, ModeratorWednesday, June 17, 2009 6:12 AM
-
|
| Abhijeet Lakra Thursday, June 11, 2009 2:27 AM |
are not there any simple methods? because i have too many button and labels on the form so it's impossible to do for all. |
| roxcon Thursday, June 11, 2009 3:07 AM |
After a bit of thinking, here, comes my simpleand smart :) solution: Add that event for a button(button1) and then- Add the following code in your Form's constructor:
public Form1()
{
InitializeComponent();
foreach (Control cntrl in this.Controls)
{
cntrl.MouseEnter += new System.EventHandler(this.button1_MouseEnter);
}
}
The code is self explanatory. Would be glad to know if it works for your requirement.
Regards,
Lakra :)
- If the post is helpful or answers your question, please mark it as such. - Marked As Answer byKira QianMSFT, ModeratorWednesday, June 17, 2009 6:12 AM
-
|
| Abhijeet Lakra Thursday, June 11, 2009 4:41 AM |
There is another problem atleast when i ran the code. If the mouse moves out of the client area of the form i.e. if i move the mouse to the title bar it changes the opacity again.
Kavitesh Singh. |
| Kavitesh Singh Thursday, June 11, 2009 5:53 AM |
After a bit of thinking, here, comes my simpleand smart :) solution: Add that event for a button(button1) and then- Add the following code in your Form's constructor:
public
Form1()
{
InitializeComponent();
foreach
(Control cntrl in
this
.Controls)
{
cntrl.MouseEnter += new
System.EventHandler(this
.button1_MouseEnter);
}
}
The code is self explanatory. Would be glad to know if it works for your requirement.
Regards, Lakra :) - If the post is helpful or answers your question, please mark it as such.
i appreciate your help but im not only asking for a button i have several button and lables and other controls in same form |
| roxcon Thursday, June 11, 2009 7:50 AM |
There is another problem atleast when i ran the code. If the mouse moves out of the client area of the form i.e. if i move the mouse to the title bar it changes the opacity again.
Kavitesh Singh.
i think u hv 2 add mouseleaver event to solve that problem - Marked As Answer byKira QianMSFT, ModeratorWednesday, June 17, 2009 6:12 AM
-
|
| roxcon Thursday, June 11, 2009 7:51 AM |
There is another problem atleast when i ran the code. If the mouse moves out of the client area of the form i.e. if i move the mouse to the title bar it changes the opacity again.
Kavitesh Singh.
i think u hv 2 add mouseleaver event to solve that problem
I used the code below for the testing purpose which had both the events set.
private void Form1_MouseEnter(object sender, EventArgs e)
{
this.Opacity = 1;
}
private void Form1_MouseLeave(object sender, EventArgs e)
{
this.Opacity = 0.5;
}
Kavitesh Singh. |
| Kavitesh Singh Friday, June 12, 2009 5:23 AM |
http://social.msdn.microsoft.com/forums/en-US/Vsexpressvcs/thread/140a5498-9299-49dd-a0cb-294a2948eb92/ see this for the best solution u can solve it as i do :) - Marked As Answer byKira QianMSFT, ModeratorWednesday, June 17, 2009 6:12 AM
-
|
| roxcon Friday, June 12, 2009 6:38 AM |