ScrollPanel.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System.ComponentModel;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. namespace PaintDotNet.SystemLayer
  5. {
  6. /// <summary>
  7. /// This is the same as System.Windows.Forms.Panel except for three things:
  8. /// 1. It exposes a Scroll event.
  9. /// 2. It allows you to disable SetFocus.
  10. /// 3. It has a much simplified interface for AutoScrollPosition, exposed via the ScrollPosition property.
  11. /// </summary>
  12. public class ScrollPanel : Panel
  13. {
  14. private bool ignoreSetFocus = false;
  15. /// <summary>
  16. /// Gets or sets whether the control ignores WM_SETFOCUS.
  17. /// </summary>
  18. public bool IgnoreSetFocus
  19. {
  20. get
  21. {
  22. return ignoreSetFocus;
  23. }
  24. set
  25. {
  26. ignoreSetFocus = value;
  27. }
  28. }
  29. /// <summary>
  30. /// Gets or sets the scrollbar position.
  31. /// </summary>
  32. [Browsable(false)]
  33. public Point ScrollPosition
  34. {
  35. get
  36. {
  37. return new Point(-AutoScrollPosition.X, -AutoScrollPosition.Y);
  38. }
  39. set
  40. {
  41. AutoScrollPosition = value;
  42. }
  43. }
  44. protected override void WndProc(ref Message m)
  45. {
  46. switch (m.Msg)
  47. {
  48. case NativeConstants.WM_SETFOCUS:
  49. if (IgnoreSetFocus)
  50. {
  51. return;
  52. }
  53. else
  54. {
  55. goto default;
  56. }
  57. default:
  58. base.WndProc(ref m);
  59. break;
  60. }
  61. }
  62. }
  63. }