Mouse translation from System.Windows.Forms.MouseButtons to System.Windows.Input.MouseButton

来源:互联网 发布:java中排序函数 编辑:程序博客网 时间:2024/06/05 03:46

In the UI world, there are two system, the Winforms and the WPF.   The WPF ones come later and have a face lift on the overall classes and designs. 


The team has made tremendous effort to bridge the two world. However, situation exists that you have to convert between the two of them , for example the MouseButton class.

  • System.Windows.Forms.MouseButtons
  • System.Windows.Input.MouseButton


Below shows the conversion code that does the code between the two.



    private static MouseButton ToMouseButton(Forms.MouseButtons button)    {      switch (button)      {        case Forms.MouseButtons.Left:          return MouseButton.Left;        case Forms.MouseButtons.Right:          return MouseButton.Right;        case Forms.MouseButtons.Middle:          return MouseButton.Middle;        case Forms.MouseButtons.XButton1:          return MouseButton.XButton1;        case Forms.MouseButtons.XButton2:          return MouseButton.XButton2;      }      throw new InvalidOperationException();    }




原创粉丝点击