Ejemplo n.º 1
0
        public Program()
        {
            HttpWebRequest.DefaultCachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);

            this.components = new Container();
            this.context = new ContextMenu();

            // Start & Stop
            this.menuAction = new MenuItem();
            this.menuAction.Index = 0;
            this.menuAction.Text = "Iniciar";
            this.menuAction.Enabled = false;
            this.menuAction.Click += (s1, e1) =>
            {
                if (this.menuAction.Text == "Iniciar")
                {
                    this.timer = new System.Windows.Forms.Timer();
                    this.timer.Interval = Convert.ToInt32(settings["INTERVAL"] ?? "1") * 3600000;
                    this.timer.Tick += (s2, e2) => this.CheckInternetSpeed();
                    this.timer.Start();
                    this.menuAction.Text = "Parar";
                    this.CheckInternetSpeed();
                }
                else
                {
                    this.timer.Stop();
                    this.timer = null;
                    this.menuAction.Text = "Iniciar";
                }
            };

            // Test Now
            this.menuTestNow = new MenuItem();
            this.menuTestNow.Index = 1;
            this.menuTestNow.Text = "Testar Agora";
            this.menuTestNow.Enabled = false;
            this.menuTestNow.Click += (s, e) => this.CheckInternetSpeed();

            // Settings
            this.menuSettings = new MenuItem();
            this.menuSettings.Index = 2;
            this.menuSettings.Text = "Configurações";
            this.menuSettings.Enabled = true;
            this.menuSettings.Click += (s1, e1) =>
            {
                this.frmSettings = new SettingsForm();
                this.frmSettings.FormClosed += (s2, e2) =>
                {
                    if (this.timer != null)
                    {
                        this.timer.Stop();
                        this.timer.Interval = Convert.ToInt32(settings["INTERVAL"] ?? "1") * 3600000;
                        this.timer.Start();
                    }

                    this.frmSettings = null;
                    this.CheckSettings();
                };
                this.frmSettings.Show();
            };

            // Exit
            this.menuExit = new MenuItem();
            this.menuExit.Index = 3;
            this.menuExit.Text = "Sair";
            this.menuExit.Enabled = true;
            this.menuExit.Click += (s, e) => Application.Exit();

            this.context.MenuItems.AddRange(new MenuItem[] {
                this.menuAction,
                this.menuTestNow,
                this.menuSettings,
                this.menuExit
            });

            this.notify = new NotifyIcon(this.components)
            {
                ContextMenuStrip = new ContextMenuStrip(),
                Icon = new System.Drawing.Icon("icon.ico"),
                Text = "Minha Net Minha Vida",
                Visible = true,
            };
            this.notify.Icon = new System.Drawing.Icon("icon.ico");
            this.notify.ContextMenu = this.context;

            this.DownloadServersList();
            this.GetUserPostion();
        }
Ejemplo n.º 2
0
        public Program()
        {
            HttpWebRequest.DefaultCachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);

            this.components = new Container();
            this.context    = new ContextMenu();

            // Start & Stop
            this.menuAction         = new MenuItem();
            this.menuAction.Index   = 0;
            this.menuAction.Text    = "Iniciar";
            this.menuAction.Enabled = false;
            this.menuAction.Click  += (s1, e1) =>
            {
                if (this.menuAction.Text == "Iniciar")
                {
                    this.timer          = new System.Windows.Forms.Timer();
                    this.timer.Interval = Convert.ToInt32(settings["INTERVAL"] ?? "1") * 3600000;
                    this.timer.Tick    += (s2, e2) => this.CheckInternetSpeed();
                    this.timer.Start();
                    this.menuAction.Text = "Parar";
                    this.CheckInternetSpeed();
                }
                else
                {
                    this.timer.Stop();
                    this.timer           = null;
                    this.menuAction.Text = "Iniciar";
                }
            };

            // Test Now
            this.menuTestNow         = new MenuItem();
            this.menuTestNow.Index   = 1;
            this.menuTestNow.Text    = "Testar Agora";
            this.menuTestNow.Enabled = false;
            this.menuTestNow.Click  += (s, e) => this.CheckInternetSpeed();

            // Settings
            this.menuSettings         = new MenuItem();
            this.menuSettings.Index   = 2;
            this.menuSettings.Text    = "Configurações";
            this.menuSettings.Enabled = true;
            this.menuSettings.Click  += (s1, e1) =>
            {
                this.frmSettings             = new SettingsForm();
                this.frmSettings.FormClosed += (s2, e2) =>
                {
                    if (this.timer != null)
                    {
                        this.timer.Stop();
                        this.timer.Interval = Convert.ToInt32(settings["INTERVAL"] ?? "1") * 3600000;
                        this.timer.Start();
                    }

                    this.frmSettings = null;
                    this.CheckSettings();
                };
                this.frmSettings.Show();
            };

            // Exit
            this.menuExit         = new MenuItem();
            this.menuExit.Index   = 3;
            this.menuExit.Text    = "Sair";
            this.menuExit.Enabled = true;
            this.menuExit.Click  += (s, e) => Application.Exit();

            this.context.MenuItems.AddRange(new MenuItem[] {
                this.menuAction,
                this.menuTestNow,
                this.menuSettings,
                this.menuExit
            });

            this.notify = new NotifyIcon(this.components)
            {
                ContextMenuStrip = new ContextMenuStrip(),
                Icon             = new System.Drawing.Icon("icon.ico"),
                Text             = "Minha Net Minha Vida",
                Visible          = true,
            };
            this.notify.Icon        = new System.Drawing.Icon("icon.ico");
            this.notify.ContextMenu = this.context;

            this.DownloadServersList();
            this.GetUserPostion();
        }