Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Feladatkiírás:
- 30. Rajzoljunk egy libikókát (vizszintes egyenes, középen forgásponttal, ami egy kis kör). Mindkét vége
- felett egy-egy textboxba beirjuk a gyerek súlyát, aki ráült. Ha azonos a két súly, a libikóka
- vizszintes marad, ha valamelyik nehezebb, abba az irányba lesüllyed, miközben a forgáspont a helyén marad.
- // csc.exe -debug+ -target:winexe -r:System.Windows.Forms.dll -r:System.Drawing.dll program.cs
- */
- using System;
- using System.Drawing;
- using System.Windows.Forms;
- public class Program
- {
- static int formWidth = 600, formHeight = 400;
- static int angle;
- static Form f = new Form()
- {
- Size = new Size(formWidth, formHeight),
- FormBorderStyle = FormBorderStyle.FixedSingle,
- Text = "Libikóka"
- };
- static TextBox tbLeft = new TextBox()
- {
- Location = new Point(100, 80)
- };
- static TextBox tbRight = new TextBox()
- {
- Location = new Point(400, 80)
- };
- static Label l = new Label()
- {
- Location = new Point(5, formHeight-60),
- Size = new Size(formWidth-10, 20),
- };
- [STAThread]
- static void Main()
- {
- f.Paint += new PaintEventHandler(Form1_Paint);
- f.Controls.Add(tbLeft);
- f.Controls.Add(tbRight);
- f.Controls.Add(l);
- tbLeft.TextChanged += new System.EventHandler(TextChanged);
- tbRight.TextChanged += new System.EventHandler(TextChanged);
- Application.Run(f);
- }
- static void TextChanged(object sender, EventArgs e)
- {
- int t1 = 0, t2 = 0;
- //int max_angle = 20;
- try
- {
- t1 = tbLeft.Text.Trim().Equals("") ? 0 : int.Parse(tbLeft.Text.Trim());
- t2 = tbRight.Text.Trim().Equals("") ? 0 : int.Parse(tbRight.Text.Trim());
- if (t1 < t2) angle = 15;
- else if (t1 > t2) angle = -15;
- else angle = 0;
- //angle = Math.Max(-max_angle, Math.Min(max_angle, (t2 - t1) * 2));
- l.Text = "";
- }
- catch (Exception ex)
- {
- l.Text = ex.Message;
- angle = 0;
- }
- f.Invalidate();
- }
- static void Form1_Paint(object sender, PaintEventArgs e)
- {
- {
- e.Graphics.TranslateTransform(formWidth/2, formHeight/2);
- e.Graphics.RotateTransform(angle);
- e.Graphics.DrawLine(new Pen(Color.Red, 5), -200, 0, 200, 0);
- e.Graphics.ResetTransform();
- e.Graphics.DrawEllipse(new Pen(Color.Black, 3), formWidth / 2, formHeight / 2, 10, 10);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement