aboutsummaryrefslogtreecommitdiff
path: root/source/ShiftUI/Form/MessageBox.cs
blob: aab960a486f86f09c7de79558b6c536ddbc5f146 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ShiftUI
{
    public class MessageBox : Form
    {
        
        public static void Show(string message, string title)
        {
            var m = new MessageBox(title, message);
            
            m.TopMost = true;
            m.ShowDialog();
        }

        public MessageBox(string title, string message)
        {
            var pnlbottom = new FlowLayoutPanel();
            pnlbottom.Height = 30;
            pnlbottom.BackColor = Application.CurrentSkin.MessageBox_BottomPanel;
            var pnltop = new Panel();
            pnlbottom.Dock = DockStyle.Bottom;
            pnltop.Dock = DockStyle.Fill;
            this.Widgets.Add(pnlbottom);
            pnlbottom.Show();
            this.Widgets.Add(pnltop);
            pnltop.Show();
            var btnok = new Button();
            btnok.Text = "OK";
            btnok.AutoSize = true;
            btnok.AutoSizeMode = AutoSizeMode.GrowAndShrink;
            pnlbottom.Widgets.Add(btnok);
            btnok.Show();
            btnok.Click += (s, a) =>
            {
                this.Close();
            };
            var lblmessage = new Label();
            lblmessage.Padding = new Padding(25);
            lblmessage.Text = message;
            lblmessage.Dock = DockStyle.Fill;
            pnltop.Widgets.Add(lblmessage);
            lblmessage.Show();
            //autosize the form
            int newheight = 10;
            for(int i = 0; i < lblmessage.Text.Length; i++)
            {
                if ((i % 2) == 0)
                    newheight += 10;
            }
            this.MaximumSize = new System.Drawing.Size(500, 200);
            this.Height = newheight + pnlbottom.Height;
            this.Load += (o, a) =>
            {
                this.Left = (Screen.PrimaryScreen.Bounds.Width - this.Width) / 2;
                this.Top = (Screen.PrimaryScreen.Bounds.Height - this.Height) / 2;

            };
            this.Text = title;
        }
    }
}