2

I want to use the new Key Enumeration in my ObjectModel to avoid having a reference to Windows.Forms in this Dll. The GUI uses a class library that wants the Keys enumeration.

Is it possible in any way to convert a Key value to a Keys value?

EDIT: I just found out that my question was already asked and answered here: How can I convert 'System.Windows.Input.Key' to 'System.Windows.Forms.Keys'?

Community
  • 1
  • 1
testalino
  • 5,474
  • 6
  • 36
  • 48

2 Answers2

5

You can use KeyInterop.VirtualKeyFromKey Method to convert to a Win32 key, and then directly cast to winforms Keys.

Simon Mourier
  • 132,049
  • 21
  • 248
  • 298
0

I would say if you want to use a type declared in another assembly, in your case the enum, you should copy the whole definition in your own assembly, basically declaring it again.

what is worse then? having a cloned declaration or referencing windows.forms.dll ?

Davide Piras
  • 43,984
  • 10
  • 98
  • 147