コード例 #1
0
            public static string ShowDialog(string text, string caption)
            {
                Form prompt = new DarkForm
                {
                    Width           = 400,
                    Height          = 150,
                    FormBorderStyle = FormBorderStyle.FixedToolWindow,
                    Text            = caption,
                    StartPosition   = FormStartPosition.CenterScreen
                };
                DarkLabel textLabel = new DarkLabel()
                {
                    Left = 50, Top = 15, Height = 50, Width = 300, Text = text
                };
                DarkTextBox textBox = new DarkTextBox()
                {
                    Left = 50, Top = 50, Width = 300
                };
                DarkButton confirmation = new DarkButton()
                {
                    Text = "Ok", Left = 250, Width = 100, Top = 80, DialogResult = DialogResult.OK
                };

                confirmation.Click += (sender, e) => { prompt.Close(); };
                prompt.Controls.Add(textBox);
                prompt.Controls.Add(confirmation);
                prompt.Controls.Add(textLabel);
                prompt.AcceptButton = confirmation;

                return(prompt.ShowDialog() == DialogResult.OK ? textBox.Text : "");
            }
コード例 #2
0
        public static void SaveWindowProperties(DarkForm form, ConfigurationBase config)
        {
            var name = "Window_" + form.Name;

            // Don't save anything to config, if form is minimized
            if (form.WindowState == FormWindowState.Minimized)
            {
                return;
            }

            config.GetType().GetProperty(name + "_Maximized")?.SetValue(config, form.WindowState == FormWindowState.Maximized);

            // Set size only if form isn't maximized, otherwise we'll get corrupted coordinates.
            if (form.WindowState != FormWindowState.Maximized)
            {
                config.GetType().GetProperty(name + "_Size")?.SetValue(config, form.Size);
                config.GetType().GetProperty(name + "_Position")?.SetValue(config, form.Location);
            }
        }
コード例 #3
0
        public static void LoadWindowProperties(DarkForm form, ConfigurationBase config)
        {
            var name = "Window_" + form.Name;

            var size = config.GetType().GetProperty(name + "_Size")?.GetValue(config);
            var pos  = config.GetType().GetProperty(name + "_Position")?.GetValue(config);
            var max  = config.GetType().GetProperty(name + "_Maximized")?.GetValue(config);

            if (size is Size)
            {
                form.Size = (Size)size;
            }
            if (pos is Point)
            {
                form.Location = (Point)pos;
            }
            if (max is bool)
            {
                form.WindowState = (bool)max ? FormWindowState.Maximized : FormWindowState.Normal;
            }

            if (form.Location.X == -1 && form.Location.Y == -1)
            {
                if (form.ParentForm == null)
                {
                    form.StartPosition = FormStartPosition.CenterScreen;
                }
                else
                {
                    form.StartPosition = FormStartPosition.CenterParent;
                }
            }
            else
            {
                form.StartPosition = FormStartPosition.Manual;
            }

            // Properly clamp screen coords to fix issues with out-of-bounds windows
            if (form.Location.X < 0)
            {
                form.Location = new Point(0, form.Location.Y);
            }
            if (form.Location.Y < 0)
            {
                form.Location = new Point(form.Location.X, 0);
            }

            // Also clamp max. width/height if we're not on multidisplay config
            if (Screen.AllScreens.Length == 1)
            {
                var w = Screen.PrimaryScreen.Bounds.Width - form.Width;
                var h = Screen.PrimaryScreen.Bounds.Height - form.Height;
                if (form.Location.X >= w)
                {
                    form.Location = new Point(w, form.Location.Y);
                }
                if (form.Location.Y >= h)
                {
                    form.Location = new Point(form.Location.X, h);
                }
            }
        }