示例#1
0
            protected override void InitializeComponents()
            {
                base.InitializeComponents();
                btnOK.Click += (sender, e) =>
                {
                    if (ItemText.IsNullOrWhiteSpace())
                    {
                        AppMessageBox.Show(AppString.Message.TextCannotBeEmpty);
                        return;
                    }
                    if (ItemCommand.IsNullOrWhiteSpace())
                    {
                        AppMessageBox.Show(AppString.Message.CommandCannotBeEmpty);
                        return;
                    }
                    AddNewItem();
                    DialogResult = DialogResult.OK;
                };

                btnBrowse.Click += (sender, e) =>
                {
                    using (OpenFileDialog dlg = new OpenFileDialog())
                    {
                        if (dlg.ShowDialog() != DialogResult.OK)
                        {
                            return;
                        }
                        this.ItemFilePath = dlg.FileName;
                        this.ItemText     = Path.GetFileNameWithoutExtension(dlg.FileName);
                    }
                };
            }
示例#2
0
            protected override void InitializeComponents()
            {
                base.InitializeComponents();
                this.Controls.AddRange(new Control[] { rdoFile, rdoFolder });
                rdoFile.Top    = rdoFolder.Top = btnOK.Top + (btnOK.Height - rdoFile.Height) / 2;
                rdoFile.Left   = lblCommand.Left;
                rdoFolder.Left = rdoFile.Right + 20.DpiZoom();

                btnBrowse.Click += (sender, e) =>
                {
                    if (rdoFile.Checked)
                    {
                        BrowseFile();
                    }
                    else
                    {
                        BrowseFolder();
                    }
                };

                btnOK.Click += (sender, e) =>
                {
                    if (ItemText.IsNullOrWhiteSpace())
                    {
                        AppMessageBox.Show(AppString.Message.TextCannotBeEmpty);
                    }
                    else if (ItemFilePath.IsNullOrWhiteSpace())
                    {
                        AppMessageBox.Show(AppString.Message.CommandCannotBeEmpty);
                    }
                    else if (rdoFile.Checked && !ObjectPath.GetFullFilePath(ItemFilePath, out _))
                    {
                        AppMessageBox.Show(AppString.Message.FileNotExists);
                    }
                    else if (rdoFolder.Checked && !Directory.Exists(ItemFilePath))
                    {
                        AppMessageBox.Show(AppString.Message.FolderNotExists);
                    }
                    else
                    {
                        DialogResult = DialogResult.OK;
                    }
                };

                txtFilePath.TextChanged += (sender, e) =>
                {
                    if (Path.GetExtension(ItemFilePath).ToLower() == ".lnk")
                    {
                        using (ShellLink shortcut = new ShellLink(ItemFilePath))
                        {
                            if (File.Exists(shortcut.TargetPath))
                            {
                                ItemFilePath = shortcut.TargetPath;
                            }
                        }
                    }
                };
            }
            protected override void InitializeComponents()
            {
                base.InitializeComponents();
                this.Text = AppString.Dialog.NewSendToItem;
                this.Controls.AddRange(new Control[] { rdoFile, rdoFolder });
                rdoFile.Top    = rdoFolder.Top = btnOk.Top;
                rdoFile.Left   = lblCommand.Left;
                rdoFolder.Left = rdoFile.Right + 20.DpiZoom();

                btnBrowse.Click += (sender, e) =>
                {
                    if (rdoFile.Checked)
                    {
                        BrowseFile();
                    }
                    else
                    {
                        BrowseFolder();
                    }
                };

                btnOk.Click += (sender, e) =>
                {
                    if (ItemText.IsNullOrWhiteSpace())
                    {
                        MessageBoxEx.Show(AppString.MessageBox.TextCannotBeEmpty);
                        return;
                    }
                    if (Command.IsNullOrWhiteSpace())
                    {
                        MessageBoxEx.Show(AppString.MessageBox.CommandCannotBeEmpty);
                        return;
                    }
                    if (rdoFile.Checked && !ObjectPath.GetFullFilePath(Command, out _))
                    {
                        MessageBoxEx.Show(AppString.MessageBox.FileNotExists);
                        return;
                    }
                    if (rdoFolder.Checked && !Directory.Exists(Command))
                    {
                        MessageBoxEx.Show(AppString.MessageBox.FolderNotExists);
                        return;
                    }
                    AddNewItem();
                    DialogResult = DialogResult.OK;
                };
            }