Example #1
0
        public static string Show(string Label, string Title = "", List <Button> Buttons = null, PictureBox Image = null)
        {
            List <Label> Labels = new List <Label>();

            Labels.Add(MyLabel.Set(Label));
            return(Show(Labels, Title, Buttons, Image));
        }
Example #2
0
        public static string Show(List <Label> Labels = null, string Title = "", List <Button> Buttons = null, PictureBox Image = null)
        {
            if (Labels == null)
            {
                Labels = new List <Label>();
            }
            if (Labels.Count == 0)
            {
                Labels.Add(MyLabel.Set(""));
            }
            if (Buttons == null)
            {
                Buttons = new List <Button>();
            }
            if (Buttons.Count == 0)
            {
                Buttons.Add(MyButton.Set("OK"));
            }
            List <Button> buttons = new List <Button>(Buttons);

            buttons.Reverse();

            int ImageWidth   = 0;
            int ImageHeight  = 0;
            int LabelWidth   = 0;
            int LabelHeight  = 0;
            int ButtonWidth  = 0;
            int ButtonHeight = 0;
            int TotalWidth   = 0;
            int TotalHeight  = 0;

            MyMessageBox mb = new MyMessageBox();

            mb.Text = Title;

            //Image
            if (Image != null)
            {
                mb.Controls.Add(Image);
                Image.MaximumSize = new Size(150, 300);
                ImageWidth        = Image.Width + Image.Margin.Horizontal;
                ImageHeight       = Image.Height + Image.Margin.Vertical;
            }

            //Labels
            List <int> il = new List <int>();

            mb.panText.Location = new Point(9 + ImageWidth, 35);
            foreach (Label l in Labels)
            {
                mb.panText.Controls.Add(l);
                l.Location    = new Point(200, 50);
                l.MaximumSize = new Size(480, 2000);
                il.Add(l.Width);
            }
            int mw = Labels.Max(x => x.Width);

            il.ToString();
            Labels.ForEach(l => l.MinimumSize = new Size(Labels.Max(x => x.Width), 1));
            mb.panText.Height      = Labels.Sum(l => l.Height);
            mb.panText.MinimumSize = new Size(Labels.Max(x => x.Width) + mb.ScrollBarWidth(Labels), ImageHeight);
            mb.panText.MaximumSize = new Size(Labels.Max(x => x.Width) + mb.ScrollBarWidth(Labels), 300);
            LabelWidth             = mb.panText.Width;
            LabelHeight            = mb.panText.Height;

            //Buttons
            foreach (Button b in buttons)
            {
                mb.panButtons.Controls.Add(b);
                b.Location = new Point(3, 3);
                b.TabIndex = Buttons.FindIndex(i => i.Text == b.Text);
                b.Click   += new EventHandler(mb.Button_Click);
            }
            ButtonWidth  = mb.panButtons.Width;
            ButtonHeight = mb.panButtons.Height;

            //Set Widths
            if (ButtonWidth > ImageWidth + LabelWidth)
            {
                Labels.ForEach(l => l.MinimumSize = new Size(ButtonWidth - ImageWidth - mb.ScrollBarWidth(Labels), 1));
                mb.panText.Height      = Labels.Sum(l => l.Height);
                mb.panText.MinimumSize = new Size(Labels.Max(x => x.Width) + mb.ScrollBarWidth(Labels), ImageHeight);
                mb.panText.MaximumSize = new Size(Labels.Max(x => x.Width) + mb.ScrollBarWidth(Labels), 300);
                LabelWidth             = mb.panText.Width;
                LabelHeight            = mb.panText.Height;
            }
            TotalWidth = ImageWidth + LabelWidth;

            //Set Height
            TotalHeight = LabelHeight + ButtonHeight;

            mb.panButtons.Location = new Point(TotalWidth - ButtonWidth + 9, mb.panText.Location.Y + mb.panText.Height + 10);

            mb.Size = new Size(TotalWidth + 25, TotalHeight + 47);
            mb.ShowDialog();
            return(mb.Result);
        }