Skip to content

Commit

Permalink
jpabeem#6 Reorder pdf
Browse files Browse the repository at this point in the history
  • Loading branch information
emilpalsson committed Oct 15, 2018
1 parent 349a352 commit 8f4b3b7
Showing 1 changed file with 64 additions and 5 deletions.
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

0 comments on commit 8f4b3b7

Please sign in to comment.