Ejemplo n.º 1
0
        private void flash_button_when_keypressed(System.Windows.Forms.Button b)
        {
            Color previous_color = b.BackColor;

            b.BackColor = Color.Black;
            b.Refresh();
            System.Threading.Thread.Sleep(50);
            b.BackColor = previous_color;
            b.Refresh();
        }
Ejemplo n.º 2
0
        public Dialog(string title, string text, string[] buttons)
        {
            InitializeComponent();
            this.Text = title;
            this.DialogText.Text = text;
            this.DialogText.Refresh();
            this.Width = this.DialogText.Width + 24;
            this.Height = this.DialogText.Height + 18;
            this.buttons = new List<Button>();
            this.focusedButton = 0;

            if (buttons.Length > 0)
            {
                this.SuspendLayout();

                int x = 12;
                int y = this.DialogText.Location.Y + this.DialogText.Size.Height + 9;
                int h = 0;

                for (int i = 0; i < buttons.Length; i++)
                {
                    string buttonText = buttons[i];
                    Button button = new Button();
                    button.Location = new System.Drawing.Point(x, y);
                    button.Name = buttonText;
                    button.Text = buttonText;
                    button.AutoSize = true;
                    button.Font = new System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Bold);
                    button.UseVisualStyleBackColor = true;
                    button.BackColor = KomMee.ABCDEFKeyboardView.DefaultBackgroundColor;
                    button.ForeColor = KomMee.ABCDEFKeyboardView.DefaultForegroundColor;
                    this.Controls.Add(button);
                    this.buttons.Add(button);
                    button.Refresh();
                    x += button.Width + 9;
                    if(button.Height > h)
                        h = button.Height;
                }
                if (x + 3 > this.Width)
                    this.Width = x + 3;
                this.Height += h + 50;

                this.buttons[this.focusedButton].BackColor = KomMee.ABCDEFKeyboardView.FocusBackgroundColor;
                this.buttons[this.focusedButton].ForeColor = KomMee.ABCDEFKeyboardView.FocusForegroundColor;

                this.ResumeLayout(false);
                this.PerformLayout();

                //this.Location = Input.getDialogLocation(this.Size);
            }
        }
Ejemplo n.º 3
0
 public void MoveBitmap(int x, int y)
 {
     if (_baseBitmap == null)
     {
         return;
     }
     _graphics = Graphics.FromImage(btnPreview.BackgroundImage);
     _graphics.Clear(Color.White);
     if (btnPreview.BackgroundImage.Width < 100)
     {
         _graphics.DrawImage(_baseBitmap, x / 2, y / 2);
     }
     else
     {
         _graphics.DrawImage(_baseBitmap, x, y);
     }
     Application.DoEvents();
     this.Update();
     this.Refresh();
     btnPreview.Refresh();
     btnPreview.Focus();
 }
Ejemplo n.º 4
0
 private void CenterButton(System.Windows.Forms.Button btn_ok)
 {
     btn_ok.Location = new Point((btn_ok.Parent.ClientSize.Width / 2) - 35);
     btn_ok.Refresh();
 }
Ejemplo n.º 5
0
        // Technique from http://www.vb-helper.com/howto_2008_uac_shield.html
        private Bitmap GetUacShieldIcon()
        {
            const int width = 50;
            const int height = 50;
            const int margin = 4;
            Bitmap shieldImage;
            Button button = new Button()
            {
                Text = " ",
                Size = new Size(width, height),
                FlatStyle = FlatStyle.System
            };

            button.SetShieldIcon(true);

            Bitmap buttonImage = new Bitmap(width, height);

            button.Refresh();
            button.DrawToBitmap(buttonImage, new Rectangle(0, 0, width, height));

            int minX = width;
            int maxX = 0;
            int minY = width;
            int maxY = 0;

            for (int y = margin; y < height - margin; y++)
            {
                var targetColor = buttonImage.GetPixel(margin, y);

                for (int x = margin; x < width - margin; x++)
                {
                    if (buttonImage.GetPixel(x, y).Equals(targetColor))
                    {
                        buttonImage.SetPixel(x, y, Color.Transparent);
                    }
                    else
                    {
                        if (minY > y) minY = y;
                        if (minX > x) minX = x;
                        if (maxY < y) maxY = y;
                        if (maxX < x) maxX = x;
                    }
                }
            }

            int shieldWidth = maxX - minX + 1;
            int shieldHeight = maxY - minY + 1;

            shieldImage = new Bitmap(shieldWidth, shieldHeight);

            using (Graphics g = Graphics.FromImage(shieldImage))
                g.DrawImage(buttonImage, 0, 0, new Rectangle(minX, minY, shieldWidth, shieldHeight), GraphicsUnit.Pixel);

            buttonImage.Dispose();

            return shieldImage;
        }
Ejemplo n.º 6
0
 private void TableColorSelected(Color btnColor, Panel opendPanel, Button ClickBtn, MouseEventArgs e)
 {
     int index = ((e.X - 3) / 0x12) + (((e.Y - 3) / 0x12) * 4);
     btnColor = this.m_Color[index];
     ClickBtn.Refresh();
     opendPanel.Visible = false;
 }
Ejemplo n.º 7
0
        public static void SetButtonStyle(Button ctrl)
        {
            IntPtr hWnd;
            int style;

            ctrl.Capture = true;
            hWnd = GetCapture();
            ctrl.Capture = false;

            style = GetWindowLong(hWnd, GWL_STYLE);
            SetWindowLong(hWnd, GWL_STYLE, (style | BS_CENTER | BS_VCENTER |
              BS_MULTILINE));

            ctrl.Refresh();
        }
Ejemplo n.º 8
0
        private void updateTextFile(int buttonId, String url, String path, String filename, String description, Button button, PictureBox pic, ref String newContents)
        {
            enableButtons(false);
            shouldBeEnabled[buttonId] = false;

            if (readyToGo[buttonId])
            {
                readyToGo[buttonId] = false;

                if (newContents == null)
                {
                    MessageBox.Show(this, "Sorry, no data found. Please close the update window and try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    enableButtons(true);
                    pic.Image = Properties.Resources.x;
                    return;
                }

                button.Text = String.Format("Writing updates to {0}.", filename);
                button.Refresh();

                using (StreamWriter sw = new StreamWriter(path, false))
                {
                    sw.Write(newContents);
                    sw.Close();
                }

                button.Text = String.Format("You now have the latest {0}.", description);
                pic.Image = Properties.Resources.check;
                if (buttonId == Blocks)
                {
                    ColorPalette.Reset();
                    ColorPalette.Preload();
                }
                else if (buttonId == Biomes)
                {
                    BiomeType.Reset();
                    ((Form1)Owner).FillLists();
                }

                enableButtons(true);
                return;
            }

            enableButtons(false);
            shouldBeEnabled[buttonId] = false;
            button.Text = String.Format("Checking for updates to {0}.", filename);
            button.Refresh();

            String json = null;

            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                request.Method = "GET";
                request.Headers["Accept-Encoding"] = "gzip,deflate";
                request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
                request.UserAgent = userAgent;
                request.Proxy = null;

                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                StreamReader responseStream = new StreamReader(response.GetResponseStream());
                json = responseStream.ReadToEnd();
                response.Close();
                responseStream.Close();
            }
            catch (Exception)
            {
                button.Text = "Unable to connect to GitHub. Please try again later.";
                shouldBeEnabled[buttonId] = true;
                readyToGo[buttonId] = false;
                enableButtons(true);
                pic.Image = Properties.Resources.x;
                return;
            }

            json = json.Replace("\\n", "");

            String serverSha = new Regex("[\"']sha[\"']: ?\"([^\"']+)[\"']", RegexOptions.IgnoreCase | RegexOptions.Multiline).Match(json).Groups[1].Value;

            byte[] raw = File.ReadAllBytes(path);
            byte[] head = Encoding.UTF8.GetBytes("blob " + raw.Length.ToString() + "\0");
            byte[] combined = new byte[head.Length + raw.Length];
            head.CopyTo(combined, 0);
            raw.CopyTo(combined, head.Length);

            SHA1 sha1 = new SHA1CryptoServiceProvider();
            String localSha = BitConverter.ToString(sha1.ComputeHash(combined)).Replace("-", "").ToLower();

            if (serverSha == localSha)
            {
                button.Text = String.Format("You have the latest {0}. No action is necessary.", description);
                shouldBeEnabled[buttonId] = false;
                readyToGo[buttonId] = false;
                enableButtons(true);
                pic.Image = Properties.Resources.check;
            }
            else
            {
                newContents = new Regex("[\"']content[\"']: ?\"([^\"']+)[\"']", RegexOptions.IgnoreCase | RegexOptions.Multiline).Match(json).Groups[1].Value;
                newContents = Encoding.UTF8.GetString(Convert.FromBase64String(newContents));
                button.Text = String.Format("Updated {0} available! Click to save a new copy of {1}.", description, filename);
                shouldBeEnabled[buttonId] = true;
                readyToGo[buttonId] = true;
                enableButtons(true);
                pic.Image = Properties.Resources.bang;
            }
        }
Ejemplo n.º 9
0
 private void GetButtonLoction(Button btn)
 {
     Point p = new Point(btnEnd.X - btnStart.X, btnEnd.Y - btnStart.Y);
     btn.Location = new Point(btn.Location.X + p.X, btn.Location.Y + p.Y);
     btn.Refresh();
 }
Ejemplo n.º 10
0
 public void setButtonOn(Button btn, Form frm)
 {
     foreach (Control c in frm.Controls)
     {
         c.Enabled = true;
     }
     btn.Text = originalText;
     originalText = "";
     btn.Refresh();
     Cursor.Current = Cursors.Default; ;
 }
Ejemplo n.º 11
0
 public void setButtonOff(Button btn, Form frm)
 {
     foreach (Control c in frm.Controls)
     {
         c.Enabled = false;
     }
     originalText = btn.Text;
     btn.Text = "Čakajte...";
     btn.Refresh();
     Cursor.Current = Cursors.WaitCursor;
 }
Ejemplo n.º 12
0
        public void LoadElements(System.Xml.XmlReader ids)
        {
            TInterfaceElement ie = new TInterfaceElement();
            while (ids.Read())
                if (ids.IsStartElement())
                {
                    switch (ids.Name)
                    {
                        case "SCREEN_Width":
                            {
                                ids.Read();
                                Width = Convert.ToInt16(ids.Value);
                            }; break;
                        case "SCREEN_Height":
                            {
                                ids.Read();
                                Height = Convert.ToInt16(ids.Value);
                            }; break;
                        case "SCREEN_BackColor":
                            {
                                ids.Read();
                                BackColor = utftUtils.GetUTFTColor(ids.Value);
                            }; break;
                        case "SCREEN_FontColor":
                            {
                                ids.Read();
                                FontColor = utftUtils.GetUTFTColor(ids.Value);
                            }; break;
                        case "SCREEN_ABorderColor":
                            {
                                ids.Read();
                                ActiveBorderColor = utftUtils.GetUTFTColor(ids.Value);
                            }; break;
                        case "SCREEN_PBorderColor":
                            {
                                ids.Read();
                                PassiveBorderColor = utftUtils.GetUTFTColor(ids.Value);
                            }; break;
                        case "Desctop":
                            {
                                ids.Read();
                                Image = new System.Drawing.Bitmap(ids.Value);
                            };break;
                        case "Element":
                            ie = new TInterfaceElement();
                            break;
                        case "ItemType":
                            {
                                ids.Read();
                                switch (ids.Value)
                                {
                                    case "Border":
                                        {
                                            Button btn = new Button();

                                            btn.Parent = pnl;
                                            btn.MouseDown += new MouseEventHandler(MouseDown);
                                            btn.MouseMove += new MouseEventHandler(MouseMove);

                                            btn.ContextMenuStrip = pmElement;
                                            btn.Text = "Border";
                                            btn.Refresh();
                                            ie.border = btn;
                                        } break; // button
                                    case "2": break; // edit
                                    case "Label":
                                        {
                                            Label lbl = new Label();

                                            lbl.Parent = pnl;
                                            lbl.MouseDown += new MouseEventHandler(MouseDown);
                                            lbl.MouseMove += new MouseEventHandler(MouseMove);

                                            lbl.Text = "Label";
                                            lbl.ContextMenuStrip = pmElement;
                                            lbl.Refresh();
                                            ie.border = lbl;
                                        } break; // label
                                    case "4": break; // Checker
                                }
                            }
                            break;
                        case "ID": ids.Read(); ie.ID = Convert.ToByte(ids.Value); break;
                        case "ItemName": ids.Read(); ie.ItemName = ids.Value; listitem.Add(ie.ItemName, ie); AddItem(ie); break;
                        case "X": ids.Read(); ie.X = Convert.ToInt16(ids.Value); break;
                        case "Y": ids.Read(); ie.Y = Convert.ToInt16(ids.Value); break;
                        case "Width": ids.Read(); ie.width = Convert.ToInt16(ids.Value); break;
                        case "Height": ids.Read(); ie.heigth = Convert.ToInt16(ids.Value); break;
                        case "BackColor": ids.Read(); ie.BackColor = utftUtils.GetUTFTColor(ids.Value); break;
                        case "FontColor": ids.Read(); ie.FontColor = utftUtils.GetUTFTColor(ids.Value); break;
                        case "CanSelect": ids.Read(); ie.CanSelect = Convert.ToBoolean(ids.Value); break;
                        case "Text": ids.Read(); ie.Text = ids.Value; break;
                    }// ids.Name
                }//while
        }
Ejemplo n.º 13
0
        public void CreateElement()
        {
            Button btn = new Button();

            btn.Parent = pnl;
            btn.MouseDown += new MouseEventHandler(MouseDown);
            btn.MouseMove += new MouseEventHandler(MouseMove);

            btn.ContextMenuStrip = pmElement;
            btn.Text = "Border";
            btn.Refresh();

            TInterfaceElement item = new TInterfaceElement();
            item.border = btn;
            item.ItemName = "Border";
            item.BackColor = VGA_COLOR.VGA_BLACK;
            item.FontColor = VGA_COLOR.VGA_WHITE;
            Boolean err = true;
            int i = 0;
            while (err)
                try
                {
                    listitem.Add(item.ItemName, item);
                    btn.Tag = item.ItemName;
                    err = false;
                    AddItem(item);
                }
                catch (Exception ee)
                {
                    i++;
                    item.ItemName = "Border" + i.ToString();
                }
        }