Featured image of post 1_A

1_A

Very frist pratical homework of statistics, main scope is to better understanding VB.net and C# programming leanguage

1_A assignament

Request

Create - in both languages C# and VB.NET - a program which does the following simple tasks to get acquainted with the tool:

when a button is pressed some text appears in a richtexbox on the startup form when another button is pressed animate one or more colored balls within a rectangle

My Solution

Code in C#

Code in VB.net

Code in zip(mirror)

Form code In C#

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
  public MyFristGUI()
        {
            InitializeComponent();

            t.Interval = 4;
            flag = new Bitmap(480, 160);
            g = Graphics.FromImage(flag);
            t.Tick += T_Tick;

        }
        Bitmap flag;
        Graphics g;
        int x = 20;
        int y = 20;
        Timer t = new Timer();
       

        private void button1_Click(object sender, EventArgs e)
        {
            this.richTextBox1.Text = "button pressed";
        }

     
        private void T_Tick(object sender, EventArgs e)
        {    
            var rand2 = new Random();
            g = Graphics.FromImage(flag);
            g.Clear(Color.White);
            g.DrawCircle(new Pen(Brushes.Red, 2), x, y, 20);
            g.FillCircle(Brushes.Red, x, y, 20);
           
            x = x+rand2.Next(-10, 10);
            y = y+ rand2.Next(-10,10);
            if (x > 460) x = x - 10;
            if (x < 20) x = x + 10;
            if (y > 140) y = y - 10;
            if (y < 20) y = y + 10;
            pictureBox2.Image = flag;

         
           
        }



        private void MyFristGUI_Load(object sender, EventArgs e)
        {


        }

        private void button2_MouseClick(object sender, MouseEventArgs e)
        {
            
            var rand = new Random();
            x = rand.Next(20, 460);
            y = rand.Next(20, 140);
            t.Start();
            this.button2.Visible = false;
            this.button3.Text = "STOP";
            this.button3.Visible = true;
        }

        private void button3_MouseClick(object sender, MouseEventArgs e)
        {
            t.Stop();
            g.Clear(BackColor);
            this.button3.Visible = false;
            this.button2.Visible = true;
            pictureBox2.Image = flag;
        }

       
    }
comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy