code_junkie

Set same icon for all my Forms

Nov 11th, 2011
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. public MyCustomForm()
  2. {
  3. Icon = GetExecutableIcon();
  4. }
  5.  
  6. public Icon GetExecutableIcon()
  7. {
  8. IntPtr large;
  9. IntPtr small;
  10. ExtractIconEx(Application.ExecutablePath, 0, out large, out small, 1);
  11. return Icon.FromHandle(small);
  12. }
  13.  
  14. [DllImport("Shell32")]
  15. public static extern int ExtractIconEx(
  16. string sFile,
  17. int iIndex,
  18. out IntPtr piLargeVersion,
  19. out IntPtr piSmallVersion,
  20. int amountIcons);
  21.  
  22. public new Form Owner {
  23. set {
  24. this.Icon = (value == null ? null : value.Icon);
  25. base.Owner = value;
  26. }
  27.  
  28. get {
  29. return base.Owner;
  30. }
  31. }
  32.  
  33. form.icon = MainFrom.Icon
  34.  
  35. Icon = MainFrom.Icon
Add Comment
Please, Sign In to add comment