Hi,@MERUN KUMAR MAITY. Welcome to Microsoft Q&A.
- Error Causes for Stack Overflow The program starts with the Main function as the entry function .If you use the parameter args[0] of the entry function, it means that the program needs to be executed in the console and pass the parameters, but you did not pass the parameters of the entry function, so an error is reported
- Modify mouse speed in WPF
public const UInt32 SPI_SETMOUSESPEED = 0x0071;
uint newSpeed=20; // Set the speed of your mouse(1-20);The default value is 10
[DllImport("User32.dll")]
static extern Boolean SystemParametersInfo(UInt32 uiAction,UInt32 uiParam,UInt32 pvParam,UInt32 fWinIni);
public void Fun()
{
bool result = SystemParametersInfo(SPI_SETMOUSESPEED, 0, newSpeed, 0);
}
- By default, WPF executes the event for the topmost control
- Refer to the example
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="3*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Rectangle Name="rect1" Fill="SkyBlue" MouseMove="rect1_MouseMove" Width="200" Height="200" HorizontalAlignment="Center" Margin="0,0,0,0"/>
<Ellipse Name="rect2" Fill="DarkOrange" MouseMove="rect2_MouseMove" Width="200" Height="200" HorizontalAlignment="Center" Margin="150,0,0,0"/>
<Polygon Name="rect3" Points="100,100 200,200 0,200" Stroke="Black" MouseMove="rect3_MouseMove" StrokeThickness="2" Margin="350,0,0,0" Fill="YellowGreen"/>
<TextBlock Grid.Row="1" Name="lblInfo"></TextBlock>
</Grid>
public partial class MainWindow : Window
{
public const UInt32 SPI_SETMOUSESPEED = 0x0071;
uint newSpeed; // Set the speed of your mouse(1-20);The default value is 10
[DllImport("User32.dll")]
static extern Boolean SystemParametersInfo(UInt32 uiAction,UInt32 uiParam,UInt32 pvParam,UInt32 fWinIni);
public MainWindow()
{
InitializeComponent();
}
private void rect1_MouseMove(object sender, MouseEventArgs e)
{
Point pt = e.GetPosition(this); //Get the position of the mouse
newSpeed = 10;
bool result = SystemParametersInfo(SPI_SETMOUSESPEED, 0, newSpeed, 0);
if (result == true)
{
this.lblInfo.Text = $"Speed 1x ({pt.X},{pt.Y})";
}
else
{
this.lblInfo.Text = $"Speed set failure";
}
}
private void rect2_MouseMove(object sender, MouseEventArgs e)
{
Point pt = e.GetPosition(this); //Get the position of the mouse
bool result = SystemParametersInfo(SPI_SETMOUSESPEED, 0, newSpeed, 0);
if(result==true)
{
this.lblInfo.Text = $"Speed 2x ({pt.X},{pt.Y})";
}
else
{
this.lblInfo.Text = $"Speed set failure";
}
}
private void rect3_MouseMove(object sender, MouseEventArgs e)
{
Point pt = e.GetPosition(this); //Get the position of the mouse
newSpeed = 5;
bool result = SystemParametersInfo(SPI_SETMOUSESPEED, 0, newSpeed, 0);
if (result == true)
{
this.lblInfo.Text = $"Speed 3x ({pt.X},{pt.Y})";
}
else
{
this.lblInfo.Text = $"Speed set failure";
}
}
}
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.