MainForm.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. namespace ScreenSaverEf
  5. {
  6. public partial class MainForm : Form
  7. {
  8. readonly Image _imgSky = Properties.Resources.sky;
  9. readonly Image _imgDn = Properties.Resources.dn;
  10. readonly Image _imgC = Properties.Resources.st_kei10a02_;
  11. PointF _posSky;
  12. PointF _posDn;
  13. PointF _posSkyReset;
  14. PointF _posDnReset;
  15. PointF _posC = PointF.Empty;
  16. PointF _posCr;
  17. Rectangle _blkDn;
  18. #region POSC_DATA
  19. readonly float[] _cx = new float[] {
  20. -6,
  21. -5.5F,
  22. -5,
  23. -4,
  24. -3,
  25. -1.5F,
  26. 0,
  27. 1.5F,
  28. 3,
  29. 4,
  30. 5,
  31. 5.5F,
  32. 6,5.5F,5,4,3,1.5F,0,-1.5F,-3,-4,-5,-5.5F,
  33. };
  34. int _cxi = 6;
  35. readonly float[] _cy = new float[] {
  36. -6,
  37. -5,
  38. -3,
  39. 0,
  40. 3,
  41. 5,
  42. 6,5,3,0,-3,-5
  43. };
  44. int _cyi = 3;
  45. #endregion
  46. int? _scrNo;
  47. public MainForm()
  48. {
  49. InitializeComponent();
  50. }
  51. public MainForm(int scrNo)
  52. : this()
  53. {
  54. _scrNo = scrNo;
  55. }
  56. private void Form1_Load(object sender, EventArgs e)
  57. {
  58. var rect = _scrNo.HasValue ? Screen.AllScreens[_scrNo.Value].Bounds : Screen.PrimaryScreen.Bounds;
  59. var p = Location; p.Offset(rect.Location);
  60. Location = p;
  61. Size = rect.Size;
  62. FormBorderStyle = FormBorderStyle.None;
  63. TopMost = true;
  64. ResetPos();
  65. UpdateTimer.Start();
  66. }
  67. private void ResetPos()
  68. {
  69. _posSkyReset = _posSky = new PointF(-_imgSky.Width + Width, (Height - 600) / 2f);
  70. _posDnReset = _posDn = new PointF(-_imgDn.Width + Width, (Height - 600) / 2f);
  71. _posCr = new PointF(Width - _imgC.Width, (Height - 600) / 2f);
  72. _blkDn = new Rectangle(new Point(0, (int)_posSky.Y + _imgSky.Height), new Size(Width, (Height - 600) / 2));
  73. }
  74. private void timer1_Tick(object sender, EventArgs e)
  75. {
  76. _posSky.X += .5f;//.5F;
  77. _posDn.X += 1.5f;//1.5F;
  78. _cxi++;
  79. if (_cxi % 2 == 0)
  80. _cyi++;
  81. if (_cxi > _cx.Length - 1) _cxi = 0;
  82. if (_cyi > _cy.Length - 1) _cyi = 0;
  83. _posC.X = _posCr.X + _cx[_cxi];
  84. _posC.Y = _posCr.Y + _cy[_cyi] - 14;
  85. Invalidate();
  86. }
  87. private void Form1_Paint(object sender, PaintEventArgs e)
  88. {
  89. var dc = e.Graphics;
  90. if (UpdateTimer.Enabled)
  91. {
  92. if (_posSky.X > 0 && _posSky.X <= Width)
  93. dc.DrawImage(_imgSky, new PointF(-_imgSky.Width + _posSky.X, _posSky.Y));
  94. if (_posSky.X > Width)
  95. _posSky.X = _posSkyReset.X;
  96. dc.DrawImage(_imgSky, _posSky);
  97. if (_posDn.X > 0 && _posDn.X <= Width)
  98. dc.DrawImage(_imgDn, new PointF(-_imgDn.Width + _posDn.X, _posDn.Y));
  99. if (_posDn.X > Width)
  100. _posDn.X = _posDnReset.X;
  101. dc.DrawImage(_imgDn, _posDn);
  102. dc.DrawImage(_imgC, _posC);
  103. dc.FillRectangle(Brushes.Black, _blkDn);
  104. }
  105. else
  106. {
  107. dc.DrawString("µã»÷¿ªÊ¼", new Font("΢ÈíÑźÚ", 20), Brushes.White, ClientSize.Width / 2f, ClientSize.Height / 2f);
  108. }
  109. }
  110. private void Form1_MouseClick(object sender, MouseEventArgs e)
  111. {
  112. if (UpdateTimer.Enabled)
  113. Application.Exit();
  114. else
  115. UpdateTimer.Start();
  116. }
  117. private void Form1_Resize(object sender, EventArgs e)
  118. {
  119. ResetPos();
  120. }
  121. private void Form1_KeyPress(object sender, KeyPressEventArgs e)
  122. {
  123. Application.Exit();
  124. }
  125. private void Form1_KeyDown(object sender, KeyEventArgs e)
  126. {
  127. Application.Exit();
  128. }
  129. private void Form1_KeyUp(object sender, KeyEventArgs e)
  130. {
  131. Application.Exit();
  132. }
  133. private void Form1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
  134. {
  135. Application.Exit();
  136. }
  137. }
  138. }