Skip to content

Commit

Permalink
Added drag&drop for images in IssueForm. Bumped version to 2.6.4
Browse files Browse the repository at this point in the history
  • Loading branch information
RickZeeland committed Nov 21, 2022
1 parent aaea238 commit fbd4b25
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 37 deletions.
5 changes: 5 additions & 0 deletions MiniBug/IssueForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

101 changes: 66 additions & 35 deletions MiniBug/IssueForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,34 +178,11 @@ private void EditIssue()
this.txtImage.Text = CurrentIssue.ImageFilename;
this.txtImage.ForeColor = Color.Black;

// If there is an attached image, display it
if (!string.IsNullOrEmpty(CurrentIssue.ImageFilename))
{
// If there is an attached image, display it
string fullFilename = CurrentIssue.ImageFilename;
string filename = Path.GetFileName(fullFilename);

if (!File.Exists(fullFilename))
{
// Try to find image in the current apllication directory
if (Directory.Exists("Images"))
{
filename = @"Images\" + filename;
}

fullFilename = Path.Combine(Application.StartupPath, filename);
}

if (File.Exists(fullFilename))
{
this.txtImage.Text = fullFilename.Replace(Application.StartupPath + @"\", string.Empty);
this.splitContainer1.SplitterDistance = this.splitContainer1.Height / 2;
this.pictureBox1.Image = Image.FromFile(fullFilename);
this.pictureBox1.Visible = true;
}
else
{
this.txtImage.ForeColor = Color.Red; // Not found, display file name in red
}
this.splitContainer1.SplitterDistance = this.splitContainer1.Height / 2;
this.LoadImage(CurrentIssue.ImageFilename);
}

lblID.Text = CurrentIssue.ID.ToString();
Expand Down Expand Up @@ -284,19 +261,46 @@ private void buttonBrowseImage_Click(object sender, EventArgs e)
openFileDialog1.FileName = string.Empty;
openFileDialog1.InitialDirectory = Application.StartupPath; // Open in current directory

if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
this.splitContainer1.SplitterDistance = this.splitContainer1.Height / 2; // Make room in the splitcontainer
string imageFilename = openFileDialog1.FileName;
imageFilename = imageFilename.Replace(Application.StartupPath + @"\", string.Empty); // Truncate file name if possible
this.txtImage.Text = imageFilename;
LoadImage(openFileDialog1.FileName);
}
}

/// <summary>
/// Load an image in the PictureBox.
/// </summary>
/// <param name="imageFilename">The image file name</param>
private void LoadImage(string imageFilename)
{
string fullFilename = imageFilename;
string filename = Path.GetFileName(fullFilename);

if (File.Exists(imageFilename))
if (!File.Exists(fullFilename))
{
// Try to find image in the current application directory
if (Directory.Exists("Images"))
{
this.pictureBox1.Image = Image.FromFile(imageFilename);
this.pictureBox1.Visible = true;
this.txtImage.ForeColor = Color.Black;
filename = @"Images\" + filename;
}

fullFilename = Path.Combine(Application.StartupPath, filename);
}

imageFilename = fullFilename.Replace(Application.StartupPath + @"\", string.Empty); // Truncate file name if possible
this.txtImage.Text = imageFilename;

if (File.Exists(imageFilename))
{
this.txtImage.ForeColor = Color.Black;
this.splitContainer1.SplitterDistance = this.splitContainer1.Height / 2; // Make room in the splitcontainer
this.pictureBox1.Image = Image.FromFile(imageFilename);
this.pictureBox1.Visible = true;
}
else
{
this.txtImage.ForeColor = Color.Red; // Not found, display file name in red
}
}

Expand Down Expand Up @@ -625,5 +629,32 @@ private void cboStatus_SelectedIndexChanged(object sender, EventArgs e)
var brush = ApplicationSettings.IssueStatusColors[status];
this.panelStatus.BackColor = ((SolidBrush)brush).Color;
}

/// <summary>
/// Note: drag and drop does not work in Visual Studio.
/// </summary>
private void IssueForm_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Move;
}

/// <summary>
/// Note: drag and drop does not work in Visual Studio.
/// </summary>
private void IssueForm_DragDrop(object sender, DragEventArgs e)
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);

if (files != null)
{
//foreach (string file in files)
//{
// // Keep Messagebox on top of other applications
// MessageBox.Show(file, Program.myName, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
//}

this.LoadImage(files[0]);
}
}
}
}
4 changes: 2 additions & 2 deletions MiniBug/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.6.3.0")]
[assembly: AssemblyFileVersion("2.6.3.0")]
[assembly: AssemblyVersion("2.6.4.0")]
[assembly: AssemblyFileVersion("2.6.4.0")]
[assembly: NeutralResourcesLanguage("")]

0 comments on commit fbd4b25

Please sign in to comment.