Beispiel #1
0
        public void Info(string title, string info, Font fnt, int[] array, bool themeit = false)
        {
            Text = title;
            textBoxInfo.TextBox.SelectionTabs = array;
            textBoxInfo.TextBox.ReadOnly      = true;
            textBoxInfo.Text = info;
            textBoxInfo.TextBox.Select(0, 0);

            if (themeit)
            {
                BaseUtils.ThemeableForms theme = BaseUtils.ThemeAbleFormsInstance.Instance;
                if (fnt == null)
                {
                    fnt = new Font(theme.FontName, 12.0F);
                }
                theme.ApplyToForm(this, fnt);
            }

            textBoxInfo.Font = fnt;
        }
Beispiel #2
0
        public void Show(Form p, string lname, System.Drawing.Size size, System.Drawing.Point pos, string caption, Entry[] e, Object t)
        {
            logicalname = lname; // passed back to caller via trigger
            entries     = e;
            callertag   = t;     // passed back to caller via trigger

            BaseUtils.ThemeableForms theme = BaseUtils.ThemeAbleFormsInstance.Instance;

            FormBorderStyle = FormBorderStyle.FixedDialog;

            Size = size;

            if (pos.X == -999)
            {
                StartPosition = FormStartPosition.CenterScreen;
            }
            else
            {
                Location      = pos;
                StartPosition = FormStartPosition.Manual;
            }

            Panel outer = new Panel()
            {
                Dock = DockStyle.Fill, BorderStyle = BorderStyle.FixedSingle
            };

            outer.MouseDown += FormMouseDown;

            Controls.Add(outer);

            Label textLabel = new Label()
            {
                Left = 4, Top = 8, Width = Width - 50, Text = caption
            };

            textLabel.MouseDown += FormMouseDown;

            if (!theme.WindowsFrame)
            {
                outer.Controls.Add(textLabel);
            }

            ToolTip tt = new ToolTip();

            tt.ShowAlways = true;
            for (int i = 0; i < entries.Length; i++)
            {
                Entry   ent = entries[i];
                Control c   = (Control)Activator.CreateInstance(ent.controltype);
                ent.control = c;
                c.Size      = ent.size;
                c.Location  = ent.pos;
                if (!(c is ExtendedControls.ComboBoxCustom))        // everything but get text
                {
                    c.Text = ent.text;
                }
                c.Tag = ent;     // point control tag at ent structure
                outer.Controls.Add(c);
                if (ent.tooltip != null)
                {
                    tt.SetToolTip(c, ent.tooltip);
                }

                if (c is ExtendedControls.ButtonExt)
                {
                    ExtendedControls.ButtonExt b = c as ExtendedControls.ButtonExt;
                    b.Click += (sender, ev) =>
                    {
                        Entry en = (Entry)(((Control)sender).Tag);
                        Trigger?.Invoke(logicalname, en.name, callertag);       // pass back the logical name of dialog, the name of the control, the caller tag
                    };
                }

                if (c is ExtendedControls.TextBoxBorder)
                {
                    ExtendedControls.TextBoxBorder tb = c as ExtendedControls.TextBoxBorder;
                    tb.Multiline = tb.WordWrap = ent.textboxmultiline;
                }

                if (c is ExtendedControls.CheckBoxCustom)
                {
                    ExtendedControls.CheckBoxCustom cb = c as ExtendedControls.CheckBoxCustom;
                    cb.Checked = ent.checkboxchecked;
                    cb.Click  += (sender, ev) =>
                    {
                        Entry en = (Entry)(((Control)sender).Tag);
                        Trigger?.Invoke(logicalname, en.name, callertag);       // pass back the logical name of dialog, the name of the control, the caller tag
                    };
                }

                if (c is ExtendedControls.ComboBoxCustom)
                {
                    ExtendedControls.ComboBoxCustom cb = c as ExtendedControls.ComboBoxCustom;
                    cb.Items.AddRange(ent.comboboxitems.Split(','));
                    if (cb.Items.Contains(ent.text))
                    {
                        cb.SelectedItem = ent.text;
                    }
                    cb.SelectedIndexChanged += (sender, ev) =>
                    {
                        Control ctr = (Control)sender;
                        if (ctr.Enabled)
                        {
                            Entry en = (Entry)(ctr.Tag);
                            Trigger?.Invoke(logicalname, en.name, callertag);       // pass back the logical name of dialog, the name of the control, the caller tag
                        }
                    };
                }
            }

            ShowInTaskbar = false;

            theme.ApplyToForm(this, System.Drawing.SystemFonts.DefaultFont);

            Show(p);
        }
Beispiel #3
0
        // lab sets the items, def can be less or null
        public static List <string> ShowDialog(Form p, string caption, string[] lab, string[] def, bool multiline = false, string[] tooltips = null)
        {
            BaseUtils.ThemeableForms theme = BaseUtils.ThemeAbleFormsInstance.Instance;

            int vstart   = theme.WindowsFrame ? 20 : 40;
            int vspacing = multiline ? 60 : 40;
            int lw       = 100;
            int lx       = 10;
            int tx       = 10 + lw + 8;

            Form prompt = new Form()
            {
                Width           = 600,
                Height          = 90 + vspacing * lab.Length + (theme.WindowsFrame ? 20 : 0),
                FormBorderStyle = FormBorderStyle.FixedDialog,
                Text            = caption,
                StartPosition   = FormStartPosition.CenterScreen,
            };

            Panel outer = new Panel()
            {
                Dock = DockStyle.Fill, BorderStyle = BorderStyle.FixedSingle
            };

            prompt.Controls.Add(outer);

            Label textLabel = new Label()
            {
                Left = lx, Top = 8, Width = prompt.Width - 50, Text = caption
            };

            if (!theme.WindowsFrame)
            {
                outer.Controls.Add(textLabel);
            }

            Label[] lbs = new Label[lab.Length];
            ExtendedControls.TextBoxBorder[] tbs = new ExtendedControls.TextBoxBorder[lab.Length];

            ToolTip tt = new ToolTip();

            tt.ShowAlways = true;

            int y = vstart;

            for (int i = 0; i < lab.Length; i++)
            {
                lbs[i] = new Label()
                {
                    Left = lx, Top = y, Width = lw, Text = lab[i]
                };
                tbs[i] = new ExtendedControls.TextBoxBorder()
                {
                    Left       = tx,
                    Top        = y,
                    Width      = prompt.Width - 50 - tx,
                    Text       = (def != null && i < def.Length) ? def[i] : "",
                    Height     = vspacing - 20,
                    Multiline  = multiline,
                    ScrollBars = (multiline) ? ScrollBars.Vertical : ScrollBars.None,
                    WordWrap   = multiline
                };
                outer.Controls.Add(lbs[i]);
                outer.Controls.Add(tbs[i]);

                if (tooltips != null && i < tooltips.Length)
                {
                    tt.SetToolTip(lbs[i], tooltips[i]);
                    tt.SetToolTip(tbs[i], tooltips[i]);
                }

                y += vspacing;
            }

            ExtendedControls.ButtonExt confirmation = new ExtendedControls.ButtonExt()
            {
                Text = "Ok", Left = tbs[0].Right - 80, Width = 80, Top = y, DialogResult = DialogResult.OK
            };
            outer.Controls.Add(confirmation);
            confirmation.Click += (sender, e) => { prompt.Close(); };

            ExtendedControls.ButtonExt cancel = new ExtendedControls.ButtonExt()
            {
                Text = "Cancel", Left = confirmation.Location.X - 90, Width = 80, Top = confirmation.Top, DialogResult = DialogResult.Cancel
            };
            outer.Controls.Add(cancel);
            cancel.Click += (sender, e) => { prompt.Close(); };

            if (!multiline)
            {
                prompt.AcceptButton = confirmation;
            }

            prompt.CancelButton  = cancel;
            prompt.ShowInTaskbar = false;

            theme.ApplyToForm(prompt, System.Drawing.SystemFonts.DefaultFont);

            if (prompt.ShowDialog(p) == DialogResult.OK)
            {
                var r = (from ExtendedControls.TextBoxBorder t in tbs select t.Text).ToList();
                return(r);
            }
            else
            {
                return(null);
            }
        }
Beispiel #4
0
        public void Init(string ptext, string caption, MessageBoxButtons buttons, MessageBoxIcon ic)
        {
            if (buttons == MessageBoxButtons.AbortRetryIgnore)
            {
                buttonExt1.Tag = DialogResult.Ignore; buttonExt1.Text = "Ignore";
                buttonExt2.Tag = DialogResult.Retry; buttonExt2.Text = "Retry";
                buttonExt3.Tag = DialogResult.Abort; buttonExt3.Text = "Abort";
            }
            else if (buttons == MessageBoxButtons.OK)
            {
                buttonExt1.Tag     = DialogResult.OK; buttonExt1.Text = "OK";
                buttonExt2.Visible = false;
                buttonExt3.Visible = false;
                this.AcceptButton  = this.CancelButton = buttonExt1;
            }
            else if (buttons == MessageBoxButtons.OKCancel)
            {
                buttonExt1.Tag     = DialogResult.Cancel; buttonExt1.Text = "Cancel";
                buttonExt2.Tag     = DialogResult.OK; buttonExt2.Text = "OK";
                buttonExt3.Visible = false;
            }
            else if (buttons == MessageBoxButtons.RetryCancel)
            {
                buttonExt1.Tag     = DialogResult.Cancel; buttonExt1.Text = "Cancel";
                buttonExt2.Tag     = DialogResult.OK; buttonExt2.Text = "Retry";
                buttonExt3.Visible = false;
            }
            else if (buttons == MessageBoxButtons.YesNo)
            {
                buttonExt1.Tag     = DialogResult.No; buttonExt1.Text = "No";
                buttonExt2.Tag     = DialogResult.Yes; buttonExt2.Text = "Yes";
                buttonExt3.Visible = false;
            }
            else if (buttons == MessageBoxButtons.YesNoCancel)
            {
                buttonExt1.Tag = DialogResult.Cancel; buttonExt1.Text = "Cancel";
                buttonExt2.Tag = DialogResult.No; buttonExt2.Text = "No";
                buttonExt3.Tag = DialogResult.Yes; buttonExt3.Text = "Yes";
            }

            labelCaption.Text = this.Text = caption;
            text = ptext;

            if (ic == MessageBoxIcon.Asterisk)
            {
                icon = SystemIcons.Asterisk;
            }
            if (ic == MessageBoxIcon.Error)
            {
                icon = SystemIcons.Error;
            }
            if (ic == MessageBoxIcon.Exclamation)
            {
                icon = SystemIcons.Exclamation;
            }
            if (ic == MessageBoxIcon.Information)
            {
                icon = SystemIcons.Information;
            }
            if (ic == MessageBoxIcon.Question)
            {
                icon = SystemIcons.Question;
            }
            if (ic == MessageBoxIcon.Warning)
            {
                icon = SystemIcons.Warning;
            }

            int ystart = 30;

            BaseUtils.ThemeableForms theme = BaseUtils.ThemeAbleFormsInstance.Instance;
            if (theme != null)  // paranoid
            {
                fnt        = new Font(theme.FontName, 12.0F);
                forecolour = theme.TextBlockColor;
                bool border = theme.ApplyToForm(this, fnt);
                if (!border)
                {
                    labelCaption.Visible = true;
                    ystart += 20;
                }
            }
            else
            {
                fnt        = new Font("MS Sans Serif", 12.0F);
                forecolour = Color.Red;
            }

            int bordery = Bounds.Height - ClientRectangle.Height;
            int borderx = Bounds.Width - ClientRectangle.Width;

            int left = (ic != MessageBoxIcon.None) ? 80 : 20;

            using (Graphics g = CreateGraphics())
            {
                SizeF sizeftext    = g.MeasureString(text, fnt);
                SizeF sizefcaption = g.MeasureString(caption, fnt);

                Height = (int)sizeftext.Height + ystart + 50 + bordery;
                Width  = Math.Min(Math.Max(300, left + (int)Math.Max(sizeftext.Width, sizefcaption.Width) + 20), 1800) + borderx;

                textarea = new Rectangle(left, ystart, (int)(sizeftext.Width + 1), (int)(sizeftext.Height + 1));
            }
        }