Ejemplo n.º 1
0
 void SetPos(ref Point lp, Label lab, Point tp, ExtendedControls.ExtRichTextBox box, int vspacing, int i)
 {
     lab.Location = lp;
     box.Location = tp;
     box.Tag      = lab.Tag = i;
     lab.Visible  = box.Visible = true;
     lp.Y        += vspacing;
 }
Ejemplo n.º 2
0
        // lab sets the items, def can be less or null
        public static List <string> ShowDialog(Form p, string caption, Icon ic, string[] lab, string[] def,
                                               bool multiline    = false,
                                               string[] tooltips = null,
                                               bool cursoratend  = false,
                                               int widthboxes    = 200, // sizes based on standard dialog size of 12, scaled up
                                               int heightboxes   = -1)
        {
            DraggableForm prompt = new DraggableForm()
            {
                FormBorderStyle = FormBorderStyle.FixedDialog,
                Text            = caption,
                StartPosition   = FormStartPosition.CenterScreen,
                Icon            = ic
            };

            int lx = 10;

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

            prompt.Controls.Add(outer);
            outer.MouseDown += (s, e) => { prompt.OnCaptionMouseDown(s as Control, e); };
            outer.MouseUp   += (s, e) => { prompt.OnCaptionMouseUp(s as Control, e); };

            Label textLabel = new Label()
            {
                Left = lx, Top = 8, AutoSize = true, Text = caption
            };

            textLabel.MouseDown += (s, e) => { prompt.OnCaptionMouseDown(s as Control, e); };
            textLabel.MouseUp   += (s, e) => { prompt.OnCaptionMouseUp(s as Control, e); };

            ITheme theme = ThemeableFormsInstance.Instance;

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

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

            ToolTip tt = new ToolTip();

            tt.ShowAlways = true;

            int y = theme.WindowsFrame ? 20 : 40;

            if (heightboxes == -1)
            {
                heightboxes = multiline ? 80 : 24;
            }

            for (int i = 0; i < lab.Length; i++)
            {
                lbs[i] = new Label()
                {
                    Left = lx, Top = y, AutoSize = true, Text = lab[i]
                };
                outer.Controls.Add(lbs[i]);

                tbs[i] = new ExtendedControls.ExtRichTextBox()
                {
                    Left   = 0,     // will be set once we know the paras of all lines
                    Top    = y,
                    Width  = widthboxes,
                    Text   = (def != null && i < def.Length) ? def[i] : "",
                    Height = heightboxes,
                };

                if (cursoratend)
                {
                    tbs[i].Select(tbs[i].Text.Length, tbs[i].Text.Length);
                }

                outer.Controls.Add(tbs[i]);

                if (tooltips != null && i < tooltips.Length)
                {
                    tt.SetToolTip(lbs[i], tooltips[i]);
                    tbs[i].SetTipDynamically(tt, tooltips[i]);      // no container here, set tool tip on text boxes using this
                }

                y += heightboxes + 20;
            }

            ExtendedControls.ExtButton confirmation = new ExtendedControls.ExtButton()
            {
                Text = "OK".Tx(), Left = 0, Width = 100, Top = y, DialogResult = DialogResult.OK
            };
            outer.Controls.Add(confirmation);
            confirmation.Click += (sender, e) => { prompt.Close(); };

            ExtendedControls.ExtButton cancel = new ExtendedControls.ExtButton()
            {
                Text = "Cancel".Tx(), Left = 0, Width = 100, 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;
            prompt.AutoScaleMode = AutoScaleMode.Font;

            theme.ApplyDialog(prompt);

            int controlleft = 0;

            for (int i = 0; i < lab.Length; i++)
            {
                controlleft = Math.Max(controlleft, lbs[i].Right + 16);     // seems have to do this after sizing, confusingly
            }
            for (int i = 0; i < lab.Length; i++)                            // all go here
            {
                tbs[i].Left = controlleft;
            }

            confirmation.Left = tbs[0].Right - confirmation.Width;          // cancel/confirm based on this
            cancel.Left       = confirmation.Left - cancel.Width - 16;

            Size controlsize = outer.FindMaxSubControlArea(0, 0);

            prompt.Size = new Size(controlsize.Width + 40, controlsize.Height + (theme.WindowsFrame ? 50 : 8));

            if (prompt.ShowDialog(p) == DialogResult.OK)
            {
                var r = (from t in tbs select t.Text).ToList();
                return(r);
            }
            else
            {
                return(null);
            }
        }