| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524 | using PaintDotNet.SystemLayer;using System;using System.Drawing;using System.Windows.Forms;namespace PaintDotNet{    public static class TaskDialog    {        public static int DefaultPixelWidth96Dpi = 300;        public static TaskButton Show(            IWin32Window owner,            Icon formIcon,            string formTitle,            Image taskImage,            string introText,            TaskButton[] taskButtons,            TaskButton acceptTaskButton,            TaskButton cancelTaskButton)        {            return Show(owner, formIcon, formTitle, taskImage, true, introText,                taskButtons, acceptTaskButton, cancelTaskButton, false, 0);        }        public static TaskButton Show(            IWin32Window owner,            Icon formIcon,            string formTitle,            Image taskImage,            bool scaleTaskImageWithDpi,            string introText,            TaskButton[] taskButtons,            TaskButton acceptTaskButton,            TaskButton cancelTaskButton,            bool showCheckbox,            int conflictNum)        {            bool useChecked;            return Show(owner, formIcon, formTitle, taskImage, scaleTaskImageWithDpi, introText,                taskButtons, acceptTaskButton, cancelTaskButton, DefaultPixelWidth96Dpi, showCheckbox, conflictNum, out useChecked);        }        public static TaskButton Show(            IWin32Window owner,            Icon formIcon,            string formTitle,            Image taskImage,            bool scaleTaskImageWithDpi,            string introText,            TaskButton[] taskButtons,            TaskButton acceptTaskButton,            TaskButton cancelTaskButton,            int pixelWidth96Dpi,            bool showCheckbox,            int conflictNum,            out bool useChecked)        {            return Show(owner, formIcon, formTitle, taskImage, scaleTaskImageWithDpi, introText,                taskButtons, acceptTaskButton, cancelTaskButton, pixelWidth96Dpi, null, null, showCheckbox, conflictNum, out useChecked);        }        public static TaskButton Show(            IWin32Window owner,            Icon formIcon,            string formTitle,            Image taskImage,            bool scaleTaskImageWithDpi,            string introText,            TaskButton[] taskButtons,            TaskButton acceptTaskButton,            TaskButton cancelTaskButton,            int pixelWidth96Dpi,            string auxButtonText,            EventHandler auxButtonClickHandler,            bool showCheckbox,            int conflictNum,            out bool useChecked)        {            using (TaskDialogForm form = new TaskDialogForm(showCheckbox, conflictNum))            {                form.Icon = formIcon;                form.IntroText = introText;                form.Text = formTitle;                form.TaskImage = taskImage;                form.ScaleTaskImageWithDpi = scaleTaskImageWithDpi;                form.TaskButtons = taskButtons;                form.AcceptTaskButton = acceptTaskButton;                form.CancelTaskButton = cancelTaskButton;                if (auxButtonText != null)                {                    form.AuxButtonText = auxButtonText;                }                if (auxButtonClickHandler != null)                {                    form.AuxButtonClick += auxButtonClickHandler;                }                int pixelWidth = UI.ScaleWidth(pixelWidth96Dpi);                form.ClientSize = new Size(pixelWidth, form.ClientSize.Height);                DialogResult dr = form.ShowDialog(owner);                TaskButton result = form.DialogResult;                useChecked = form.checkBox.Checked;                return result;            }        }        private sealed class TaskDialogForm : PdnBaseForm        {            public bool showCheckbox = true;            private PictureBox taskImagePB;            private bool scaleTaskImageWithDpi;            private Label introTextLabel;            private TaskButton[] taskButtons;            private CommandButton[] commandButtons;            private HeaderLabel separator;            private TaskButton acceptTaskButton;            private TaskButton cancelTaskButton;            private TaskButton dialogResult;            public CheckBox checkBox;            private Button auxButton;            public string AuxButtonText            {                get                {                    return this.auxButton.Text;                }                set                {                    this.auxButton.Text = value;                    PerformLayout();                }            }            public event EventHandler AuxButtonClick;            private void OnAuxButtonClick()            {                if (AuxButtonClick != null)                {                    AuxButtonClick(this, EventArgs.Empty);                }            }            public new TaskButton DialogResult            {                get                {                    return this.dialogResult;                }            }            public Image TaskImage            {                get                {                    return this.taskImagePB.Image;                }                set                {                    this.taskImagePB.Image = value;                    PerformLayout();                    Invalidate(true);                }            }            public bool ScaleTaskImageWithDpi            {                get                {                    return this.scaleTaskImageWithDpi;                }                set                {                    this.scaleTaskImageWithDpi = value;                    PerformLayout();                    Invalidate(true);                }            }            public string IntroText            {                get                {                    return this.introTextLabel.Text;                }                set                {                    this.introTextLabel.Text = value;                    PerformLayout();                    Invalidate(true);                }            }            public TaskButton[] TaskButtons            {                get                {                    return (TaskButton[])this.taskButtons.Clone();                }                set                {                    this.taskButtons = (TaskButton[])value.Clone();                    InitCommandButtons();                    PerformLayout();                    Invalidate(true);                }            }            public TaskButton AcceptTaskButton            {                get                {                    return this.acceptTaskButton;                }                set                {                    this.acceptTaskButton = value;                    IButtonControl newAcceptButton = null;                    for (int i = 0; i < this.commandButtons.Length; ++i)                    {                        TaskButton asTaskButton = this.commandButtons[i].Tag as TaskButton;                        if (this.acceptTaskButton == asTaskButton)                        {                            newAcceptButton = this.commandButtons[i];                        }                    }                    AcceptButton = newAcceptButton;                }            }            public TaskButton CancelTaskButton            {                get                {                    return this.cancelTaskButton;                }                set                {                    this.cancelTaskButton = value;                    IButtonControl newCancelButton = null;                    for (int i = 0; i < this.commandButtons.Length; ++i)                    {                        TaskButton asTaskButton = this.commandButtons[i].Tag as TaskButton;                        if (this.cancelTaskButton == asTaskButton)                        {                            newCancelButton = this.commandButtons[i];                        }                    }                    CancelButton = newCancelButton;                }            }            /// <summary>            ///             /// </summary>            /// <param name="showCheckbox">ÊÇ·ñÏÔʾcheckbox</param>            /// <param name="num">³åÍ»ÊýÁ¿</param>            public TaskDialogForm(bool showCheckbox, int num)            {                this.showCheckbox = showCheckbox;                InitializeComponent();                if (!this.showCheckbox)                 {                    this.checkBox.Visible = false;                }                else                {                    if (num > 0)                     {                        this.checkBox.Text = PdnResources.GetString("Menu.Forafter.text") + num + PdnResources.GetString("Menu.Fiveoperation.text");                        this.checkBox.Visible = true;                    }else                    {                        this.checkBox.Visible = false;                    }                }            }            private void InitializeComponent()            {                SuspendLayout();                this.introTextLabel = new Label();                this.auxButton = new Button();                this.taskImagePB = new PictureBox();                this.separator = new HeaderLabel();                this.checkBox = new CheckBox();                //                // checkBox                //                this.checkBox.Dock = DockStyle.Bottom;                this.checkBox.Padding = new Padding(10, 0, 0, 0);                //                // introTextLabel                //                this.introTextLabel.Name = "introTextLabel";                //                // taskImagePB                //                this.taskImagePB.Name = "taskImagePB";                this.taskImagePB.SizeMode = PictureBoxSizeMode.StretchImage;                //                // auxButton                //                this.auxButton.Name = "auxButton";                this.auxButton.AutoSize = true;                this.auxButton.FlatStyle = FlatStyle.System;                this.auxButton.Visible = false;                this.auxButton.Click +=                    delegate (object sender, EventArgs e)                    {                        OnAuxButtonClick();                    };                //                // separator                //                this.separator.Name = "separator";                this.separator.RightMargin = 0;                //                // TaskDialogForm                //                this.Name = "TaskDialogForm";                this.ClientSize = new Size(300, 100);                this.FormBorderStyle = FormBorderStyle.FixedDialog;                this.MinimizeBox = false;                this.MaximizeBox = false;                this.ShowInTaskbar = false;                this.StartPosition = FormStartPosition.CenterParent;                this.Controls.Add(this.introTextLabel);                this.Controls.Add(this.taskImagePB);                this.Controls.Add(this.auxButton);                this.Controls.Add(this.separator);                this.Controls.Add(this.checkBox);                                ResumeLayout();            }                        protected override void OnLayout(LayoutEventArgs levent)            {                int leftMargin = UI.ScaleWidth(8);                int rightMargin = UI.ScaleWidth(8);                int topMargin = UI.ScaleHeight(8);                int bottomMargin = UI.ScaleHeight(8);                int imageToIntroHMargin = UI.ScaleWidth(8);                int topSectionToLinksVMargin = UI.ScaleHeight(8);                int commandButtonVMargin = UI.ScaleHeight(0);                int afterCommandButtonsVMargin = UI.ScaleHeight(8);                int insetWidth = ClientSize.Width - leftMargin - rightMargin;                if (this.taskImagePB.Image == null)                {                    this.taskImagePB.Location = new Point(0, topMargin);                    this.taskImagePB.Size = new Size(0, 0);                    this.taskImagePB.Visible = false;                }                else                {                    this.taskImagePB.Location = new Point(leftMargin, topMargin);                    if (this.scaleTaskImageWithDpi)                    {                        this.taskImagePB.Size = UI.ScaleSize(this.taskImagePB.Image.Size);                    }                    else                    {                        this.taskImagePB.Size = this.taskImagePB.Image.Size;                    }                    this.taskImagePB.Visible = true;                }                this.introTextLabel.Location = new Point(this.taskImagePB.Right + imageToIntroHMargin, this.taskImagePB.Top);                this.introTextLabel.Width = ClientSize.Width - this.introTextLabel.Left - rightMargin;                this.introTextLabel.Height = this.introTextLabel.GetPreferredSize(new Size(this.introTextLabel.Width, 1)).Height;                int y = Math.Max(this.taskImagePB.Bottom, this.introTextLabel.Bottom);                y += topSectionToLinksVMargin;                if (!string.IsNullOrEmpty(this.auxButton.Text))                {                    this.auxButton.Visible = true;                    this.auxButton.Location = new Point(leftMargin, y);                    this.auxButton.PerformLayout();                    y += this.auxButton.Height;                    y += topSectionToLinksVMargin;                }                else                {                    this.auxButton.Visible = false;                }                if (this.commandButtons != null)                {                    this.separator.Location = new Point(leftMargin, y);                    this.separator.Width = insetWidth;                    y += this.separator.Height;                    for (int i = 0; i < this.commandButtons.Length; ++i)                    {                        this.commandButtons[i].Location = new Point(leftMargin, y);                        this.commandButtons[i].Width = insetWidth;                        this.commandButtons[i].PerformLayout();                        y += this.commandButtons[i].Height + commandButtonVMargin;                    }                    y += afterCommandButtonsVMargin;                }                this.ClientSize = new Size(ClientSize.Width, (this.showCheckbox ? (y + 20) : y));                base.OnLayout(levent);            }            private void InitCommandButtons()            {                SuspendLayout();                if (this.commandButtons != null)                {                    foreach (CommandButton commandButton in this.commandButtons)                    {                        Controls.Remove(commandButton);                        commandButton.Tag = null;                        commandButton.Click -= CommandButton_Click;                        commandButton.Dispose();                    }                    this.commandButtons = null;                }                this.commandButtons = new CommandButton[this.taskButtons.Length];                IButtonControl newAcceptButton = null;                IButtonControl newCancelButton = null;                for (int i = 0; i < this.commandButtons.Length; ++i)                {                    TaskButton taskButton = this.taskButtons[i];                    CommandButton commandButton = new CommandButton();                    commandButton.ActionText = taskButton.ActionText;                    commandButton.ActionImage = taskButton.Image;                    commandButton.AutoSize = true;                    commandButton.ExplanationText = taskButton.ExplanationText;                    commandButton.Tag = taskButton;                    commandButton.Click += CommandButton_Click;                    this.commandButtons[i] = commandButton;                    Controls.Add(commandButton);                    if (this.acceptTaskButton == taskButton)                    {                        newAcceptButton = commandButton;                    }                    if (this.cancelTaskButton == taskButton)                    {                        newCancelButton = commandButton;                    }                }                AcceptButton = newAcceptButton;                CancelButton = newCancelButton;                if (newAcceptButton != null && newAcceptButton is Control)                {                    ((Control)newAcceptButton).Select();                }                ResumeLayout();            }            private void CommandButton_Click(object sender, EventArgs e)            {                CommandButton commandButton = (CommandButton)sender;                if (commandButton.keyCode == 0)                {                    for (int i = 0; i < this.taskButtons.Length; i++)                    {                        if (this.taskButtons[i].ActionText == PdnResources.GetString("CloseWorkspaceAction.SaveButton.ActionText") + "( Y )")                        {                            this.dialogResult = this.taskButtons[i];                            commandButton.keyCode = -1;                            break;                        }                    }                }                else if (commandButton.keyCode == 1)                {                    for (int i = 0; i < this.taskButtons.Length; i++)                    {                        if (this.taskButtons[i].ActionText == PdnResources.GetString("CloseWorkspaceAction.DontSaveButton.ActionText") + "( N )")                        {                            this.dialogResult = this.taskButtons[i];                            commandButton.keyCode = -1;                            break;                        }                    }                }                else                    this.dialogResult = (TaskButton)commandButton.Tag;                Close();            }        }    }}
 |