NEWS

[C#] Chia sẻ source code make Crazy Error Message Effect Bomb Windows

[C#] Chia sẻ source code make Crazy Error Message Effect Bomb Windows
Đăng bởi: Thảo Meo - Lượt xem: 2243 08:59:45, 20/03/2023C#   In bài viết

Xin chào các bạn, bài viết hôm nay mình chia sẻ các bạn source code Crazy Effect Error Message trên winform, khi người dùng click vào sẻ hiển thị ngẫu nhiên các thông báo lỗi.

[C#] Crazy Error Windows 

Video demo ứng dụng:

Source code C#:

using bs;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Forms;

namespace CrazyError
{
    public partial class Form1 : Form
    {


       
        private int step = 30;
        bool dixuong = true;
        bool dilen = false;
        bool dungtrai = false;
        bool dungphai = false;
        Random r= new Random();
        public Form1()
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.Manual;
            this.Location = new Point(0, 0);
            
        }

        public  Point GetRandomScreenLocation()
        {
            Random rand = new Random();
            Screen screen = Screen.PrimaryScreen;
            int x = rand.Next(screen.Bounds.Left, screen.Bounds.Right);
            int y = rand.Next(screen.Bounds.Top, screen.Bounds.Bottom);
            return new Point(x, y);
        }
        

        private void button1_Click(object sender, EventArgs e)
        {
            this.Hide();
            Rectangle screenBounds = Screen.PrimaryScreen.Bounds;

            var listForm = new List<Form>();
            var listForm2 = new List<Form>();
            var listForm3 = new List<Form>();
            var rnd = new Random();

            var task1 = Task.Run(() =>
            {
                for (int i = 1; i <= 50; i++)
                {
                    var formrand = r.Next(1, 4);
                    Form frm;
                  
                    if (formrand == 1)
                    {
                        frm = new Form2();
                    }
                    else if (formrand == 2)
                    {
                        frm = new Form3();
                    }
                    else {
                        frm = new Form4();
                    }
                    
                    listForm2.Add(frm);
                    frm.StartPosition = FormStartPosition.Manual;
                    var point = GetRandomScreenLocation();
                    frm.Location = point;
                    this.BeginInvoke(new Action(() =>
                    {
                        frm.Show();

                        if (i == 50) {
                            foreach (var item in listForm2)
                            {
                                item.Close();
                            }
                        }

                    }));
                    Task.Delay(150).Wait();
                }
            });

            task1.ContinueWith(t => {

                Task.Run(() =>
                {


                    var temp = new Form2();
                    int x = 100;
                    int y = 100;

                    for (int i = 1; i <= 500; i++)
                    {
                        Form form;

                        form = new Form2();

                        form.Name = $"form{i}";
                        listForm.Add(form);

                        form.StartPosition = FormStartPosition.Manual;
                        form.Location = new Point(x, y);


                        if (form.Top + form.Height >= screenBounds.Bottom)
                        {
                            dilen = true;
                            dixuong = false;
                        }

                        if (form.Left + form.Width >= screenBounds.Right)
                        {
                            dungphai = true;
                            dungtrai = false;
                        }

                        if (form.Left <= screenBounds.Left)
                        {
                            dungtrai = true;
                            dungphai = false;
                        }

                        if (form.Top <= screenBounds.Top)
                        {
                            dilen = false;
                            dixuong = true;

                        }

                        if (dilen)
                        {
                            if (dungphai)
                            {
                                x = x - step;
                            }
                            else
                            {
                                x = x + step;
                            }

                            y = y - step;
                        }

                        if (dixuong)
                        {

                            y = y + step;
                            if (dungtrai)
                            {
                                x = x + step;
                            }
                            else
                            {
                                x = x - step;
                            }
                        }




                        this.BeginInvoke(new Action(() =>
                        {
                            form.Show();

                            if (i > 20 && i < 200)
                            {
                                foreach (var item in listForm)
                                {
                                    var intNumber = Convert.ToInt32(item.Name.Replace("form", ""));
                                    if (i - intNumber == 20)
                                    {
                                        item.Close();
                                    }
                                }
                            }
                            if (i == 500)
                            {
                                foreach (var item in listForm)
                                {

                                    item.Close();

                                }
                                var frm = new BsodForm();
                                frm.Show();
                            }
                        }));


                        Task.Delay(30).Wait();
                    }

                });

                Task.Run(() =>
                {


                    var temp = new Form3();
                    int x = 350;
                    int y = 500;

                    for (int i = 1; i <= 400; i++)
                    {
                        Form form;

                        form = new Form3();

                        form.Name = $"form{i}";
                        listForm3.Add(form);

                        form.StartPosition = FormStartPosition.Manual;
                        form.Location = new Point(x, y);


                        if (form.Top + form.Height >= screenBounds.Bottom)
                        {
                            dilen = true;
                            dixuong = false;
                        }

                        if (form.Left + form.Width >= screenBounds.Right)
                        {
                            dungphai = true;
                            dungtrai = false;
                        }

                        if (form.Left <= screenBounds.Left)
                        {
                            dungtrai = true;
                            dungphai = false;
                        }

                        if (form.Top <= screenBounds.Top)
                        {
                            dilen = false;
                            dixuong = true;

                        }

                        if (dilen)
                        {
                            if (dungphai)
                            {
                                x = x - step;
                            }
                            else
                            {
                                x = x + step;
                            }

                            y = y - step;
                        }

                        if (dixuong)
                        {

                            y = y + step;
                            if (dungtrai)
                            {
                                x = x + step;
                            }
                            else
                            {
                                x = x - step;
                            }
                        }




                        this.BeginInvoke(new Action(() =>
                        {
                            form.Show();

                            if (i > 20 && i < 200)
                            {
                                foreach (var item in listForm3)
                                {
                                    var intNumber = Convert.ToInt32(item.Name.Replace("form", ""));
                                    if (i - intNumber == 20)
                                    {
                                        item.Close();
                                    }
                                }
                            }
                            if (i == 400)
                            {
                                foreach (var item in listForm3)
                                {

                                    item.Close();

                                }
                               
                            }

                        }));


                        Task.Delay(30).Wait();
                    }

                });
            });

              

        }


    }
}

Thanks for watching!

DOWNLOAD SOURCE

THÔNG TIN TÁC GIẢ

BÀI VIẾT LIÊN QUAN

[C#] Chia sẻ source code make Crazy Error Message Effect Bomb Windows
Đăng bởi: Thảo Meo - Lượt xem: 2243 08:59:45, 20/03/2023C#   In bài viết

CÁC BÀI CÙNG CHỦ ĐỀ

Đọc tiếp
.