1. 程式人生 > >C# .Net Winform視窗特效處理

C# .Net Winform視窗特效處理

  1. public class FormAutoDock
  2. {
  3. public static void SideHideOrShow(Form DockableForm, ref int DockFormHeight, Timer _dockTimer)
  4. {
  5. if (DockableForm.WindowState != FormWindowState.Minimized)
  6. {
  7. _dockTimer.Interval = 1500;
  8. if (Cursor.Position.X > DockableForm.Left - 1 && Cursor.Position.X < DockableForm.Right && Cursor.Position.Y > DockableForm.Top - 1 && Cursor.Position.Y < DockableForm.Bottom)
  9. {
  10. if (DockableForm.Top <= 0 && DockableForm.Left > 5 && DockableForm.Left < Screen.PrimaryScreen.WorkingArea.Width - DockableForm.Width)
  11. {
  12. DockableForm.Top = 0;
  13. }
  14. else if (DockableForm.Left <= 0)
  15. {
  16. DockableForm.Left = 0;
  17. }
  18. else if (DockableForm.Left + DockableForm.Width >= Screen.PrimaryScreen.WorkingArea.Width)
  19. {
  20. DockableForm.Left = Screen.PrimaryScreen.WorkingArea.Width - DockableForm.Width;
  21. }
  22. else
  23. {
  24. if (DockFormHeight > 0)
  25. {
  26. DockableForm.Height = DockFormHeight;
  27. DockFormHeight = 0;
  28. }
  29. }
  30. }
  31. else
  32. {
  33. if (DockFormHeight < 1)
  34. {
  35. DockFormHeight = DockableForm.Height;
  36. }
  37. if (DockableForm.Top <= 4 && DockableForm.Left > 5 && DockableForm.Left < Screen.PrimaryScreen.WorkingArea.Width - DockableForm.Width)
  38. {
  39. DockableForm.Top = 3 - DockableForm.Height;
  40. if (DockableForm.Left <= 4)
  41. {
  42. DockableForm.Left = -5;
  43. }
  44. else if (DockableForm.Left + DockableForm.Width >= Screen.PrimaryScreen.WorkingArea.Width - 4)
  45. {
  46. DockableForm.Left = Screen.PrimaryScreen.WorkingArea.Width - DockableForm.Width + 5;
  47. }
  48. }
  49. else if (DockableForm.Left <= 4)
  50. {
  51. DockableForm.Left = 3 - DockableForm.Width;
  52. }
  53. else if (DockableForm.Left + DockableForm.Width >= Screen.PrimaryScreen.WorkingArea.Width - 4)
  54. {
  55. DockableForm.Left = Screen.PrimaryScreen.WorkingArea.Width - 3;
  56. }
  57. _dockTimer.Interval = 200;
  58. }
  59. }
  60. }
  61. }