У меня есть кнопка внутри WinformHost, и я хочу переместить ее в любую позицию внутри WindowsFormsHost с помощью мыши. Я сделал, как показано ниже. Но это мерцание, когда наведите курсор мыши на кнопку. Пожалуйста, помогите исправить.
<Grid x:Name="myGrid" Background="Transparent" Height="400" Width="700">
<WindowsFormsHost Height="200" HorizontalAlignment="Left" Margin="10,108,0,0" Name="windowsFormsHost1" VerticalAlignment="Top" Width="200" Background="PaleVioletRed">
<wf:FlowLayoutPanel Name="FlowPanel" BackColor="Red" Dock="Fill">
<wf:Panel.Controls>
<wf:Button x:Name="Btn1" MouseMove="Btn1_MouseMove" MouseDown="Btn1_MouseDown" Width="120" Height="120" Text="BTN1" BackColor="yellow"></wf:Button>
<wf:Button x:Name="Btn2" Width="120" Height="120" Text="BTN2" BackColor="Red"></wf:Button>
</wf:Panel.Controls>
</wf:FlowLayoutPanel>
</WindowsFormsHost>
</Grid>
private System.Drawing.Point MouseDownLocation;
private void Btn1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
btn1.Left = e.X + btn1.Left - MouseDownLocation.X;
btn1.Top = e.Y + btn1.Top - MouseDownLocation.Y;
}
}
private void Btn1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
MouseDownLocation = e.Location;
}
}