Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#

private void knop2_MouseEnter(object sender, MouseEventArgs e)
{
knop2.Margin = new Thickness(10,10,0,0);


it want to make the button go up a little bit everytime i mouse enter the button, until it disappears from the screen.

What I have tried:

private void knop2_MouseEnter(object sender, MouseEventArgs e)
{
knop2.Margin = new Thickness(different coördinates);
C#

Posted
Updated 20-Feb-18 23:20pm
Comments
BillWoodruff 20-Feb-18 22:35pm    
Why would you want to do this very strange thing ?

the right way of doing this is place your button on canvas or let it be on window .
create an mousemove event for window or canvas for every move it captures the Point .point.x ,point.y
point a=e.getposition(window or canvas)
so place your button ------ PointToScreen(point.x,point.y);
if this is not clear .let me know i ll send the piece of code which works fine.
 
Share this answer
 
v2
Comments
Member 13554627 21-Feb-18 4:26am    
could you send the code just to check myself?
saimanisha 21-Feb-18 5:07am    
ok i will send you sample code by doing it.
Member 13554627 21-Feb-18 5:14am    
thanks!
saimanisha 21-Feb-18 5:19am    
but tell me the correct requirement iam juss posting a sample .try the below code and let me know is that works fine for you.
Member 13554627 21-Feb-18 5:20am    
just a sample with the pointoscreen method is enough
Xaml :
<Grid>
        <Canvas Background="Transparent" Name="canvas" Height="260" Width="280" MouseMove="canvas_MouseMove" >
            <Button Width="31" Height="30" Name="move"  ></Button>
        </Canvas>
    </Grid>


c# :

private void canvas_MouseMove(object sender, MouseEventArgs e)
     {

         Point p = e.GetPosition(canvas);
         move.Margin = new Thickness(p.X, p.Y, 0, 0);

     }
 
Share this answer
 
Comments
Member 13554627 21-Feb-18 5:23am    
thanks!
BillWoodruff 21-Feb-18 7:27am    
I know your intention is to be helpful, but think about the difference between teaching someone in a way that their skills increase because they are actively involved in figuring out the answer/solution for themselves ... compared to writing code for someone.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900