Delete button
This commit is contained in:
14
ImageView/FrmImageView.Designer.cs
generated
14
ImageView/FrmImageView.Designer.cs
generated
@@ -33,6 +33,7 @@
|
||||
this.btnPrev = new System.Windows.Forms.Button();
|
||||
this.btnSelectInExplorer = new System.Windows.Forms.Button();
|
||||
this.picImageView = new ImageView.Controls.CtrImageViewer();
|
||||
this.btnDelete = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.picImageView)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
@@ -82,11 +83,23 @@
|
||||
this.picImageView.TabIndex = 0;
|
||||
this.picImageView.TabStop = false;
|
||||
//
|
||||
// btnDelete
|
||||
//
|
||||
this.btnDelete.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.btnDelete.Location = new System.Drawing.Point(194, 521);
|
||||
this.btnDelete.Name = "btnDelete";
|
||||
this.btnDelete.Size = new System.Drawing.Size(75, 23);
|
||||
this.btnDelete.TabIndex = 4;
|
||||
this.btnDelete.Text = "Delete";
|
||||
this.btnDelete.UseVisualStyleBackColor = true;
|
||||
this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click);
|
||||
//
|
||||
// FrmImageView
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(663, 550);
|
||||
this.Controls.Add(this.btnDelete);
|
||||
this.Controls.Add(this.btnSelectInExplorer);
|
||||
this.Controls.Add(this.btnPrev);
|
||||
this.Controls.Add(this.btnNext);
|
||||
@@ -105,5 +118,6 @@
|
||||
private System.Windows.Forms.Button btnNext;
|
||||
private System.Windows.Forms.Button btnPrev;
|
||||
private System.Windows.Forms.Button btnSelectInExplorer;
|
||||
private System.Windows.Forms.Button btnDelete;
|
||||
}
|
||||
}
|
||||
@@ -39,10 +39,13 @@ namespace ImageView
|
||||
Image image;
|
||||
try
|
||||
{
|
||||
image = Bitmap.FromFile(_imagePath);
|
||||
using (var bmpTemp = new Bitmap(_imagePath))
|
||||
{
|
||||
FixImageOrientation(bmpTemp);
|
||||
image = new Bitmap(bmpTemp);
|
||||
}
|
||||
}
|
||||
catch (Exception) { return false; }
|
||||
FixImageOrientation(image);
|
||||
picImageView.ImageShow = image;
|
||||
Text = Path.GetFileName(_imagePath);
|
||||
return true;
|
||||
@@ -70,25 +73,25 @@ namespace ImageView
|
||||
return files[idx];
|
||||
}
|
||||
|
||||
private void NextImage()
|
||||
private bool NextImage()
|
||||
{
|
||||
string filename = _imagePath;
|
||||
do
|
||||
{
|
||||
filename = NextFile(filename);
|
||||
if (filename == null) { break; }
|
||||
if (SetImage(filename)) { break; }
|
||||
if (filename == null) { return false; }
|
||||
if (SetImage(filename)) { return true; }
|
||||
} while (true);
|
||||
}
|
||||
|
||||
private void PrevImage()
|
||||
private bool PrevImage()
|
||||
{
|
||||
string filename = _imagePath;
|
||||
do
|
||||
{
|
||||
filename = PrevFile(filename);
|
||||
if (filename == null) { break; }
|
||||
if (SetImage(filename)) { break; }
|
||||
if (filename == null) { return false; }
|
||||
if (SetImage(filename)) { return true; }
|
||||
} while (true);
|
||||
}
|
||||
|
||||
@@ -110,8 +113,12 @@ namespace ImageView
|
||||
public static short GetExifOrientation(Image photo)
|
||||
{
|
||||
const int orientationIndex = 0x0112;
|
||||
PropertyItem prop = photo.GetPropertyItem(orientationIndex);
|
||||
return BitConverter.ToInt16(prop.Value, 0);
|
||||
try
|
||||
{
|
||||
PropertyItem prop = photo.GetPropertyItem(orientationIndex);
|
||||
return BitConverter.ToInt16(prop.Value, 0);
|
||||
}
|
||||
catch (Exception) { return 0; }
|
||||
}
|
||||
|
||||
public static void FixImageOrientation(Image image)
|
||||
@@ -131,5 +138,23 @@ namespace ImageView
|
||||
}
|
||||
}
|
||||
|
||||
private void btnDelete_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult result = MessageBox.Show("Are you sure to delete this image?", "", MessageBoxButtons.YesNo);
|
||||
if (result != DialogResult.Yes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string fileToDelete = _imagePath;
|
||||
if (NextImage() == false)
|
||||
{
|
||||
if (PrevImage() == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
File.Delete(fileToDelete);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user