fork download
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. using System.Diagnostics;
  5. using System.Timers;
  6.  
  7. namespace WindowsFormsApplication3
  8. {
  9. public partial class Form1 : Form
  10. {
  11. const double MaxPixelPerSec = 500;
  12. float x = 0;
  13. Stopwatch Stopwatch = new Stopwatch();
  14. System.Timers.Timer Timer2 = new System.Timers.Timer();
  15.  
  16. public Form1()
  17. {
  18. InitializeComponent();
  19. UpdatePixelPerSec();
  20. Timer2.SynchronizingObject = this;
  21. UpdateTimerInterval();
  22. Timer2.Elapsed += Timer2_Elapsed;
  23. Timer2.Start();
  24. }
  25.  
  26. public double PixelPerSec
  27. {
  28. get
  29. {
  30. return Math.Round(MaxPixelPerSec * tbSpeedInPercentage.Value / 100, 2);
  31. }
  32. }
  33.  
  34. private void Timer2_Elapsed(object sender, ElapsedEventArgs e)
  35. {
  36. var bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
  37. var r = pictureBox1.Height / 2;
  38. x += (float)(PixelPerSec * Stopwatch.Elapsed.TotalSeconds);
  39. if (x > pictureBox1.Width) x -= pictureBox1.Width + 2 * r;
  40. Stopwatch.Restart();
  41.  
  42. using (var g = Graphics.FromImage(bmp))
  43. {
  44. g.Clear(Color.White);
  45. using (var br = new SolidBrush(Color.Red))
  46. {
  47. g.FillEllipse(br, x, 0, r * 2, r * 2);
  48. }
  49. }
  50. pictureBox1.Image = bmp;
  51. }
  52.  
  53. private void UpdateTimerInterval()
  54. {
  55. Timer2.Interval = 1000 / tbFrameRate.Value;
  56. lblFps.Text = tbFrameRate.Value.ToString();
  57. }
  58.  
  59. private void UpdatePixelPerSec()
  60. {
  61. lblPixelPerSec.Text = PixelPerSec.ToString("F2");
  62. }
  63.  
  64. private void tbFrameRate_ValueChanged(object sender, EventArgs e)
  65. {
  66. UpdateTimerInterval();
  67. }
  68.  
  69. private void tbSpeedInPercentage_ValueChanged(object sender, EventArgs e)
  70. {
  71. UpdatePixelPerSec();
  72. }
  73. }
  74.  
  75. partial class Form1
  76. {
  77. /// <summary>
  78. /// 必要なデザイナー変数です。
  79. /// </summary>
  80. private System.ComponentModel.IContainer components = null;
  81.  
  82. /// <summary>
  83. /// 使用中のリソースをすべてクリーンアップします。
  84. /// </summary>
  85. /// <param name="disposing">マネージ リソースを破棄する場合は true を指定し、その他の場合は false を指定します。</param>
  86. protected override void Dispose(bool disposing)
  87. {
  88. if (disposing && (components != null))
  89. {
  90. components.Dispose();
  91. }
  92. base.Dispose(disposing);
  93. }
  94.  
  95. #region Windows フォーム デザイナーで生成されたコード
  96.  
  97. /// <summary>
  98. /// デザイナー サポートに必要なメソッドです。このメソッドの内容を
  99. /// コード エディターで変更しないでください。
  100. /// </summary>
  101. private void InitializeComponent()
  102. {
  103. this.pictureBox1 = new System.Windows.Forms.PictureBox();
  104. this.tbFrameRate = new System.Windows.Forms.TrackBar();
  105. this.tbSpeedInPercentage = new System.Windows.Forms.TrackBar();
  106. this.label1 = new System.Windows.Forms.Label();
  107. this.lblFps = new System.Windows.Forms.Label();
  108. this.lblPixelPerSec = new System.Windows.Forms.Label();
  109. this.label4 = new System.Windows.Forms.Label();
  110. ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
  111. ((System.ComponentModel.ISupportInitialize)(this.tbFrameRate)).BeginInit();
  112. ((System.ComponentModel.ISupportInitialize)(this.tbSpeedInPercentage)).BeginInit();
  113. this.SuspendLayout();
  114. //
  115. // pictureBox1
  116. //
  117. this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  118. | System.Windows.Forms.AnchorStyles.Left)
  119. | System.Windows.Forms.AnchorStyles.Right)));
  120. this.pictureBox1.Location = new System.Drawing.Point(12, 12);
  121. this.pictureBox1.Name = "pictureBox1";
  122. this.pictureBox1.Size = new System.Drawing.Size(685, 208);
  123. this.pictureBox1.TabIndex = 0;
  124. this.pictureBox1.TabStop = false;
  125. //
  126. // tbFrameRate
  127. //
  128. this.tbFrameRate.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
  129. | System.Windows.Forms.AnchorStyles.Right)));
  130. this.tbFrameRate.Location = new System.Drawing.Point(150, 226);
  131. this.tbFrameRate.Maximum = 60;
  132. this.tbFrameRate.Minimum = 1;
  133. this.tbFrameRate.Name = "tbFrameRate";
  134. this.tbFrameRate.Size = new System.Drawing.Size(547, 45);
  135. this.tbFrameRate.TabIndex = 1;
  136. this.tbFrameRate.TickFrequency = 10;
  137. this.tbFrameRate.Value = 30;
  138. this.tbFrameRate.ValueChanged += new System.EventHandler(this.tbFrameRate_ValueChanged);
  139. //
  140. // tbSpeedInPercentage
  141. //
  142. this.tbSpeedInPercentage.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
  143. | System.Windows.Forms.AnchorStyles.Right)));
  144. this.tbSpeedInPercentage.Location = new System.Drawing.Point(150, 277);
  145. this.tbSpeedInPercentage.Maximum = 100;
  146. this.tbSpeedInPercentage.Name = "tbSpeedInPercentage";
  147. this.tbSpeedInPercentage.Size = new System.Drawing.Size(547, 45);
  148. this.tbSpeedInPercentage.TabIndex = 2;
  149. this.tbSpeedInPercentage.TickFrequency = 10;
  150. this.tbSpeedInPercentage.Value = 20;
  151. this.tbSpeedInPercentage.ValueChanged += new System.EventHandler(this.tbSpeedInPercentage_ValueChanged);
  152. //
  153. // label1
  154. //
  155. this.label1.Location = new System.Drawing.Point(10, 226);
  156. this.label1.Name = "label1";
  157. this.label1.Size = new System.Drawing.Size(64, 20);
  158. this.label1.TabIndex = 3;
  159. this.label1.Text = "Frame/sec";
  160. this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
  161. //
  162. // lblFps
  163. //
  164. this.lblFps.BackColor = System.Drawing.Color.White;
  165. this.lblFps.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
  166. this.lblFps.Location = new System.Drawing.Point(80, 226);
  167. this.lblFps.Name = "lblFps";
  168. this.lblFps.Size = new System.Drawing.Size(64, 20);
  169. this.lblFps.TabIndex = 4;
  170. this.lblFps.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
  171. //
  172. // lblPixelPerSec
  173. //
  174. this.lblPixelPerSec.BackColor = System.Drawing.Color.White;
  175. this.lblPixelPerSec.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
  176. this.lblPixelPerSec.Location = new System.Drawing.Point(80, 277);
  177. this.lblPixelPerSec.Name = "lblPixelPerSec";
  178. this.lblPixelPerSec.Size = new System.Drawing.Size(64, 20);
  179. this.lblPixelPerSec.TabIndex = 6;
  180. this.lblPixelPerSec.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
  181. //
  182. // label4
  183. //
  184. this.label4.Location = new System.Drawing.Point(10, 277);
  185. this.label4.Name = "label4";
  186. this.label4.Size = new System.Drawing.Size(64, 20);
  187. this.label4.TabIndex = 5;
  188. this.label4.Text = "Pixel/sec";
  189. this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
  190. //
  191. // Form1
  192. //
  193. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
  194. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  195. this.ClientSize = new System.Drawing.Size(709, 334);
  196. this.Controls.Add(this.lblPixelPerSec);
  197. this.Controls.Add(this.label4);
  198. this.Controls.Add(this.lblFps);
  199. this.Controls.Add(this.label1);
  200. this.Controls.Add(this.tbSpeedInPercentage);
  201. this.Controls.Add(this.tbFrameRate);
  202. this.Controls.Add(this.pictureBox1);
  203. this.Name = "Form1";
  204. this.Text = "Form1";
  205. ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
  206. ((System.ComponentModel.ISupportInitialize)(this.tbFrameRate)).EndInit();
  207. ((System.ComponentModel.ISupportInitialize)(this.tbSpeedInPercentage)).EndInit();
  208. this.ResumeLayout(false);
  209. this.PerformLayout();
  210.  
  211. }
  212.  
  213. #endregion
  214.  
  215. private System.Windows.Forms.PictureBox pictureBox1;
  216. private System.Windows.Forms.TrackBar tbFrameRate;
  217. private System.Windows.Forms.TrackBar tbSpeedInPercentage;
  218. private System.Windows.Forms.Label label1;
  219. private System.Windows.Forms.Label lblFps;
  220. private System.Windows.Forms.Label lblPixelPerSec;
  221. private System.Windows.Forms.Label label4;
  222. }
  223.  
  224.  
  225. }
  226.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(3,22): error CS0234: The type or namespace name `Forms' does not exist in the namespace `System.Windows'. Are you missing `System.Windows.Forms' assembly reference?
prog.cs(9,34): error CS0246: The type or namespace name `Form' could not be found. Are you missing an assembly reference?
prog.cs(86,33): error CS0115: `WindowsFormsApplication3.Form1.Dispose(bool)' is marked as an override but no suitable method found to override
prog.cs(215,32): error CS0234: The type or namespace name `Forms' does not exist in the namespace `System.Windows'. Are you missing `System.Windows.Forms' assembly reference?
prog.cs(216,32): error CS0234: The type or namespace name `Forms' does not exist in the namespace `System.Windows'. Are you missing `System.Windows.Forms' assembly reference?
prog.cs(217,32): error CS0234: The type or namespace name `Forms' does not exist in the namespace `System.Windows'. Are you missing `System.Windows.Forms' assembly reference?
prog.cs(218,32): error CS0234: The type or namespace name `Forms' does not exist in the namespace `System.Windows'. Are you missing `System.Windows.Forms' assembly reference?
prog.cs(219,32): error CS0234: The type or namespace name `Forms' does not exist in the namespace `System.Windows'. Are you missing `System.Windows.Forms' assembly reference?
prog.cs(220,32): error CS0234: The type or namespace name `Forms' does not exist in the namespace `System.Windows'. Are you missing `System.Windows.Forms' assembly reference?
prog.cs(221,32): error CS0234: The type or namespace name `Forms' does not exist in the namespace `System.Windows'. Are you missing `System.Windows.Forms' assembly reference?
Compilation failed: 10 error(s), 0 warnings
stdout
Standard output is empty