code_junkie

Using events in IE hosted windows form controls

Nov 12th, 2011
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. //Control Code:
  2. public class CardReader : Panel,ICardReaderEvents, ICardReaderProperties
  3. {
  4. public void Error()
  5. {
  6. }
  7. public void Success()
  8. {
  9. }
  10. }
  11.  
  12. //Interface for events
  13. [Guid("DD0C202B-12B4-4457-9FC6-05F88A6E8BC5")]
  14. [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
  15. public interface ICardReaderEvents
  16. {
  17. [DispId(0x60020000)]
  18. void Error();
  19.  
  20. [DispId(0x60020001)]
  21. void Success();
  22. }
  23.  
  24. //Interface for public properties/methods
  25. public interface ICardReaderProperties
  26. {
  27. ...
  28. }
  29.  
  30. //JavaScript to handle events
  31. <SCRIPT FOR="CardReader1" EVENT="Error">
  32. window.status = "Error...";
  33. </SCRIPT>
  34.  
  35. <SCRIPT FOR="CardReader1" EVENT="Success">
  36. window.alert("Success");
  37. window.status = "";
  38. </SCRIPT>
  39.  
  40. public event Error;
  41. public event Success;
  42.  
  43. protected void OnError()
  44. {
  45. if(Error != null)
  46. Error();
  47. }
  48.  
  49. protected void OnSuccess()
  50. {
  51. if(Success != null)
  52. Success();
  53. }
  54.  
  55. <object id="CR" ...></object>
  56.  
  57. <script type="text/javascript">
  58. function CR::Error()
  59. {
  60. alert("Error!");
  61. }
  62.  
  63. function CR::Success()
  64. {
  65. alert("Success");
  66. }
  67. </script>
Add Comment
Please, Sign In to add comment