public BetterMessageBoxFluentInterface <T> StandardImage(StandardImageKind imageKind)
        {
            byte[] imageData;
            switch (imageKind)
            {
            case StandardImageKind.Error:
                imageData = BetterMessageBoxStandardIcons.Error48;
                break;

            case StandardImageKind.Warning:
                imageData = BetterMessageBoxStandardIcons.Warning48;
                break;

            case StandardImageKind.Question:
                imageData = BetterMessageBoxStandardIcons.Question48;
                break;

            case StandardImageKind.Success:
                imageData = BetterMessageBoxStandardIcons.Success48;
                break;

            default:
                throw new ArgumentException("imageKind");
            }
            using (MemoryStream stream = new MemoryStream(imageData))
            {
                Image image = System.Drawing.Image.FromStream(stream);
                BetterMessageBoxData = BetterMessageBoxData.WithImage(image);
            }
            return(this);
        }
        public BetterMessageBoxFluentInterface <T> ResourceImage(Assembly assembly, string resourceName)
        {
            Stream stream = assembly.GetManifestResourceStream(resourceName.Replace('/', '.').Replace('\\', '.'));
            Image  image  = System.Drawing.Image.FromStream(stream);

            BetterMessageBoxData = BetterMessageBoxData.WithImage(image);
            return(this);
        }
Exemplo n.º 3
0
        public BetterMessageBoxForm(BetterMessageBoxData <T> data)
        {
            const int ButtonWidthPadding  = 12;
            const int ButtonHeightPadding = 8;
            const int ButtonSpacing       = 8;
            const int FormWidthPadding    = 16;
            const int FormHeightPadding   = 16;

            int imageWidth  = data.Image?.Width ?? 0;
            int imageHeight = data.Image?.Height ?? 0;

            _data        = data;
            DialogResult = DialogResult.None;

            Text            = _data.Caption ?? string.Empty;
            MinimizeBox     = false;
            MaximizeBox     = false;
            ShowIcon        = false;
            ShowInTaskbar   = false;
            FormBorderStyle = FormBorderStyle.FixedSingle;

            Font font     = new Font(_data.FontName, _data.FontSize);
            Font boldFont = new Font(_data.FontName, _data.FontSize, FontStyle.Bold);
            Size textSize = TextRenderer.MeasureText(_data.Message ?? string.Empty, font);

            _buttonPanel = new Panel();
            Controls.Add(_buttonPanel);

            if (data.Image != null && imageWidth > 0)
            {
                _pictureBox = new PictureBox();
                Controls.Add(_pictureBox);
                _pictureBox.Image    = data.Image;
                _pictureBox.Size     = data.Image.Size;
                _pictureBox.Location = new Point(FormWidthPadding, FormHeightPadding);
            }

            int textVerticalOffset = textSize.Height >= imageHeight
                                ? 0
                                : (imageHeight - textSize.Height) / 2;

            _textBox = new TextBox();
            Controls.Add(_textBox);
            _textBox.BorderStyle = BorderStyle.None;
            _textBox.Multiline   = true;
            _textBox.Location    = new Point(FormWidthPadding + (imageWidth > 0 ? imageWidth + FormWidthPadding : 0), FormHeightPadding + textVerticalOffset);
            _textBox.Size        = new Size(textSize.Width + FormWidthPadding * 2, textSize.Height + FormHeightPadding * 2);
            _textBox.WordWrap    = true;
            _textBox.Text        = _data.Message ?? string.Empty;
            _textBox.BackColor   = BackColor;
            _textBox.Font        = font;

            int buttonOffset = 0;
            int maxHeight    = 0;

            foreach (BetterMessageBoxButton <T> buttonData in data.Buttons)
            {
                BetterMessageBoxButton <T> localButtonData = buttonData;

                Button button = new Button();
                _buttonPanel.Controls.Add(button);
                Font buttonFont     = buttonData.Bold ? boldFont : font;
                Size buttonTextSize = TextRenderer.MeasureText(buttonData.Text ?? string.Empty, buttonFont);
                button.AutoSize = false;
                button.Location = new Point(buttonOffset, 0);
                button.Font     = buttonFont;
                button.Size     = new Size(buttonTextSize.Width + ButtonWidthPadding * 2,
                                           buttonTextSize.Height + ButtonHeightPadding * 2);
                button.Text   = buttonData.Text;
                button.Click += (sender, e) =>
                {
                    OnButtonClicked(localButtonData);
                };

                buttonOffset += buttonTextSize.Width + ButtonWidthPadding * 2 + ButtonSpacing;
                if (buttonTextSize.Height > maxHeight)
                {
                    maxHeight = buttonTextSize.Height;
                }
            }
            foreach (Control control in _buttonPanel.Controls)
            {
                control.Height = maxHeight + ButtonHeightPadding * 2;
            }

            _buttonPanel.Size = new Size(buttonOffset - ButtonSpacing + FormWidthPadding,
                                         maxHeight + ButtonHeightPadding * 2 + FormHeightPadding);

            ClientSize = new Size(
                Math.Max(_buttonPanel.Width + FormWidthPadding, _textBox.Width + (imageWidth > 0 ? imageWidth + FormWidthPadding : 0)),
                Math.Max(imageHeight + FormHeightPadding * 2, _textBox.Height) + _buttonPanel.Height);

            _buttonPanel.Location = new Point(ClientSize.Width - _buttonPanel.Width, ClientSize.Height - _buttonPanel.Height);

            _buttonPanel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
            _textBox.Anchor     = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Right | AnchorStyles.Left;

            StartPosition = _data.Owner != null ? FormStartPosition.CenterParent : FormStartPosition.CenterScreen;
        }
 public BetterMessageBoxFluentInterface <T> Font(string fontName, int fontSize)
 {
     BetterMessageBoxData = BetterMessageBoxData.WithFont(fontName, fontSize);
     return(this);
 }
 public BetterMessageBoxFluentInterface <T> Image(Image image)
 {
     BetterMessageBoxData = BetterMessageBoxData.WithImage(image);
     return(this);
 }
 public BetterMessageBoxFluentInterface <T> Button(string text, T value, bool bold = false)
 {
     BetterMessageBoxData = BetterMessageBoxData.AddButtons(new BetterMessageBoxButton <T>(text, value, bold));
     return(this);
 }
 public BetterMessageBoxFluentInterface <T> Buttons(params BetterMessageBoxButton <T>[] buttons)
 {
     BetterMessageBoxData = BetterMessageBoxData.AddButtons(buttons);
     return(this);
 }
 public BetterMessageBoxFluentInterface <T> Caption(string caption)
 {
     BetterMessageBoxData = BetterMessageBoxData.WithCaption(caption);
     return(this);
 }
 public BetterMessageBoxFluentInterface <T> Message(string message)
 {
     BetterMessageBoxData = BetterMessageBoxData.WithMessage(message);
     return(this);
 }
Exemplo n.º 10
0
 public BetterMessageBoxFluentInterface <T> Owner(IWin32Window owner)
 {
     BetterMessageBoxData = BetterMessageBoxData.WithOwner(owner);
     return(this);
 }