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();
}
本文详细介绍了如何将Winforms中的MouseButton类转换为WPF中的MouseButton类,提供了具体的代码实现,帮助开发者在不同UI系统间进行无缝转换。
638

被折叠的 条评论
为什么被折叠?



