Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Reorder pdf #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 64 additions & 5 deletions MergePDF/PdfSelectorControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ namespace MergePDF
public partial class PdfSelectorControl : UserControl
{
private OpenFileDialog openFileDialog;
public string FileName { get; private set; }
public string FileName
{
get => textBox.Text;
set => textBox.Text = value;
}

public int Index { get; }

TextBox textBox;
Expand All @@ -30,14 +35,70 @@ public PdfSelectorControl(int index)

Controls.Add(textBox);
Controls.Add(CreateOpenButton());
Controls.Add(CreateMoveUpButton());
Controls.Add(CreateMoveDownButton());
}

private Button CreateMoveUpButton()
{
Button button = new Button
{
Location = new Point(490, 0),
Size = new Size(20, 20),
Text = "▲",
Visible = true
};

button.Click += (sender, e) =>
{
if (this.Index == 1)
{
MessageBox.Show("This is already the first file.", "Unable to move", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
var prev = (PdfSelectorControl)this.Parent.Controls[this.Index - 2];
var prevFileName = prev.FileName;
prev.FileName = FileName;
FileName = prevFileName;

};

return button;
}

private Button CreateMoveDownButton()
{
Button button = new Button
{
Location = new Point(510, 0),
Size = new Size(20, 20),
Text = "▼",
Visible = true
};

button.Click += (sender, e) =>
{
var next = this.Parent.Controls[this.Index] as PdfSelectorControl;
if (next == null)
{
MessageBox.Show("This is already the last file.", "Unable to move", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
var nextFilename = next.FileName;
next.FileName = FileName;
FileName = nextFilename;

};

return button;
}

private void CreateTextbox()
{
textBox = new TextBox
{
Location = new Point(126, 0),
Size = new Size(400, 20),
Size = new Size(350, 20),
Visible = true,
ReadOnly = true
};
Expand All @@ -59,9 +120,7 @@ private Button CreateOpenButton()
{
try
{
string fileName = dialog.FileName;
textBox.Text = fileName;
FileName = fileName;
FileName = dialog.FileName;
}
catch (System.IO.IOException)
{
Expand Down