2017-11-18 8 views
0

実際にC#wpfでJarvis AIプログラムを作成しようとしていますが、コード内で例外が発生しています。実際問題は、実行中のアプリケーションでマウスの右ボタンを押すと、アプリケーションが動かなくなってクラッシュする場合があります。誰でもこの問題を解決できます。WPFアプリケーションが右マウスボタンを押したときにクラッシュする

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Data; 
using System.Windows.Documents; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Imaging; 
using System.Windows.Navigation; 
using System.Windows.Shapes; 

namespace jarvis 
{ 
    /// <summary> 
    /// Interaction logic for MainWindow.xaml 
    /// </summary> 
    public partial class MainWindow : Window 
    { 
     public MainWindow() 
     { 
      InitializeComponent(); 
     } 

     private void Grid_MouseDown(object sender, MouseButtonEventArgs e) 
     { 
      this.DragMove(); 
     } 



    } 
} 

答えて

0

は、私はこれらのコードを使用しているし、それが実際に

public const int WM_NCLBUTTONDOWN = 0xA1; 
public const int HT_CAPTION = 0x2; 

[DllImportAttribute("user32.dll")] 
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam); 
[DllImportAttribute("user32.dll")] 
public static extern bool ReleaseCapture(); 

は、実際に私は私のWPFアプリケーション、との問題を抱えている。この

if (e.Button == MouseButtons.Left) 
      { 
       ReleaseCapture(); 
       SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0); 
      } 
0

私が何を達成しようとしているかわからないが、あなたはマウスの左ボタンでウィンドウを移動したい場合は、単に条件を追加:DragMoveでInvalidOperationExceptionが()メソッドを引き起こし

private void Grid_MouseDown(object sender, MouseButtonEventArgs e) 
{ 
    if(e.LeftButton == MouseButtonState.Pressed) 
     this.DragMove(); 
} 

その他のマウスボタン。 ウィンドウの移動にマウスの右ボタンを使用する場合は、そのためのカスタムメソッドを記述する必要があります。

+0

のように、フォームのマウスダウンイベントにReleaseCaptureメソッドを使用して動作しますとき、これまで私実行中のアプリケーション上でマウスの右ボタンを押すと、スタックされ、クラッシュします。これを解決する方法。 –

+0

** Grid_MouseDown **メソッドを上記のコードで置き換えてみてください。これで問題は解決します。 –

関連する問題