public InputBox(string text, string caption, string defaultValue)
        {
            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();

            text              = StringParser.Parse(text);
            this.Text         = StringParser.Parse(caption);
            acceptButton.Text = StringParser.Parse("${res:Global.OKButtonText}");
            cancelButton.Text = StringParser.Parse("${res:Global.CancelButtonText}");

            Size size;

            using (Graphics g = this.CreateGraphics()) {
                Rectangle screen = Screen.PrimaryScreen.WorkingArea;
                SizeF     sizeF  = g.MeasureString(text, label.Font, screen.Width - 20);
                size        = sizeF.ToSize();
                size.Width += 4;
            }
            if (size.Width < 200)
            {
                size.Width = 200;
            }
            Size clientSize = this.ClientSize;

            clientSize.Width  += size.Width - label.Width;
            clientSize.Height += size.Height - label.Height;
            this.ClientSize    = clientSize;
            label.Text         = text;
            textBox.Text       = defaultValue;
            this.DialogResult  = DialogResult.Cancel;
            RightToLeftConverter.ConvertRecursive(this);
        }
        public SaveErrorInformDialog(string fileName, string message, string dialogName, Exception exceptionGot)
        {
            this.Text = StringParser.Parse(dialogName);
            //  Must be called for initialization
            this.InitializeComponent2();
            RightToLeftConverter.ConvertRecursive(this);

            displayMessage = StringParser.Parse(message, new string[, ] {
                { "FileName", fileName },
                { "Path", Path.GetDirectoryName(fileName) },
                { "FileNameWithoutPath", Path.GetFileName(fileName) },
                { "Exception", exceptionGot.GetType().FullName },
            });
            descriptionTextBox.Lines = this.displayMessage.Split('\n');

            this.exceptionGot = exceptionGot;
        }
Example #3
0
        public SaveErrorChooseDialog(string fileName, string message, string dialogName, Exception exceptionGot, bool chooseLocationEnabled)
        {
            this.Text = StringParser.Parse(dialogName);
            //  Must be called for initialization
            this.InitializeComponents(chooseLocationEnabled);
            RightToLeftConverter.ConvertRecursive(this);

            displayMessage = StringParser.Parse(
                message,
                new StringTagPair("FileName", fileName),
                new StringTagPair("Path", Path.GetDirectoryName(fileName)),
                new StringTagPair("FileNameWithoutPath", Path.GetFileName(fileName)),
                new StringTagPair("Exception", exceptionGot.GetType().FullName)
                );

            descriptionTextBox.Lines = StringParser.Parse(this.displayMessage).Split('\n');

            this.exceptionGot = exceptionGot;
        }
Example #4
0
        public CustomDialog(string caption, string message, int acceptButton, int cancelButton, string[] buttonLabels)
        {
            this.SuspendLayout();
            MyInitializeComponent();

            this.Icon         = null;
            this.acceptButton = acceptButton;
            this.cancelButton = cancelButton;

            message   = StringParser.Parse(message);
            this.Text = StringParser.Parse(caption);

            using (Graphics g = this.CreateGraphics()) {
                Rectangle screen     = Screen.PrimaryScreen.WorkingArea;
                SizeF     size       = g.MeasureString(message, label.Font, screen.Width - 20);
                Size      clientSize = size.ToSize();
                Button[]  buttons    = new Button[buttonLabels.Length];
                int[]     positions  = new int[buttonLabels.Length];
                int       pos        = 0;
                for (int i = 0; i < buttons.Length; i++)
                {
                    Button newButton = new Button();
                    newButton.FlatStyle = FlatStyle.System;
                    newButton.Tag       = i;
                    string buttonLabel = StringParser.Parse(buttonLabels[i]);
                    newButton.Text   = buttonLabel;
                    newButton.Click += new EventHandler(ButtonClick);
                    SizeF buttonSize = g.MeasureString(buttonLabel, newButton.Font);
                    newButton.Width = Math.Max(newButton.Width, ((int)Math.Ceiling(buttonSize.Width / 8.0) + 1) * 8);
                    positions[i]    = pos;
                    buttons[i]      = newButton;
                    pos            += newButton.Width + 4;
                }
                if (acceptButton >= 0)
                {
                    AcceptButton = buttons[acceptButton];
                }
                if (cancelButton >= 0)
                {
                    CancelButton = buttons[cancelButton];
                }

                pos += 4;                 // add space before first button
                // (we don't start with pos=4 because this space doesn't belong to the button panel)

                if (pos > clientSize.Width)
                {
                    clientSize.Width = pos;
                }
                clientSize.Height += panel.Height + 6;
                this.ClientSize    = clientSize;
                int start = (clientSize.Width - pos) / 2;
                for (int i = 0; i < buttons.Length; i++)
                {
                    buttons[i].Location = new Point(start + positions[i], 4);
                }
                panel.Controls.AddRange(buttons);
            }
            label.Text = message;

            RightToLeftConverter.ConvertRecursive(this);
            this.ResumeLayout(false);
        }