2019-03-22 23:53:20 +01:00
using Microsoft.VisualBasic.FileIO ;
using Mk0.GUI.Banner ;
2019-04-05 10:52:47 +02:00
using Mk0.Software.ImageSorter.Properties ;
2019-03-22 23:53:20 +01:00
using Mk0.Tools.Calculation ;
2019-04-05 10:52:47 +02:00
using Mk0.Tools.FileAssociaton ;
2019-03-22 23:53:20 +01:00
using Mk0.Tools.Images ;
using Mk0.Tools.Randomization ;
using System ;
using System.Collections.Generic ;
using System.ComponentModel ;
using System.Diagnostics ;
using System.Drawing ;
using System.Drawing.Imaging ;
using System.IO ;
using System.Linq ;
using System.Threading ;
using System.Windows.Forms ;
2019-12-27 23:42:36 +01:00
using Mk0.Software.OnlineUpdater ;
2022-08-13 19:45:21 +02:00
using System.Threading.Tasks ;
2019-03-22 23:53:20 +01:00
namespace Mk0.Software.ImageSorter
{
public partial class Main : Form
{
public string quellPath = "" ;
public string zielPath = "" ;
2023-03-27 19:10:29 +02:00
private string [ ] fileTypes = { ".jpg" , ".png" , ".jpeg" , ".gif" , ".tif" , ".tiff" , ".bmp" , ".webp" , ".heic" } ;
2019-03-22 23:53:20 +01:00
private int moved = 0 ;
private int imageIndex ;
private List < Button > buttons = new List < Button > ( ) ;
private List < string > images = new List < string > ( ) ;
private List < string > history = new List < string > ( ) ;
private bool moving ;
private bool moveable = false ;
private Point startLocation ; //verschieben
2019-04-05 11:53:41 +02:00
private Cursor grabCursor = new Cursor ( new MemoryStream ( Resources . grab ) ) ;
private Cursor grabbingCursor = new Cursor ( new MemoryStream ( Resources . grabbing ) ) ;
2019-03-22 23:53:20 +01:00
private double xFaktor = 0.0 ;
private double yFaktor = 0.0 ;
private static object locker = new object ( ) ;
private Thread folderThread ;
private bool threadIsRunning = false ;
private Banner banner ;
private string startuppath ;
private string startupimage ;
2019-03-30 14:07:41 +01:00
public string [ ] Args ;
2020-01-12 09:37:11 +01:00
private FormWindowState lastState = FormWindowState . Minimized ;
2020-01-19 08:40:43 +01:00
private string defaultWindowName ;
2019-03-22 23:53:20 +01:00
2019-03-30 14:07:41 +01:00
public Main ( )
2019-03-22 23:53:20 +01:00
{
InitializeComponent ( ) ;
2020-01-20 12:03:22 +01:00
defaultWindowName = Text ;
2019-08-15 20:31:28 +02:00
banner = new Banner ( components , panelBanner , pictureBoxBanner1 , pictureBoxBanner2 , labelBanner1 , labelBanner2 ) ;
pictureBoxImage . Cursor = grabCursor ;
2019-03-22 23:53:20 +01:00
DoubleBuffered = true ;
SetDefaultPath ( ) ;
2019-04-02 17:36:31 +02:00
comboBoxZoom . SelectedIndex = Properties . Settings . Default . zoom ;
2019-04-05 21:18:55 +02:00
2019-12-27 14:59:29 +01:00
//file assoc prüfen und in einstellungen richtig setzen
if ( FileAssociation . Check ( "Image_Sorter_JPG" , Application . ExecutablePath , "JPG Bild" , $@"{Application.StartupPath}\AssocIcons\jpg.ico" ) & &
FileAssociation . Check ( "Image_Sorter_PNG" , Application . ExecutablePath , "PNG Bild" , $@"{Application.StartupPath}\AssocIcons\png.ico" ) & &
FileAssociation . Check ( "Image_Sorter_GIF" , Application . ExecutablePath , "GIF Bild" , $@"{Application.StartupPath}\AssocIcons\gif.ico" ) & &
FileAssociation . Check ( "Image_Sorter_JPEG" , Application . ExecutablePath , "JPEG Bild" , $@"{Application.StartupPath}\AssocIcons\jpeg.ico" ) & &
FileAssociation . Check ( "Image_Sorter_BMP" , Application . ExecutablePath , "BMP Bild" , $@"{Application.StartupPath}\AssocIcons\bmp.ico" ) & &
FileAssociation . Check ( "Image_Sorter_TIF" , Application . ExecutablePath , "TIF Bild" , $@"{Application.StartupPath}\AssocIcons\tif.ico" ) & &
2023-03-27 19:10:29 +02:00
FileAssociation . Check ( "Image_Sorter_TIFF" , Application . ExecutablePath , "TIFF Bild" , $@"{Application.StartupPath}\AssocIcons\tiff.ico" ) & &
FileAssociation . Check ( "Image_Sorter_WEBP" , Application . ExecutablePath , "WEBP Bild" , $@"{Application.StartupPath}\AssocIcons\webp.ico" ) & &
FileAssociation . Check ( "Image_Sorter_HEIC" , Application . ExecutablePath , "HEIC Bild" , $@"{Application.StartupPath}\AssocIcons\heic.ico" ) )
2019-12-27 14:59:29 +01:00
{
Properties . Settings . Default . fileAssociation = true ;
}
else
{
Properties . Settings . Default . fileAssociation = false ;
}
Properties . Settings . Default . Save ( ) ;
2019-03-30 14:07:41 +01:00
}
2019-04-05 10:52:47 +02:00
2019-03-30 14:07:41 +01:00
private void Main_Load ( object sender , EventArgs e )
{
if ( Args ! = null )
2019-04-05 10:52:47 +02:00
{
2019-03-30 14:07:41 +01:00
ProcessParameters ( null , Args ) ;
Args = null ;
}
2020-01-20 12:03:22 +01:00
2019-12-27 23:42:36 +01:00
AutoUpdater . ShowSkipButton = false ;
2020-04-27 18:57:57 +02:00
AutoUpdater . Start ( "https://www.kmpr.at/update/imagesorter.xml" ) ;
2019-03-30 14:07:41 +01:00
}
2019-04-05 10:52:47 +02:00
2019-03-30 14:07:41 +01:00
public delegate void ProcessParametersDelegate ( object sender , string [ ] args ) ;
public void ProcessParameters ( object sender , string [ ] args )
{
if ( args ! = null & & args . Length ! = 0 )
{
if ( ! string . IsNullOrEmpty ( args [ 0 ] ) & & File . Exists ( args [ 0 ] ) )
{
startuppath = Path . GetDirectoryName ( args [ 0 ] ) ;
startupimage = Path . GetFileName ( args [ 0 ] ) ;
if ( ! string . IsNullOrEmpty ( startuppath ) & & File . Exists ( startuppath ) )
{
startuppath = Path . GetDirectoryName ( startuppath ) ;
startupimage = Path . GetFileName ( startuppath ) ;
}
SetDefaultPath ( ) ;
SearchImages ( ) ;
CountPicsInPath ( ) ;
LoadPicture ( GetImageIndex ( Path . Combine ( startuppath , startupimage ) ) ) ;
2023-08-10 14:46:36 +02:00
ShowPreviewImages ( ) ;
2019-10-26 14:48:15 +02:00
if ( WindowState ! = FormWindowState . Normal | | WindowState ! = FormWindowState . Maximized )
{
2020-01-12 09:37:11 +01:00
if ( lastState ! = FormWindowState . Minimized ) { WindowState = lastState ; } else { WindowState = FormWindowState . Normal ; }
2019-10-26 14:48:15 +02:00
}
2020-01-12 09:37:11 +01:00
Activate ( ) ;
2019-10-26 14:48:15 +02:00
BringToFront ( ) ;
2020-01-12 09:37:11 +01:00
TopMost = true ;
TopMost = false ;
2019-03-30 14:07:41 +01:00
}
2019-04-05 10:52:47 +02:00
}
}
/// <summary>
/// Extrahiert die Icons für die Fileassociation
/// </summary>
private void ExtractAssocIcons ( )
{
Directory . CreateDirectory ( $@"{Application.StartupPath}\AssocIcons" ) ;
WriteResource ( $@"{Application.StartupPath}\AssocIcons\jpg.ico" , Resources . jpg ) ;
WriteResource ( $@"{Application.StartupPath}\AssocIcons\png.ico" , Resources . png ) ;
WriteResource ( $@"{Application.StartupPath}\AssocIcons\gif.ico" , Resources . gif ) ;
WriteResource ( $@"{Application.StartupPath}\AssocIcons\jpeg.ico" , Resources . jpeg ) ;
WriteResource ( $@"{Application.StartupPath}\AssocIcons\bmp.ico" , Resources . bmp ) ;
WriteResource ( $@"{Application.StartupPath}\AssocIcons\tif.ico" , Resources . tif ) ;
WriteResource ( $@"{Application.StartupPath}\AssocIcons\tiff.ico" , Resources . tiff ) ;
2022-08-14 15:52:11 +02:00
WriteResource ( $@"{Application.StartupPath}\AssocIcons\webp.ico" , Resources . webp ) ;
2023-03-27 19:10:29 +02:00
WriteResource ( $@"{Application.StartupPath}\AssocIcons\heic.ico" , Resources . heic ) ;
2019-04-05 10:52:47 +02:00
}
/// <summary>
/// Helfer um Resources auf die Platte zu schreiben
/// </summary>
/// <param name="path">Zielpfad</param>
/// <param name="icon">Resource</param>
private void WriteResource ( string path , Icon icon )
{
using ( var fileStream = new FileStream ( path , FileMode . Create ) )
{
icon . Save ( fileStream ) ;
}
2019-03-22 23:53:20 +01:00
}
/// <summary>
/// Default: Lädt das erste Bild
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Main_Shown ( object sender , EventArgs e )
{
2020-01-10 21:27:04 +01:00
if ( Properties . Settings . Default . fullScreen )
2019-03-22 23:53:20 +01:00
{
2020-01-10 21:27:04 +01:00
WindowState = FormWindowState . Maximized ;
2019-03-22 23:53:20 +01:00
}
2020-01-10 21:27:04 +01:00
else
2019-03-22 23:53:20 +01:00
{
2020-01-10 21:27:04 +01:00
if ( Properties . Settings . Default . lastHeight > = MinimumSize . Height )
{
Height = Properties . Settings . Default . lastHeight ;
}
if ( Properties . Settings . Default . lastWidth > = MinimumSize . Width )
{
Width = Properties . Settings . Default . lastWidth ;
}
if ( Properties . Settings . Default . lastTop < = Screen . PrimaryScreen . Bounds . Height & & Properties . Settings . Default . lastTop > = 0 )
{
Top = Properties . Settings . Default . lastTop ;
}
if ( Properties . Settings . Default . lastLeft < = Screen . PrimaryScreen . Bounds . Width & & Properties . Settings . Default . lastLeft > = 0 )
{
Left = Properties . Settings . Default . lastLeft ;
}
2019-03-22 23:53:20 +01:00
}
2019-08-15 20:31:28 +02:00
groupBoxInformationen . Visible = Properties . Settings . Default . showInfo ;
if ( ! groupBoxInformationen . Visible )
2019-07-29 17:32:26 +02:00
{
2019-08-15 20:31:28 +02:00
groupBoxZiele . Location = new Point ( groupBoxZiele . Location . X , 12 ) ;
2022-08-13 19:45:21 +02:00
groupBoxZiele . Height + = 87 ;
2019-07-29 17:32:26 +02:00
}
2019-03-22 23:53:20 +01:00
CheckSubfolders ( ) ;
SearchImages ( ) ;
CountPicsInPath ( ) ;
if ( string . IsNullOrEmpty ( startupimage ) )
{
LoadPicture ( 0 ) ;
}
else
{
LoadPicture ( GetImageIndex ( Path . Combine ( startuppath , startupimage ) ) ) ;
}
ResetUndo ( ) ;
2022-08-13 18:06:29 +02:00
panelImageBackground . BackColor = Properties . Settings . Default . lightBackgroundColour ;
pictureBoxImage . BackColor = Properties . Settings . Default . lightBackgroundColour ;
2023-08-10 14:43:56 +02:00
if ( Properties . Settings . Default . preview )
{
panelImageBackground . Height - = 100 ;
ShowPreviewImages ( ) ;
panelPreview . Visible = true ;
}
2022-08-15 16:34:55 +02:00
//Christmas Easteregg
if ( DateTime . Now . Month = = 12 & & DateTime . Now . Day > = 24 & & DateTime . Now . Day < = 27 )
{
buttonChristmas . Visible = true ;
}
//End
2019-07-28 10:22:02 +02:00
ToolTip t1 = new ToolTip
{
AutoPopDelay = 5000 ,
InitialDelay = 1000 ,
ReshowDelay = 500
} ;
t1 . SetToolTip ( buttonJumpBack , "Voriges Bild" ) ;
ToolTip t2 = new ToolTip
{
AutoPopDelay = 5000 ,
InitialDelay = 1000 ,
ReshowDelay = 500
} ;
t2 . SetToolTip ( buttonJumpForward , "Nächstes Bild" ) ;
ToolTip t3 = new ToolTip
{
AutoPopDelay = 5000 ,
InitialDelay = 1000 ,
ReshowDelay = 500
} ;
t3 . SetToolTip ( buttonUndo , "Aktion Rückgängig machen" ) ;
ToolTip t4 = new ToolTip
{
AutoPopDelay = 5000 ,
InitialDelay = 1000 ,
ReshowDelay = 500
} ;
2021-04-02 21:16:50 +02:00
t4 . SetToolTip ( buttonSettings , "Einstellungen öffnen (F10)" ) ;
2019-07-28 10:22:02 +02:00
ToolTip t5 = new ToolTip
{
AutoPopDelay = 5000 ,
InitialDelay = 1000 ,
ReshowDelay = 500
} ;
2022-08-15 16:34:55 +02:00
t5 . SetToolTip ( buttonQuellPfad , "Quellpfad festlegen (Q)" ) ;
2019-07-28 10:22:02 +02:00
ToolTip t6 = new ToolTip
{
AutoPopDelay = 5000 ,
InitialDelay = 1000 ,
ReshowDelay = 500
} ;
2022-08-15 10:37:49 +02:00
t6 . SetToolTip ( buttonInfo , "Informationen ein-/ausblenden (I)" ) ;
2019-08-07 15:55:48 +02:00
ToolTip t7 = new ToolTip
{
AutoPopDelay = 5000 ,
InitialDelay = 1000 ,
ReshowDelay = 500
} ;
2021-04-02 21:16:50 +02:00
t7 . SetToolTip ( buttonDateirenamer , "Dateirenamer öffnen (F12)" ) ;
2022-08-15 10:37:49 +02:00
ToolTip t8 = new ToolTip
{
AutoPopDelay = 5000 ,
InitialDelay = 1000 ,
ReshowDelay = 500
} ;
t8 . SetToolTip ( buttonRander , "Ränder manuell beschneiden (R)" ) ;
ToolTip t9 = new ToolTip
{
AutoPopDelay = 5000 ,
InitialDelay = 1000 ,
ReshowDelay = 500
} ;
t9 . SetToolTip ( buttonDuplicate , "Duplizieren (D)" ) ;
ToolTip t10 = new ToolTip
{
AutoPopDelay = 5000 ,
InitialDelay = 1000 ,
ReshowDelay = 500
} ;
t10 . SetToolTip ( buttonDeleteImage , "Löschen (Entf)" ) ;
ToolTip t11 = new ToolTip
{
AutoPopDelay = 5000 ,
InitialDelay = 1000 ,
ReshowDelay = 500
} ;
t11 . SetToolTip ( buttonHintergrund , "Hintergrund hell/dunkel umschalten (H)" ) ;
ToolTip t12 = new ToolTip
{
AutoPopDelay = 5000 ,
InitialDelay = 1000 ,
ReshowDelay = 500
} ;
t12 . SetToolTip ( buttonTransformation , "Transformation (T)" ) ;
ToolTip t13 = new ToolTip
{
AutoPopDelay = 5000 ,
InitialDelay = 1000 ,
ReshowDelay = 500
} ;
t13 . SetToolTip ( buttonMirrorHorizontal , "Horizontal spiegeln" ) ;
ToolTip t14 = new ToolTip
{
AutoPopDelay = 5000 ,
InitialDelay = 1000 ,
ReshowDelay = 500
} ;
t14 . SetToolTip ( buttonMirrorVertikal , "Vertikal spiegeln" ) ;
ToolTip t15 = new ToolTip
{
AutoPopDelay = 5000 ,
InitialDelay = 1000 ,
ReshowDelay = 500
} ;
t15 . SetToolTip ( buttonRotate90 , "Drehen 90°" ) ;
ToolTip t16 = new ToolTip
{
AutoPopDelay = 5000 ,
InitialDelay = 1000 ,
ReshowDelay = 500
} ;
t16 . SetToolTip ( buttonRotate180 , "Drehen 180°" ) ;
ToolTip t17 = new ToolTip
{
AutoPopDelay = 5000 ,
InitialDelay = 1000 ,
ReshowDelay = 500
} ;
t17 . SetToolTip ( buttonRotate270 , "Drehen 270°" ) ;
ToolTip t18 = new ToolTip
{
AutoPopDelay = 5000 ,
InitialDelay = 1000 ,
ReshowDelay = 500
} ;
2022-08-15 16:34:55 +02:00
t18 . SetToolTip ( buttonRandOben , "Oben (Ctrl+Auf)" ) ;
2022-08-15 10:37:49 +02:00
ToolTip t19 = new ToolTip
{
AutoPopDelay = 5000 ,
InitialDelay = 1000 ,
ReshowDelay = 500
} ;
2022-08-15 16:34:55 +02:00
t19 . SetToolTip ( buttonRandUnten , "Unten (Ctrl+Ab)" ) ;
2022-08-15 10:37:49 +02:00
ToolTip t20 = new ToolTip
{
AutoPopDelay = 5000 ,
InitialDelay = 1000 ,
ReshowDelay = 500
} ;
2022-08-15 16:34:55 +02:00
t20 . SetToolTip ( buttonRandRechts , "Rechts (Ctrl+Rechts)" ) ;
2022-08-15 10:37:49 +02:00
ToolTip t21 = new ToolTip
{
AutoPopDelay = 5000 ,
InitialDelay = 1000 ,
ReshowDelay = 500
} ;
2022-08-15 16:34:55 +02:00
t21 . SetToolTip ( buttonRandLinks , "Links (Ctrl+Links)" ) ;
ToolTip t22 = new ToolTip
{
AutoPopDelay = 5000 ,
InitialDelay = 1000 ,
ReshowDelay = 500
} ;
t22 . SetToolTip ( buttonPreview , "Bildvorschau (P)" ) ;
ToolTip t23 = new ToolTip
{
AutoPopDelay = 5000 ,
InitialDelay = 1000 ,
ReshowDelay = 500
} ;
t23 . SetToolTip ( buttonHeart , "Unterstütze dieses Projekt" ) ;
ToolTip t24 = new ToolTip
{
AutoPopDelay = 5000 ,
InitialDelay = 1000 ,
ReshowDelay = 500
} ;
t24 . SetToolTip ( buttonChristmas , "Frohe Weihnachten!" ) ;
2019-03-22 23:53:20 +01:00
}
/// <summary>
/// Startpfad auf letzten Pfad legen, wenn Bilder vorhanden sind, sonst auf Bild-Bibliothek, wenn da auch keine sind, dann den Applikationspfad
/// </summary>
private void SetDefaultPath ( )
{
string tmpPath = Application . StartupPath ;
if ( string . IsNullOrEmpty ( startuppath ) )
{
if ( ! string . IsNullOrEmpty ( Properties . Settings . Default . lastPath ) & & Directory . Exists ( Properties . Settings . Default . lastPath ) )
{
tmpPath = Properties . Settings . Default . lastPath ;
}
int picsHere = 0 ;
foreach ( string type in fileTypes )
{
var list = Directory . GetFiles ( tmpPath , "*." + type ) ;
if ( list . Length > 0 )
{
picsHere + = list . Length ;
}
}
string myPics = Environment . GetFolderPath ( Environment . SpecialFolder . MyPictures ) ;
if ( Directory . Exists ( myPics ) & & picsHere = = 0 )
{
tmpPath = myPics ;
}
}
else
{
tmpPath = startuppath ;
}
quellPath = tmpPath ;
labelQuellPath . Text = tmpPath ;
if ( ! string . IsNullOrEmpty ( Properties . Settings . Default . targetPath ) )
{
zielPath = Properties . Settings . Default . targetPath ;
labelZielPath . Text = Properties . Settings . Default . targetPath ;
}
}
/// <summary>
/// Wenn Subfolders vorhanden, Text ausblenden und für jeden Subfolder einen Button anlegen
/// </summary>
private void CheckSubfolders ( )
{
if ( ! threadIsRunning )
{
folderThread = new Thread ( new ThreadStart ( CheckSubfoldersThread ) )
{
IsBackground = true
} ;
folderThread . Start ( ) ;
}
}
private void CheckSubfoldersThread ( )
{
threadIsRunning = true ;
try
{
var folders = Directory . GetDirectories ( zielPath , "*" , System . IO . SearchOption . TopDirectoryOnly ) ;
DirectoryInfo di = new DirectoryInfo ( zielPath ) ;
int dircount = di . GetDirectories ( ) . Length ;
Invoke ( new dlgRefreshButtons ( RefreshButtons ) , dircount , folders ) ;
}
catch ( Exception )
{
}
finally
{
threadIsRunning = false ;
}
}
/// <summary>
/// Erstellt für jeden Subfolder einen Button zum verschieben
/// </summary>
/// <param name="dircount"></param>
/// <param name="folders"></param>
private void RefreshButtons ( int dircount , string [ ] folders )
{
RemoveButtons ( buttons ) ;
buttons . Clear ( ) ;
if ( dircount > 0 )
{
labelNoTargets . Visible = false ;
AddButtons ( folders ) ;
}
else
{
labelNoTargets . Visible = true ;
}
}
public delegate void dlgRefreshButtons ( int dircount , string [ ] folders ) ;
/// <summary>
/// Fügt Buttons aus array hinzu
/// </summary>
/// <param name="folders"></param>
private void AddButtons ( string [ ] folders , int top = 9 , int left = 9 )
{
Array . Sort ( folders ) ;
foreach ( string folder in folders )
{
2019-08-15 20:31:28 +02:00
if ( Path . GetFileNameWithoutExtension ( folder ) . ToString ( ) ! = "$RECYCLE" & & Path . GetFileNameWithoutExtension ( folder ) . ToString ( ) ! = "System Volume Information" & & Path . GetFileNameWithoutExtension ( folder ) . ToString ( ) ! = "ImageSorter" & & Path . GetFileNameWithoutExtension ( folder ) . ToString ( ) ! = "Image Sorter" & & Path . GetFileNameWithoutExtension ( folder ) . ToString ( ) ! = "AssocIcons" )
2019-03-22 23:53:20 +01:00
{
Button button = new Button
{
Left = left ,
Top = top
} ;
int count = 0 ;
button . Text = Path . GetFileNameWithoutExtension ( folder ) . ToString ( ) + " (" + count + ")" ;
button . Size = new Size ( 225 , 30 ) ;
button . Click + = new EventHandler ( MovePicture ) ;
2019-08-07 15:55:48 +02:00
System . Timers . Timer tx = new System . Timers . Timer ( 35 ) ;
tx . Elapsed + = new System . Timers . ElapsedEventHandler ( ( sender1 , e1 ) = > ButtonFade ( button , tx ) ) ;
button . Tag = tx ;
2019-03-22 23:53:20 +01:00
buttons . Add ( button ) ;
top + = button . Height + 2 ;
}
}
foreach ( Button button in this . buttons )
{
2019-08-15 20:31:28 +02:00
panelButtons . Controls . Add ( button ) ;
2019-03-22 23:53:20 +01:00
}
2022-08-13 19:45:21 +02:00
AsyncCountFilesInFolders ( ) ;
}
/// <summary>
/// Zählt die Files in den Folders asynchron und addiert anschließend die Zahl zum Button-Text hinzu
/// </summary>
/// <returns></returns>
private async Task AsyncCountFilesInFolders ( )
{
await Task . Run ( ( ) = >
{
foreach ( Control ctl in panelButtons . Controls )
{
if ( ctl is Button )
{
try
{
string [ ] folderButton = ctl . Text . Split ( '(' ) ;
int count = int . Parse ( folderButton [ 1 ] . Substring ( 0 , folderButton [ 1 ] . Length - 1 ) ) ; //sollte das nicht später gezählt werden??
string targetPath = Path . Combine ( zielPath , folderButton [ 0 ] . Substring ( 0 , folderButton [ 0 ] . Length - 1 ) ) ;
2022-08-16 14:36:58 +02:00
foreach ( string file in Directory . EnumerateFiles ( targetPath , "*.*" , System . IO . SearchOption . AllDirectories ) . Where ( s = > fileTypes . Any ( ext = > ext = = Path . GetExtension ( s ) ) ) )
2022-08-13 19:45:21 +02:00
{
2022-08-16 14:36:58 +02:00
count + + ;
2022-08-13 19:45:21 +02:00
}
if ( ctl . InvokeRequired )
ctl . Invoke ( new Action ( ( ) = > ctl . Text = folderButton [ 0 ] + "(" + count + ")" ) ) ;
else
ctl . Text = folderButton [ 0 ] + "(" + count + ")" ;
}
catch ( Exception )
{
}
}
}
} ) ;
2019-03-22 23:53:20 +01:00
}
/// <summary>
/// Entfernt alle Buttons aus Liste
/// </summary>
/// <param name="list"></param>
private void RemoveButtons ( List < Button > list )
{
foreach ( Button button in list )
{
2019-08-15 20:31:28 +02:00
panelButtons . Controls . Remove ( button ) ;
2019-03-22 23:53:20 +01:00
}
}
/// <summary>
/// Einstellungen ändern
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonSettings_Click ( object sender , EventArgs e )
{
Settings s = new Settings ( ) ;
s . ShowDialog ( ) ;
zielPath = Properties . Settings . Default . targetPath ;
2019-04-05 10:52:47 +02:00
labelZielPath . Text = zielPath ;
2019-03-22 23:53:20 +01:00
imageIndex = 0 ;
2019-04-05 10:52:47 +02:00
if ( Properties . Settings . Default . fileAssociation )
{
ExtractAssocIcons ( ) ;
2019-04-05 21:16:57 +02:00
FileAssociation . Add ( "Image_Sorter_JPG" , ".jpg" , Application . ExecutablePath , "JPG Bild" , $@"{Application.StartupPath}\AssocIcons\jpg.ico" ) ;
FileAssociation . Add ( "Image_Sorter_PNG" , ".png" , Application . ExecutablePath , "PNG Bild" , $@"{Application.StartupPath}\AssocIcons\png.ico" ) ;
FileAssociation . Add ( "Image_Sorter_GIF" , ".gif" , Application . ExecutablePath , "GIF Bild" , $@"{Application.StartupPath}\AssocIcons\gif.ico" ) ;
FileAssociation . Add ( "Image_Sorter_JPEG" , ".jpeg" , Application . ExecutablePath , "JPEG Bild" , $@"{Application.StartupPath}\AssocIcons\jpeg.ico" ) ;
FileAssociation . Add ( "Image_Sorter_BMP" , ".bmp" , Application . ExecutablePath , "BMP Bild" , $@"{Application.StartupPath}\AssocIcons\bmp.ico" ) ;
FileAssociation . Add ( "Image_Sorter_TIF" , ".tif" , Application . ExecutablePath , "TIF Bild" , $@"{Application.StartupPath}\AssocIcons\tif.ico" ) ;
FileAssociation . Add ( "Image_Sorter_TIFF" , ".tiff" , Application . ExecutablePath , "TIFF Bild" , $@"{Application.StartupPath}\AssocIcons\tiff.ico" ) ;
2022-08-14 15:52:11 +02:00
FileAssociation . Add ( "Image_Sorter_WEBP" , ".webp" , Application . ExecutablePath , "WEBP Bild" , $@"{Application.StartupPath}\AssocIcons\webp.ico" ) ;
2023-03-27 19:10:29 +02:00
FileAssociation . Add ( "Image_Sorter_HEIC" , ".heic" , Application . ExecutablePath , "HEIC Bild" , $@"{Application.StartupPath}\AssocIcons\heic.ico" ) ;
2019-04-05 10:52:47 +02:00
}
else
{
2019-08-07 15:55:48 +02:00
if ( Directory . Exists ( $@"{Application.StartupPath}\AssocIcons" ) )
{
Directory . Delete ( $@"{Application.StartupPath}\AssocIcons" , true ) ;
2019-12-27 14:59:29 +01:00
FileAssociation . Remove ( "Image_Sorter_JPG" ) ;
FileAssociation . Remove ( "Image_Sorter_PNG" ) ;
FileAssociation . Remove ( "Image_Sorter_GIF" ) ;
FileAssociation . Remove ( "Image_Sorter_JPEG" ) ;
FileAssociation . Remove ( "Image_Sorter_BMP" ) ;
FileAssociation . Remove ( "Image_Sorter_TIF" ) ;
FileAssociation . Remove ( "Image_Sorter_TIFF" ) ;
2022-08-14 15:52:11 +02:00
FileAssociation . Remove ( "Image_Sorter_WEBP" ) ;
2023-03-27 19:10:29 +02:00
FileAssociation . Remove ( "Image_Sorter_HEIC" ) ;
2019-08-07 15:55:48 +02:00
}
2019-04-05 10:52:47 +02:00
}
2019-03-22 23:53:20 +01:00
CheckSubfolders ( ) ;
SearchImages ( ) ;
CountPicsInPath ( ) ;
ResetUndo ( ) ;
2022-08-13 18:06:29 +02:00
panelImageBackground . BackColor = Properties . Settings . Default . lightBackgroundColour ;
pictureBoxImage . BackColor = Properties . Settings . Default . lightBackgroundColour ;
2019-03-22 23:53:20 +01:00
}
/// <summary>
/// Fügt alle Bilder des aktuellen Verzeichnisses der Liste hinzu
/// </summary>
private void SearchImages ( )
{
images . Clear ( ) ;
2022-08-16 14:36:58 +02:00
2023-03-19 15:00:17 +01:00
foreach ( string image in Directory . EnumerateFiles ( quellPath , "*.*" , System . IO . SearchOption . AllDirectories ) . Where ( s = > fileTypes . Any ( ext = > ext = = Path . GetExtension ( s ) . ToLower ( ) ) ) )
2019-03-22 23:53:20 +01:00
{
2022-08-16 14:36:58 +02:00
images . Add ( image ) ;
2019-03-22 23:53:20 +01:00
}
}
/// <summary>
/// Gibt den Index des Bildes in der Bilderliste zurück
/// </summary>
/// <param name="image"></param>
/// <returns></returns>
private int GetImageIndex ( string image )
{
2020-03-22 10:18:02 +01:00
int index = images . IndexOf ( image ) ;
2019-03-22 23:53:20 +01:00
return index ;
}
/// <summary>
/// Zählt die Bilddateien im Pfad
/// </summary>
private void CountPicsInPath ( )
{
Thread thread = new Thread ( new ThreadStart ( CountPicsInPathThread ) )
{
IsBackground = true
} ;
thread . Start ( ) ;
}
private void CountPicsInPathThread ( )
{
Monitor . Enter ( locker ) ;
try
{
int counted = 0 ;
counted = images . Count ( ) ;
Invoke ( new dlgRefreshCounters ( RefreshCounters ) , counted ) ;
}
catch ( Exception )
{
}
finally
{
Monitor . Exit ( locker ) ;
}
}
public delegate void dlgRefreshCounters ( int counted ) ;
/// <summary>
/// aktualisiert die Zähler zur Bilderaktionsstatistik
/// </summary>
/// <param name="total"></param>
private void RefreshCounters ( int total )
{
if ( total = = 0 )
{
labelCounter . Text = "keine Bilder vorhanden" ;
SetButtonsEnabled ( false ) ;
}
else if ( total = = 1 )
{
labelCounter . Text = "1 Bild gesamt" ;
SetButtonsEnabled ( true ) ;
}
else
{
labelCounter . Text = total . ToString ( ) + " Bilder gesamt" ;
SetButtonsEnabled ( true ) ;
}
if ( moved = = 0 )
{
labelCounter . Text + = Environment . NewLine + "keines verschoben" ;
}
else
{
labelCounter . Text + = Environment . NewLine + this . moved . ToString ( ) + " bereits verschoben" ;
}
}
/// <summary>
/// Subdirectory-Ordner Buttons aktivieren/dekativieren
/// </summary>
/// <param name="enabled"></param>
private void SetButtonsEnabled ( bool enabled )
{
foreach ( Button b in buttons )
{
b . Enabled = enabled ;
}
buttonDeleteImage . Enabled = enabled ;
buttonMirrorHorizontal . Enabled = enabled ;
buttonMirrorVertikal . Enabled = enabled ;
buttonRotate180 . Enabled = enabled ;
buttonRotate270 . Enabled = enabled ;
buttonRotate90 . Enabled = enabled ;
2019-04-02 17:36:31 +02:00
comboBoxZoom . Enabled = enabled ;
2019-07-28 10:22:02 +02:00
buttonJumpForward . Enabled = enabled ;
2019-03-22 23:53:20 +01:00
labelNoImages . Visible = ! enabled ;
2021-04-02 21:16:50 +02:00
buttonDateirenamer . Enabled = enabled ;
2019-03-22 23:53:20 +01:00
}
/// <summary>
/// Lädt das Bild in die Picturebox
/// </summary>
/// <param name="index"></param>
private void LoadPicture ( int index )
{
if ( images . Count ( ) > 0 )
{
imageIndex = index ;
if ( imageIndex > = images . Count ( ) | | imageIndex < 0 )
{
imageIndex = 0 ;
}
2019-08-15 20:31:28 +02:00
pictureBoxImage . ImageLocation = CropImageBorders ( images . ElementAt ( imageIndex ) ) ;
2022-08-16 14:36:58 +02:00
string resolutionTitle = "" ;
//if(pictureBoxImage.Image != null)
//{
// resolutionTitle = " (" + pictureBoxImage.Image.Width + "px x " + pictureBoxImage.Image.Height + "px)";
//}
Text = defaultWindowName + " - " + Path . GetFileName ( pictureBoxImage . ImageLocation ) + resolutionTitle ;
2019-03-22 23:53:20 +01:00
}
else
{
2019-08-15 20:31:28 +02:00
pictureBoxImage . Image = null ;
2020-01-19 08:40:43 +01:00
Text = defaultWindowName ;
2019-03-22 23:53:20 +01:00
}
}
/// <summary>
/// Entfernt gleichfarbige Rahmen automatisch von Bildern
/// </summary>
/// <param name="imagepath"></param>
private string CropImageBorders ( string imagepath )
{
try
{
Bitmap p = new Bitmap ( imagepath ) ;
Bitmap x = BorderCropper . CropUnwantedBackground ( p ) ;
p . Dispose ( ) ;
if ( x ! = null )
{
x . Save ( imagepath ) ;
Image myImg = CopyImage . GetCopyImage ( imagepath ) ;
ShowAutoBorderChopMessage ( myImg , imagepath ) ;
}
}
catch ( Exception )
{
}
return imagepath ;
}
/// <summary>
/// Löscht die Undo-History
/// </summary>
private void ResetUndo ( )
{
history . Clear ( ) ;
CheckUndo ( ) ;
}
/// <summary>
/// Prüft ob Undo möglich ist
/// </summary>
private void CheckUndo ( )
{
if ( history . Count ( ) > 0 )
{
buttonUndo . Enabled = true ;
}
else
{
buttonUndo . Enabled = false ;
}
}
/// <summary>
/// Verschiebt ein Bild in ein Unterverzeichnis
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MovePicture ( object sender , EventArgs e )
{
Button btn = ( Button ) sender ;
string [ ] folderButton = btn . Text . Split ( '(' ) ;
int count = int . Parse ( folderButton [ 1 ] . Substring ( 0 , folderButton [ 1 ] . Length - 1 ) ) + 1 ;
string targetPath = Path . Combine ( zielPath , folderButton [ 0 ] . Substring ( 0 , folderButton [ 0 ] . Length - 1 ) ) ;
try
{
2020-03-22 10:18:02 +01:00
string fullTargetPath = Path . Combine ( targetPath , CleanFileName ( Path . GetFileName ( pictureBoxImage . ImageLocation ) ) ) ;
2019-08-15 20:31:28 +02:00
Image myImg = CopyImage . GetCopyImage ( pictureBoxImage . ImageLocation ) ;
2019-03-22 23:53:20 +01:00
if ( File . Exists ( fullTargetPath ) )
{
2020-03-22 10:18:02 +01:00
using ( var form = new Vergleicher ( "Das zu verschiebende Bild \"" + CleanFileName ( Path . GetFileName ( pictureBoxImage . ImageLocation ) ) + "\"" + "existiert im Zielverzeichnis \"" + btn . Text + "\" bereits." + Environment . NewLine + Environment . NewLine + "Soll eine Kopie angelegt werden? Nein überschreibt die Datei, Abbrechen bricht den Vorgang ab." , pictureBoxImage . ImageLocation , fullTargetPath ) )
2019-03-22 23:53:20 +01:00
{
var result = form . ShowDialog ( ) ;
if ( result = = DialogResult . Yes )
{
2020-03-22 10:18:02 +01:00
fullTargetPath = Path . Combine ( targetPath , CleanFileName ( Path . GetFileNameWithoutExtension ( pictureBoxImage . ImageLocation ) ) + Randomize . NumbersAndDigits ( 5 , "_" ) + Path . GetExtension ( pictureBoxImage . ImageLocation ) ) ;
2019-03-22 23:53:20 +01:00
}
else if ( result = = DialogResult . No )
{
2019-08-15 20:31:28 +02:00
File . Copy ( pictureBoxImage . ImageLocation , fullTargetPath , true ) ;
File . Delete ( pictureBoxImage . ImageLocation ) ;
images . Remove ( pictureBoxImage . ImageLocation ) ;
2019-03-22 23:53:20 +01:00
history . Add ( fullTargetPath ) ;
moved + + ;
ShowMovedMessage ( myImg , fullTargetPath , btn . Text ) ;
CheckSubfolders ( ) ;
CountPicsInPath ( ) ;
LoadPicture ( imageIndex ) ;
CheckUndo ( ) ;
return ;
}
2023-08-13 13:03:55 +02:00
else if ( result = = DialogResult . Cancel )
{
ImageDelete ( null , null ) ;
return ;
}
2019-03-22 23:53:20 +01:00
else
{
return ;
}
}
}
2019-08-15 20:31:28 +02:00
File . Move ( pictureBoxImage . ImageLocation , fullTargetPath ) ;
images . Remove ( pictureBoxImage . ImageLocation ) ;
2019-03-22 23:53:20 +01:00
history . Add ( fullTargetPath ) ;
moved + + ;
ShowMovedMessage ( myImg , fullTargetPath , btn . Text ) ;
}
catch ( IOException ex )
{
MessageBox . Show ( ex . ToString ( ) ) ;
}
btn . Text = folderButton [ 0 ] + "(" + count + ")" ;
CountPicsInPath ( ) ;
LoadPicture ( imageIndex ) ;
CheckUndo ( ) ;
2023-08-11 10:30:48 +02:00
ShowPreviewImages ( false , true ) ;
2019-08-07 15:55:48 +02:00
2022-08-13 19:45:21 +02:00
if ( Properties . Settings . Default . fading )
2019-08-07 15:55:48 +02:00
{
btn . BackColor = Color . LightSalmon ;
btn . ForeColor = Color . MediumSeaGreen ;
btn . Font = new Font ( btn . Font , FontStyle . Bold ) ;
System . Timers . Timer t = new System . Timers . Timer ( 700 ) ;
t . Elapsed + = new System . Timers . ElapsedEventHandler ( ( sender1 , e1 ) = > ButtonBlink ( sender , e , btn , t ) ) ;
t . Start ( ) ;
}
2019-07-29 17:32:26 +02:00
}
2021-04-02 22:34:04 +02:00
/// <summary>
/// Removes the marks from cropping and cutting in filename
/// </summary>
/// <param name="filename"></param>
/// <returns></returns>
2020-03-22 10:18:02 +01:00
private string CleanFileName ( string filename )
{
string fn = filename ;
fn = fn . Replace ( "_crp" , "" ) ;
fn = fn . Replace ( "_cut" , "" ) ;
return fn ;
}
2019-07-29 17:32:26 +02:00
/// <summary>
/// Blinkender Button nach erfolgreichem Verschieben
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <param name="btn"></param>
2019-08-07 15:55:48 +02:00
private void ButtonBlink ( object sender , EventArgs e , Button btn , System . Timers . Timer t )
2019-07-29 17:32:26 +02:00
{
btn . BeginInvoke ( new MethodInvoker ( ( ) = >
{
2019-08-07 15:55:48 +02:00
System . Timers . Timer tx = btn . Tag as System . Timers . Timer ;
if ( tx . Enabled )
{
tx . Stop ( ) ;
btn . BackColor = Color . LightSalmon ;
}
2019-07-29 17:32:26 +02:00
btn . ForeColor = SystemColors . ControlText ;
btn . Font = new Font ( btn . Font , FontStyle . Regular ) ;
2019-08-07 15:55:48 +02:00
tx . Start ( ) ;
2019-07-29 17:32:26 +02:00
} ) ) ;
t . Stop ( ) ;
2019-03-22 23:53:20 +01:00
}
2019-08-07 15:55:48 +02:00
/// <summary>
/// Hintergrundfarbe des Buttons langsam nach Transparent blenden
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <param name="btn"></param>
private void ButtonFade ( Button btn , System . Timers . Timer tx )
{
btn . BeginInvoke ( new MethodInvoker ( ( ) = >
{
int speed = Properties . Settings . Default . fadingSpeed * ( Properties . Settings . Default . fadingSpeed / 3 ) + 1 ;
int alpha = btn . BackColor . A ;
if ( alpha - speed > = 0 )
{
btn . BackColor = Color . FromArgb ( btn . BackColor . A - speed , btn . BackColor . R , btn . BackColor . G , btn . BackColor . B ) ;
}
else
{
btn . BackColor = Color . Transparent ;
tx . Stop ( ) ;
}
} ) ) ;
}
2019-03-22 23:53:20 +01:00
/// <summary>
/// Macht die letzte Aktion rückgängig
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonUndo_Click ( object sender , EventArgs e )
{
string targetPath = Path . Combine ( this . quellPath , Path . GetFileName ( history . ElementAt ( history . Count ( ) - 1 ) ) ) ;
if ( Path . GetFullPath ( history . ElementAt ( history . Count ( ) - 1 ) ) . StartsWith ( "C:\\img-tmp" ) )
{
2019-08-15 20:31:28 +02:00
targetPath = pictureBoxImage . ImageLocation ;
2019-03-22 23:53:20 +01:00
}
try
{
Image myImg = CopyImage . GetCopyImage ( history . ElementAt ( history . Count ( ) - 1 ) ) ;
File . Copy ( history . ElementAt ( history . Count ( ) - 1 ) , targetPath , true ) ;
File . Delete ( history . ElementAt ( history . Count ( ) - 1 ) ) ;
history . Remove ( history . ElementAt ( history . Count ( ) - 1 ) ) ;
images . Insert ( imageIndex , targetPath ) ;
moved - - ;
ShowUndoMessage ( myImg , targetPath ) ;
}
catch ( IOException ex )
{
MessageBox . Show ( ex . ToString ( ) ) ;
}
CheckSubfolders ( ) ;
CountPicsInPath ( ) ;
LoadPicture ( imageIndex ) ;
CheckUndo ( ) ;
2023-08-11 10:30:48 +02:00
ShowPreviewImages ( true ) ;
2019-03-22 23:53:20 +01:00
}
/// <summary>
/// Dreht das Bild und überschreibt es
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ImageRotate ( object sender , EventArgs e )
{
Button btn = ( Button ) sender ;
string rotateString = btn . Tag . ToString ( ) ;
int rotation = int . Parse ( rotateString ) ;
Image subject = Image . FromFile ( images . ElementAt ( imageIndex ) ) ;
if ( rotation = = 90 )
{
subject . RotateFlip ( RotateFlipType . Rotate90FlipNone ) ;
}
else if ( rotation = = 180 )
{
subject . RotateFlip ( RotateFlipType . Rotate180FlipNone ) ;
}
else
{
subject . RotateFlip ( RotateFlipType . Rotate270FlipNone ) ;
}
string ext = Path . GetExtension ( images . ElementAt ( imageIndex ) ) ;
if ( ext = = ".png" )
{
subject . Save ( images . ElementAt ( imageIndex ) , ImageFormat . Png ) ;
}
else if ( ext = = ".gif" )
{
subject . Save ( images . ElementAt ( imageIndex ) , ImageFormat . Gif ) ;
}
else
{
subject . Save ( images . ElementAt ( imageIndex ) , ImageFormat . Jpeg ) ;
}
LoadPicture ( imageIndex ) ;
2019-08-15 20:31:28 +02:00
groupBoxTransformation . Visible = false ;
2019-03-22 23:53:20 +01:00
}
/// <summary>
/// Spiegelt ein Bild und überschreibt es
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ImageMirror ( object sender , EventArgs e )
{
Button btn = ( Button ) sender ;
string mirrorString = btn . Tag . ToString ( ) ;
Image subject = Image . FromFile ( images . ElementAt ( imageIndex ) ) ;
if ( mirrorString = = "x" )
{
subject . RotateFlip ( RotateFlipType . RotateNoneFlipX ) ;
}
else
{
subject . RotateFlip ( RotateFlipType . RotateNoneFlipY ) ;
}
string ext = Path . GetExtension ( images . ElementAt ( imageIndex ) ) ;
if ( ext = = ".png" )
{
subject . Save ( images . ElementAt ( imageIndex ) , ImageFormat . Png ) ;
}
else if ( ext = = ".gif" )
{
subject . Save ( images . ElementAt ( imageIndex ) , ImageFormat . Gif ) ;
}
else
{
subject . Save ( images . ElementAt ( imageIndex ) , ImageFormat . Jpeg ) ;
}
LoadPicture ( imageIndex ) ;
2019-08-15 20:31:28 +02:00
groupBoxTransformation . Visible = false ;
2019-03-22 23:53:20 +01:00
}
/// <summary>
/// Verschiebt ein Bild in den Papierkorb
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ImageDelete ( object sender , EventArgs e )
{
2019-08-15 20:31:28 +02:00
Image myImg = CopyImage . GetCopyImage ( pictureBoxImage . ImageLocation ) ;
string pfad = Path . GetFileName ( pictureBoxImage . ImageLocation ) ;
FileSystem . DeleteFile ( pictureBoxImage . ImageLocation , UIOption . OnlyErrorDialogs , RecycleOption . SendToRecycleBin , UICancelOption . DoNothing ) ;
images . Remove ( pictureBoxImage . ImageLocation ) ;
2019-03-22 23:53:20 +01:00
CheckSubfolders ( ) ;
CountPicsInPath ( ) ;
LoadPicture ( imageIndex ) ;
ShowDeletedMessage ( myImg , pfad ) ;
2023-08-11 10:30:48 +02:00
ShowPreviewImages ( false , true ) ;
2019-03-22 23:53:20 +01:00
}
/// <summary>
2019-04-02 17:36:31 +02:00
/// Zoom-Optionen
2019-03-22 23:53:20 +01:00
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
2019-04-02 17:36:31 +02:00
private void Zoom ( )
2019-03-22 23:53:20 +01:00
{
2019-04-02 17:36:31 +02:00
string zoom = comboBoxZoom . SelectedItem . ToString ( ) ;
2019-03-22 23:53:20 +01:00
2019-04-02 17:36:31 +02:00
if ( zoom = = "Original" )
2019-03-22 23:53:20 +01:00
{
2019-08-15 20:31:28 +02:00
pictureBoxImage . SizeMode = PictureBoxSizeMode . Zoom ;
pictureBoxImage . Size = new Size ( pictureBoxImage . Image . Width , pictureBoxImage . Image . Height ) ;
if ( pictureBoxImage . Image . Width > panelImageBackground . Width ) { pictureBoxImage . Left = ( panelImageBackground . Width / 2 ) - ( pictureBoxImage . Width / 2 ) ; } else { pictureBoxImage . Left = ( panelImageBackground . Width / 2 ) - ( pictureBoxImage . Image . Width / 2 ) ; }
if ( pictureBoxImage . Image . Height > panelImageBackground . Height ) { pictureBoxImage . Top = ( panelImageBackground . Height / 2 ) - ( pictureBoxImage . Height / 2 ) ; } else { pictureBoxImage . Top = ( panelImageBackground . Height / 2 ) - ( pictureBoxImage . Image . Height / 2 ) ; }
2019-03-22 23:53:20 +01:00
moveable = true ;
}
2019-04-02 17:36:31 +02:00
else if ( zoom = = "Vollbild" )
2019-03-22 23:53:20 +01:00
{
2019-08-15 20:31:28 +02:00
pictureBoxImage . SizeMode = PictureBoxSizeMode . Zoom ;
pictureBoxImage . Size = new Size ( panelImageBackground . Width , panelImageBackground . Height ) ;
pictureBoxImage . Top = 0 ;
pictureBoxImage . Left = 0 ;
2019-03-22 23:53:20 +01:00
moveable = false ;
}
2019-04-02 17:36:31 +02:00
else if ( zoom = = "Auto" )
{
2019-08-15 20:31:28 +02:00
pictureBoxImage . SizeMode = PictureBoxSizeMode . Zoom ;
if ( pictureBoxImage . Image . Width > panelImageBackground . Width | | pictureBoxImage . Image . Height > panelImageBackground . Height )
2019-04-02 17:36:31 +02:00
{
2019-08-15 20:31:28 +02:00
pictureBoxImage . Size = new Size ( panelImageBackground . Width , panelImageBackground . Height ) ;
pictureBoxImage . Top = 0 ;
pictureBoxImage . Left = 0 ;
2019-04-02 17:36:31 +02:00
moveable = false ;
}
else
{
2019-08-15 20:31:28 +02:00
pictureBoxImage . Size = new Size ( pictureBoxImage . Image . Width , pictureBoxImage . Image . Height ) ;
if ( pictureBoxImage . Image . Width > panelImageBackground . Width ) { pictureBoxImage . Left = ( panelImageBackground . Width / 2 ) - ( pictureBoxImage . Width / 2 ) ; } else { pictureBoxImage . Left = ( panelImageBackground . Width / 2 ) - ( pictureBoxImage . Image . Width / 2 ) ; }
if ( pictureBoxImage . Image . Height > panelImageBackground . Height ) { pictureBoxImage . Top = ( panelImageBackground . Height / 2 ) - ( pictureBoxImage . Height / 2 ) ; } else { pictureBoxImage . Top = ( panelImageBackground . Height / 2 ) - ( pictureBoxImage . Image . Height / 2 ) ; }
2019-04-02 17:36:31 +02:00
moveable = true ;
}
}
2019-03-22 23:53:20 +01:00
else
{
return ;
}
2019-08-15 20:31:28 +02:00
xFaktor = pictureBoxImage . Width / ( double ) pictureBoxImage . Image . Width ;
yFaktor = pictureBoxImage . Height / ( double ) pictureBoxImage . Image . Height ;
labelZoom2 . Text = "x" + Math . Round ( yFaktor , 1 ) ;
2019-03-22 23:53:20 +01:00
}
/// <summary>
/// Mausklicks in picturebox verwalten
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PictureBox_MouseDown ( object sender , MouseEventArgs e )
{
if ( e . Button = = MouseButtons . Left )
{
if ( moveable )
{
moving = true ;
startLocation = e . Location ;
2019-08-15 20:31:28 +02:00
pictureBoxImage . Cursor = grabbingCursor ;
2019-03-22 23:53:20 +01:00
}
else
{
2019-08-15 20:31:28 +02:00
pictureBoxImage . Cursor = Cursors . No ;
2019-03-22 23:53:20 +01:00
}
}
if ( e . Button = = MouseButtons . Middle )
{
if ( moveable )
{
2019-08-15 20:31:28 +02:00
pictureBoxImage . Top = ( panelImageBackground . Height / 2 ) - ( pictureBoxImage . Height / 2 ) ;
pictureBoxImage . Left = ( panelImageBackground . Width / 2 ) - ( pictureBoxImage . Width / 2 ) ;
2019-03-22 23:53:20 +01:00
}
else
{
2019-08-15 20:31:28 +02:00
pictureBoxImage . Cursor = Cursors . No ;
2019-03-22 23:53:20 +01:00
}
}
}
/// <summary>
/// Mausklicks in picturebox verwalten
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PictureBox_MouseUp ( object sender , MouseEventArgs e )
{
if ( moveable & & moving )
{
moving = false ;
2019-08-15 20:31:28 +02:00
if ( pictureBoxImage . Top > 0 ) { pictureBoxImage . Top = 0 ; }
if ( pictureBoxImage . Top < - pictureBoxImage . Height + panelImageBackground . Height ) { pictureBoxImage . Top = - pictureBoxImage . Height + panelImageBackground . Height ; }
if ( pictureBoxImage . Left > 0 ) { pictureBoxImage . Left = 0 ; }
if ( pictureBoxImage . Left < - pictureBoxImage . Width + panelImageBackground . Width ) { pictureBoxImage . Left = - pictureBoxImage . Width + panelImageBackground . Width ; }
2019-03-22 23:53:20 +01:00
}
2019-08-15 20:31:28 +02:00
pictureBoxImage . Cursor = grabCursor ;
2019-03-22 23:53:20 +01:00
}
/// <summary>
/// Bildausschnitt verschieben
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PictureBox_MouseMove ( object sender , MouseEventArgs e )
{
if ( moving )
{
2019-08-15 20:31:28 +02:00
if ( pictureBoxImage . Top > 0 ) { pictureBoxImage . Top = 0 ; }
if ( pictureBoxImage . Top < - pictureBoxImage . Height + panelImageBackground . Height ) { pictureBoxImage . Top = - pictureBoxImage . Height + panelImageBackground . Height ; }
if ( pictureBoxImage . Left > 0 ) { pictureBoxImage . Left = 0 ; }
if ( pictureBoxImage . Left < - pictureBoxImage . Width + panelImageBackground . Width ) { pictureBoxImage . Left = - pictureBoxImage . Width + panelImageBackground . Width ; }
pictureBoxImage . Top + = e . Location . Y - startLocation . Y ;
pictureBoxImage . Left + = e . Location . X - startLocation . X ;
2019-03-22 23:53:20 +01:00
}
}
/// <summary>
/// Bild Zoom
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ZoomInOut ( object sender , MouseEventArgs e )
{
2019-08-15 20:31:28 +02:00
if ( e . Delta ! = 0 & & pictureBoxImage . Image ! = null )
2019-03-22 23:53:20 +01:00
{
2019-08-15 20:31:28 +02:00
double xstep = pictureBoxImage . Width * 0.01 ;
double ystep = pictureBoxImage . Height * 0.01 ;
2019-03-22 23:53:20 +01:00
if ( xstep < 1.0 ) { xstep = 1.0 ; }
if ( ystep < 1.0 ) { ystep = 1.0 ; }
2019-08-15 20:31:28 +02:00
int maxWidth = pictureBoxImage . Image . Width * 8 ;
int minWidth = pictureBoxImage . Image . Width / 8 ;
2019-03-22 23:53:20 +01:00
2019-08-15 20:31:28 +02:00
int newWidth = pictureBoxImage . Width - ( pictureBoxImage . Width / ( int ) xstep * ( e . Delta / 120 ) ) ;
int newHeight = pictureBoxImage . Height - ( pictureBoxImage . Height / ( int ) xstep * ( e . Delta / 120 ) ) ;
2019-03-22 23:53:20 +01:00
if ( newWidth < = maxWidth & & newWidth > = minWidth )
{
2019-08-15 20:31:28 +02:00
pictureBoxImage . Width = newWidth ;
pictureBoxImage . Height = newHeight ;
2019-03-22 23:53:20 +01:00
}
2019-08-15 20:31:28 +02:00
if ( pictureBoxImage . Width > panelImageBackground . Width | | pictureBoxImage . Height > panelImageBackground . Height )
2019-03-22 23:53:20 +01:00
{
moveable = true ;
2019-08-15 20:31:28 +02:00
if ( pictureBoxImage . Right < panelImageBackground . Width ) { pictureBoxImage . Left + = - pictureBoxImage . Right + panelImageBackground . Width ; }
if ( pictureBoxImage . Bottom < panelImageBackground . Height ) { pictureBoxImage . Top + = - pictureBoxImage . Bottom + panelImageBackground . Height ; }
2019-03-22 23:53:20 +01:00
}
else
{
moveable = false ;
2019-08-15 20:31:28 +02:00
pictureBoxImage . Top = ( panelImageBackground . Height / 2 ) - ( pictureBoxImage . Height / 2 ) ;
pictureBoxImage . Left = ( panelImageBackground . Width / 2 ) - ( pictureBoxImage . Width / 2 ) ;
2019-03-22 23:53:20 +01:00
}
2019-08-15 20:31:28 +02:00
xFaktor = pictureBoxImage . Width / ( double ) pictureBoxImage . Image . Width ;
yFaktor = pictureBoxImage . Height / ( double ) pictureBoxImage . Image . Height ;
labelZoom2 . Text = "x" + Math . Round ( yFaktor , 1 ) ;
2019-03-22 23:53:20 +01:00
}
}
/// <summary>
/// Focus auf Panel1 bei MouseEnter in Picturebox
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PictureBox_MouseEnter ( object sender , EventArgs e )
{
2019-08-15 20:31:28 +02:00
panelImageBackground . Focus ( ) ;
2019-03-22 23:53:20 +01:00
}
/// <summary>
/// Focus auf Buttons bei MouseLeave von Picturebox
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PictureBox_MouseLeave ( object sender , EventArgs e )
{
2019-08-15 20:31:28 +02:00
groupBoxInformationen . Focus ( ) ;
2019-03-22 23:53:20 +01:00
}
/// <summary>
/// Bild in picturebox vollständig geladen
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PictureBox_LoadCompleted ( object sender , AsyncCompletedEventArgs e )
{
2019-04-02 17:36:31 +02:00
Zoom ( ) ;
2019-03-22 23:53:20 +01:00
}
/// <summary>
/// Maus-Fokus auf Panel2 bei MouseEnter
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Panel2_MouseEnter ( object sender , EventArgs e )
{
2019-08-15 20:31:28 +02:00
panelButtons . Focus ( ) ;
2019-03-22 23:53:20 +01:00
}
/// <summary>
2019-12-26 20:59:23 +01:00
/// Öffnet im Explorer den Ordner des Bildes und legt den Fokus auf das aktuelle Bild, wenn es existiert
2019-03-22 23:53:20 +01:00
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ToolStripMenuItemOpenExplorer_Click ( object sender , EventArgs e )
{
2019-08-15 20:31:28 +02:00
if ( File . Exists ( pictureBoxImage . ImageLocation ) )
2019-03-22 23:53:20 +01:00
{
2019-08-15 20:31:28 +02:00
Process . Start ( "explorer.exe" , @"/select, " + pictureBoxImage . ImageLocation ) ;
2019-03-22 23:53:20 +01:00
}
2019-08-15 20:31:28 +02:00
else if ( Directory . Exists ( Path . GetDirectoryName ( pictureBoxImage . ImageLocation ) ) )
2019-03-22 23:53:20 +01:00
{
2019-08-15 20:31:28 +02:00
Process . Start ( "explorer.exe" , Path . GetDirectoryName ( pictureBoxImage . ImageLocation ) ) ;
2019-03-22 23:53:20 +01:00
}
}
/// <summary>
2019-12-26 20:59:23 +01:00
/// Zeigt Details (Eigenschaften) zum aktuellen Bild an
2019-03-22 23:53:20 +01:00
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ToolStripMenuItemImageDetails_Click ( object sender , EventArgs e )
{
2019-08-15 20:31:28 +02:00
using ( Image img = Image . FromFile ( pictureBoxImage . ImageLocation ) )
2019-03-22 23:53:20 +01:00
{
2019-08-15 20:31:28 +02:00
FileInfo info = new FileInfo ( pictureBoxImage . ImageLocation ) ;
2019-03-22 23:53:20 +01:00
ImageFormat format = img . RawFormat ;
MessageBox . Show ( "Dateiname: " + info . Name + Environment . NewLine +
"Pfad: " + info . DirectoryName + Environment . NewLine +
"Erstellt: " + info . CreationTime + Environment . NewLine +
"Geändert: " + info . LastWriteTime + Environment . NewLine +
"Bildformat: " + new ImageFormatConverter ( ) . ConvertToString ( format ) + Environment . NewLine +
"Abmessungen: " + img . Width + " x " + img . Height + Environment . NewLine +
"Breite: " + img . Width + " Px" + Environment . NewLine +
"Höhe: " + img . Height + " Px" + Environment . NewLine +
"Auflösung: " + Resolution . GetImageResolution ( img ) + Environment . NewLine +
"Größe: " + FileSize . GetFileSize ( info . Length ) + Environment . NewLine +
"Bittiefe: " + Image . GetPixelFormatSize ( img . PixelFormat ) + " bit" , "Bildeigenschaften" , MessageBoxButtons . OK ) ;
}
}
2019-12-26 20:59:23 +01:00
/// <summary>
/// Zeigt die EXIF-Daten vom aktuellen Bild an
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ToolStripMenuItemShowEXIF_Click ( object sender , EventArgs e )
{
using ( Image img = Image . FromFile ( pictureBoxImage . ImageLocation ) )
{
EXIF exif = new EXIF ( img . PropertyItems ) ;
2021-04-02 22:34:04 +02:00
exif . ShowDialog ( this ) ;
2019-12-26 20:59:23 +01:00
}
}
2019-03-22 23:53:20 +01:00
/// <summary>
/// Öffnet Paint zum Bearbeiten des Bildes
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ToolStripMenuItemEditImage_Click ( object sender , EventArgs e )
{
2019-08-15 20:31:28 +02:00
FileInfo info = new FileInfo ( pictureBoxImage . ImageLocation ) ;
2019-03-22 23:53:20 +01:00
ProcessStartInfo pi = new ProcessStartInfo
{
FileName = ( "mspaint.exe" ) ,
UseShellExecute = false ,
Arguments = "\"" + info . FullName + "\""
} ;
Process p = new Process
{
StartInfo = pi
} ;
p . Start ( ) ;
p . WaitForExit ( ) ;
LoadPicture ( imageIndex ) ;
}
/// <summary>
/// Öffnet das Cropping-Form um Bilder zuzuschneiden
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BildZuschneidenToolStripMenuItem_Click ( object sender , EventArgs e )
{
2019-08-15 20:31:28 +02:00
Cropper cropper = new Cropper ( pictureBoxImage . ImageLocation ) ;
2019-03-22 23:53:20 +01:00
DialogResult result = cropper . ShowDialog ( this ) ;
if ( result = = DialogResult . OK )
{
2019-08-15 20:31:28 +02:00
string del = pictureBoxImage . ImageLocation ;
2019-03-22 23:53:20 +01:00
images [ imageIndex ] = cropper . NewFileLocation ;
LoadPicture ( imageIndex ) ;
FileSystem . DeleteFile ( del , UIOption . OnlyErrorDialogs , RecycleOption . SendToRecycleBin , UICancelOption . DoNothing ) ;
}
}
/// <summary>
2019-12-26 20:59:23 +01:00
/// Größe, Position in Settings speichern vor dem Schließen
2019-03-22 23:53:20 +01:00
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Main_FormClosing ( object sender , FormClosingEventArgs e )
{
Properties . Settings . Default . lastPath = quellPath ;
Properties . Settings . Default . lastWidth = Width ;
Properties . Settings . Default . lastHeight = Height ;
Properties . Settings . Default . lastTop = Top ;
Properties . Settings . Default . lastLeft = Left ;
2019-08-15 20:31:28 +02:00
Properties . Settings . Default . showInfo = groupBoxInformationen . Visible ;
2022-08-13 19:45:21 +02:00
Properties . Settings . Default . fullScreen = WindowState = = FormWindowState . Maximized ;
2023-08-10 14:43:56 +02:00
Properties . Settings . Default . preview = panelPreview . Visible ;
2019-03-22 23:53:20 +01:00
Properties . Settings . Default . Save ( ) ;
}
/// <summary>
/// Anzeige eines Banners bei verschobenem Bild
/// </summary>
/// <param name="bildpfad"></param>
/// <param name="ordnername"></param>
private void ShowMovedMessage ( Image bild , string bildpfad , string ordnername )
{
banner . Enqueue ( "Bild \"" + Path . GetFileName ( bildpfad ) + "\" erfolgreich nach" , "\"" + ordnername + "\" verschoben." , bild , Properties . Resources . move ) ;
banner . ShowMessages ( ) ;
}
/// <summary>
/// Anzeige eines Banners bei gelöschtem Bild
/// </summary>
/// <param name="bild"></param>
/// <param name="bildname"></param>
private void ShowDeletedMessage ( Image bild , string bildname )
{
banner . Enqueue ( "Bild \"" + bildname + "\" erfolgreich gelöscht." , "" , bild , Properties . Resources . delete ) ;
banner . ShowMessages ( ) ;
}
/// <summary>
/// Anzeige eines Banners bei rückgängig gemachter Aktion
/// </summary>
/// <param name="bildpfad"></param>
private void ShowUndoMessage ( Image bild , string bildpfad )
{
banner . Enqueue ( "Bildaktion für \"" + Path . GetFileName ( bildpfad ) + "\" erfolgreich" , "rückgängig gemacht." , bild , Properties . Resources . undo ) ;
banner . ShowMessages ( ) ;
}
/// <summary>
/// Anzeige eines Banners bei automatischem zuschneiden der Ränder
/// </summary>
/// <param name="bildpfad"></param>
private void ShowAutoBorderChopMessage ( Image bild , string bildpfad )
{
banner . Enqueue ( "Die Ränder für \"" + Path . GetFileName ( bildpfad ) + "\" wurden" , "automatisch zugeschnitten." , bild , Properties . Resources . crop ) ;
banner . ShowMessages ( ) ;
}
2019-08-10 12:03:16 +02:00
/// <summary>
/// Anzeige eines Banners bei erstelltem Duplikat
/// </summary>
/// <param name="bild"></param>
/// <param name="bildpfad"></param>
private void ShowDuplicatedMessage ( Image bild , string bildpfad )
{
2019-08-15 20:31:28 +02:00
banner . Enqueue ( "Das Duplikat \"" + Path . GetFileName ( bildpfad ) + "\"" , "wurde erstellt." , bild , Properties . Resources . duplicate ) ;
2019-08-10 12:03:16 +02:00
banner . ShowMessages ( ) ;
}
2019-03-22 23:53:20 +01:00
/// <summary>
/// Bild wieder neu zentrieren und skalieren nach Größenänderung des Fensters
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
2020-01-12 09:37:11 +01:00
private void Main_Resize ( object sender , EventArgs e )
2019-03-22 23:53:20 +01:00
{
2020-01-12 09:37:11 +01:00
if ( WindowState ! = FormWindowState . Minimized )
{
lastState = WindowState ;
}
2019-03-22 23:53:20 +01:00
try
{
2019-04-02 17:36:31 +02:00
Zoom ( ) ;
2019-03-22 23:53:20 +01:00
}
catch ( Exception )
{
}
2023-08-10 08:31:09 +02:00
if ( panelPreview . Visible )
{
ShowPreviewImages ( ) ;
}
2019-03-22 23:53:20 +01:00
}
/// <summary>
/// Globale Tasten-Events
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Main_KeyDown ( object sender , KeyEventArgs e )
{
if ( e . KeyCode = = Keys . Delete )
{
buttonDeleteImage . PerformClick ( ) ;
e . Handled = true ;
}
2022-08-15 10:37:49 +02:00
if ( ! e . Control & & ( e . KeyCode = = Keys . Left | | e . KeyCode = = Keys . Down ) )
2019-03-22 23:53:20 +01:00
{
CountPicsInPath ( ) ;
LoadPicture ( imageIndex - 1 ) ;
CheckUndo ( ) ;
e . Handled = true ;
}
2022-08-15 10:37:49 +02:00
if ( ! e . Control & & ( e . KeyCode = = Keys . Right | | e . KeyCode = = Keys . Up ) )
2019-03-22 23:53:20 +01:00
{
CountPicsInPath ( ) ;
LoadPicture ( imageIndex + 1 ) ;
CheckUndo ( ) ;
e . Handled = true ;
}
if ( e . KeyCode = = Keys . F2 )
{
toolStripMenuItemCropImage . PerformClick ( ) ;
e . Handled = true ;
}
if ( e . KeyCode = = Keys . F3 )
{
toolStripMenuItemEditImage . PerformClick ( ) ;
e . Handled = true ;
}
if ( e . KeyCode = = Keys . F4 )
{
toolStripMenuItemOpenExplorer . PerformClick ( ) ;
e . Handled = true ;
}
if ( e . KeyCode = = Keys . F5 )
{
toolStripMenuItemImageDetails . PerformClick ( ) ;
e . Handled = true ;
}
2019-12-26 20:59:23 +01:00
if ( e . KeyCode = = Keys . F6 )
{
toolStripMenuItemShowEXIF . PerformClick ( ) ;
e . Handled = true ;
}
2021-04-02 21:16:50 +02:00
if ( e . KeyCode = = Keys . F10 )
{
buttonSettings . PerformClick ( ) ;
e . Handled = true ;
}
if ( e . KeyCode = = Keys . F12 )
{
buttonDateirenamer . PerformClick ( ) ;
e . Handled = true ;
}
2019-03-22 23:53:20 +01:00
if ( e . KeyCode = = Keys . Back )
{
buttonUndo . PerformClick ( ) ;
e . Handled = true ;
}
2020-10-29 17:12:05 +01:00
if ( e . KeyCode = = Keys . H )
{
buttonHintergrund . PerformClick ( ) ;
e . Handled = true ;
}
if ( e . KeyCode = = Keys . I )
{
buttonInfo . PerformClick ( ) ;
e . Handled = true ;
}
2022-08-15 10:37:49 +02:00
if ( e . KeyCode = = Keys . R )
{
buttonRander . PerformClick ( ) ;
e . Handled = true ;
}
if ( e . KeyCode = = Keys . D )
{
buttonDuplicate . PerformClick ( ) ;
e . Handled = true ;
}
if ( e . KeyCode = = Keys . T )
{
buttonTransformation . PerformClick ( ) ;
e . Handled = true ;
}
if ( e . KeyCode = = Keys . Q )
{
buttonQuellPfad . PerformClick ( ) ;
e . Handled = true ;
}
if ( e . KeyCode = = Keys . D1 )
{
if ( groupBoxRander . Visible )
{
trackBarRander . Value = 1 ;
TrackBarRander_Scroll ( sender , e ) ;
e . Handled = true ;
}
}
if ( e . KeyCode = = Keys . D2 )
{
if ( groupBoxRander . Visible )
{
trackBarRander . Value = 2 ;
TrackBarRander_Scroll ( sender , e ) ;
e . Handled = true ;
}
}
if ( e . KeyCode = = Keys . D3 )
{
if ( groupBoxRander . Visible )
{
trackBarRander . Value = 3 ;
TrackBarRander_Scroll ( sender , e ) ;
e . Handled = true ;
}
}
if ( e . KeyCode = = Keys . D4 )
{
if ( groupBoxRander . Visible )
{
trackBarRander . Value = 4 ;
TrackBarRander_Scroll ( sender , e ) ;
e . Handled = true ;
}
}
if ( e . KeyCode = = Keys . D5 )
{
if ( groupBoxRander . Visible )
{
trackBarRander . Value = 5 ;
TrackBarRander_Scroll ( sender , e ) ;
e . Handled = true ;
}
}
if ( e . KeyCode = = Keys . D6 )
{
if ( groupBoxRander . Visible )
{
trackBarRander . Value = 6 ;
TrackBarRander_Scroll ( sender , e ) ;
e . Handled = true ;
}
}
if ( e . KeyCode = = Keys . D7 )
{
if ( groupBoxRander . Visible )
{
trackBarRander . Value = 7 ;
TrackBarRander_Scroll ( sender , e ) ;
e . Handled = true ;
}
}
if ( e . KeyCode = = Keys . D8 )
{
if ( groupBoxRander . Visible )
{
trackBarRander . Value = 8 ;
TrackBarRander_Scroll ( sender , e ) ;
e . Handled = true ;
}
}
if ( e . KeyCode = = Keys . D9 )
{
if ( groupBoxRander . Visible )
{
trackBarRander . Value = 9 ;
TrackBarRander_Scroll ( sender , e ) ;
e . Handled = true ;
}
}
if ( e . KeyCode = = Keys . D0 )
{
if ( groupBoxRander . Visible )
{
trackBarRander . Value = 10 ;
TrackBarRander_Scroll ( sender , e ) ;
e . Handled = true ;
}
}
if ( e . Control & & e . KeyCode = = Keys . Left )
{
buttonRandLinks . PerformClick ( ) ;
e . Handled = true ;
}
if ( e . Control & & e . KeyCode = = Keys . Right )
{
buttonRandRechts . PerformClick ( ) ;
e . Handled = true ;
}
if ( e . Control & & e . KeyCode = = Keys . Up )
{
buttonRandOben . PerformClick ( ) ;
e . Handled = true ;
}
if ( e . Control & & e . KeyCode = = Keys . Down )
{
buttonRandUnten . PerformClick ( ) ;
e . Handled = true ;
}
2022-08-15 16:34:55 +02:00
if ( e . KeyCode = = Keys . P )
{
buttonPreview . PerformClick ( ) ;
e . Handled = true ;
}
2019-03-22 23:53:20 +01:00
}
/// <summary>
/// Quellpfad auswählen
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonQuellPfad_Click ( object sender , EventArgs e )
{
DialogResult result = folderBrowserDialog . ShowDialog ( ) ;
if ( result = = DialogResult . OK )
{
quellPath = folderBrowserDialog . SelectedPath ;
labelQuellPath . Text = quellPath ;
}
CheckSubfolders ( ) ;
SearchImages ( ) ;
CountPicsInPath ( ) ;
LoadPicture ( 0 ) ;
ResetUndo ( ) ;
2023-08-10 09:11:56 +02:00
ShowPreviewImages ( ) ;
2019-03-22 23:53:20 +01:00
}
2019-04-02 17:36:31 +02:00
/// <summary>
/// Zoom-Combobox geändert
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ComboBoxZoom_SelectedIndexChanged ( object sender , EventArgs e )
{
Properties . Settings . Default . zoom = comboBoxZoom . SelectedIndex ;
Properties . Settings . Default . Save ( ) ;
2019-08-15 20:31:28 +02:00
if ( pictureBoxImage . Image ! = null )
2019-04-02 17:36:31 +02:00
{
Zoom ( ) ;
}
}
2019-07-28 10:22:02 +02:00
/// <summary>
/// Zu vorherigem Bild springen
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonJumpBack_Click ( object sender , MouseEventArgs e )
{
CountPicsInPath ( ) ;
2019-08-07 15:55:48 +02:00
LoadPicture ( imageIndex - 1 ) ;
2019-07-28 10:22:02 +02:00
CheckUndo ( ) ;
2023-08-11 10:30:48 +02:00
ShowPreviewImages ( true ) ;
2019-07-28 10:22:02 +02:00
}
/// <summary>
/// Zu nächstem Bild springen
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonJumpForward_Click ( object sender , MouseEventArgs e )
{
CountPicsInPath ( ) ;
LoadPicture ( imageIndex + 1 ) ;
CheckUndo ( ) ;
2023-08-11 10:30:48 +02:00
ShowPreviewImages ( false , true ) ;
2019-07-28 10:22:02 +02:00
}
/// <summary>
/// Informationen ein-/ausblenden
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonInfo_Click ( object sender , EventArgs e )
{
2019-08-15 20:31:28 +02:00
if ( groupBoxInformationen . Visible )
2019-07-28 10:22:02 +02:00
{
//ausblenden
2019-08-15 20:31:28 +02:00
groupBoxInformationen . Visible = false ;
groupBoxZiele . Location = new Point ( groupBoxZiele . Location . X , 12 ) ;
2022-08-13 19:45:21 +02:00
groupBoxZiele . Height + = 87 ;
2019-07-28 10:22:02 +02:00
}
else
{
//einblenden
2019-08-15 20:31:28 +02:00
groupBoxInformationen . Visible = true ;
groupBoxZiele . Location = new Point ( groupBoxZiele . Location . X , 99 ) ;
2022-08-13 19:45:21 +02:00
groupBoxZiele . Height - = 87 ;
2019-07-28 10:22:02 +02:00
}
}
2019-08-07 15:55:48 +02:00
2019-08-10 12:03:16 +02:00
/// <summary>
2019-08-15 20:31:28 +02:00
/// Duplikat von aktuellem Bild erzeugen
2019-08-10 12:03:16 +02:00
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonDuplicate_Click ( object sender , EventArgs e )
{
//aktuelles bild kopieren
2019-12-26 20:59:23 +01:00
string targetPath = Path . Combine ( Path . GetDirectoryName ( pictureBoxImage . ImageLocation ) , Path . GetFileNameWithoutExtension ( pictureBoxImage . ImageLocation ) + Randomize . NumbersAndDigits ( 5 , "_" ) + Path . GetExtension ( pictureBoxImage . ImageLocation ) ) ;
2019-08-15 20:31:28 +02:00
File . Copy ( pictureBoxImage . ImageLocation , targetPath , true ) ;
2019-08-10 12:03:16 +02:00
//duplikat als nächstes bild in liste aufnehmen
images . Insert ( imageIndex + 1 , targetPath ) ;
CountPicsInPath ( ) ;
//duplikat-message anzeigen
Image myImg = CopyImage . GetCopyImage ( targetPath ) ;
ShowDuplicatedMessage ( myImg , targetPath ) ;
2023-08-10 09:16:38 +02:00
2023-08-11 10:30:48 +02:00
ShowPreviewImages ( true ) ;
2019-08-10 12:03:16 +02:00
}
2019-08-15 20:31:28 +02:00
/// <summary>
/// Untermenü für Transformation ein-/ausblenden
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonTransformation_Click ( object sender , EventArgs e )
{
groupBoxTransformation . Visible = ! groupBoxTransformation . Visible ;
}
/// <summary>
/// Hintergrund hell/dunkel schalten
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonHintergrund_Click ( object sender , EventArgs e )
{
2022-08-13 18:06:29 +02:00
if ( panelImageBackground . BackColor = = Properties . Settings . Default . darkBackgroundColour )
2019-08-15 20:31:28 +02:00
{
2022-08-13 18:06:29 +02:00
panelImageBackground . BackColor = Properties . Settings . Default . lightBackgroundColour ;
pictureBoxImage . BackColor = Properties . Settings . Default . lightBackgroundColour ;
2019-08-15 20:31:28 +02:00
}
else
{
2022-08-13 18:06:29 +02:00
panelImageBackground . BackColor = Properties . Settings . Default . darkBackgroundColour ;
pictureBoxImage . BackColor = Properties . Settings . Default . darkBackgroundColour ;
2019-08-15 20:31:28 +02:00
}
}
/// <summary>
/// Ränder schneiden Untermenü ein-/ausblenden
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRander_Click ( object sender , EventArgs e )
{
groupBoxRander . Visible = ! groupBoxRander . Visible ;
}
/// <summary>
/// Rand von Bild schneiden
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void RandSchneiden_Click ( object sender , EventArgs e )
{
Button btn = ( Button ) sender ;
string cutString = btn . Tag . ToString ( ) ;
Image im = pictureBoxImage . Image ;
2019-08-16 21:27:34 +02:00
int move = trackBarRander . Value ;
2019-08-15 20:31:28 +02:00
int x = 0 , y = 0 , width = im . Width , height = im . Height ;
if ( cutString = = "links" )
{
x + = move ;
width - = move ;
}
else if ( cutString = = "rechts" )
{
width - = move ;
}
else if ( cutString = = "oben" )
{
y + = move ;
height - = move ;
}
else if ( cutString = = "unten" )
{
height - = move ;
}
2023-08-10 08:13:26 +02:00
else if ( cutString = = "linksrechts" )
{
x + = move ;
width - = move ;
width - = move ;
}
else if ( cutString = = "obenunten" )
{
y + = move ;
height - = move ;
height - = move ;
}
else if ( cutString = = "alle" )
{
x + = move ;
width - = move ;
width - = move ;
y + = move ;
height - = move ;
height - = move ;
}
2019-08-15 20:31:28 +02:00
Rectangle r = new Rectangle ( x , y , width , height ) ;
Image res = CropImage ( im , r ) ;
string folder = Path . GetDirectoryName ( pictureBoxImage . ImageLocation ) ;
string file = Path . GetFileNameWithoutExtension ( pictureBoxImage . ImageLocation ) + "_cut" ;
string ext = Path . GetExtension ( pictureBoxImage . ImageLocation ) ;
string newFileLocation = Path . Combine ( folder , file + ext ) ;
string del = pictureBoxImage . ImageLocation ;
if ( ext = = ".png" )
{
res . Save ( newFileLocation , ImageFormat . Png ) ;
}
else if ( ext = = ".gif" )
{
res . Save ( newFileLocation , ImageFormat . Gif ) ;
}
else
{
res . Save ( newFileLocation , ImageFormat . Jpeg ) ;
}
images [ imageIndex ] = newFileLocation ;
LoadPicture ( imageIndex ) ;
FileSystem . DeleteFile ( del , UIOption . OnlyErrorDialogs , RecycleOption . SendToRecycleBin , UICancelOption . DoNothing ) ;
groupBoxRander . Visible = false ;
}
/// <summary>
/// schneidet Bilder aus
/// </summary>
/// <param name="img"></param>
/// <param name="cropArea"></param>
/// <returns></returns>
private static Image CropImage ( Image img , Rectangle cropArea )
{
Bitmap bmpImage = new Bitmap ( img ) ;
Bitmap bmpCrop = bmpImage . Clone ( cropArea ,
bmpImage . PixelFormat ) ;
return ( Image ) ( bmpCrop ) ;
}
2019-08-16 21:27:34 +02:00
/// <summary>
/// Ändert das Pixel-Label auf den aktuellen Wert
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void TrackBarRander_Scroll ( object sender , EventArgs e )
{
labelRander . Text = trackBarRander . Value + " px." ;
}
2021-04-02 21:16:50 +02:00
/// <summary>
/// Öffnet den Dateirenamer
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonDateirenamer_Click ( object sender , EventArgs e )
{
2021-04-02 22:34:04 +02:00
Dateirenamer dr = new Dateirenamer ( quellPath ) ;
dr . ShowDialog ( this ) ;
2021-04-02 21:16:50 +02:00
}
2022-08-15 16:34:55 +02:00
/// <summary>
/// Preview-Sektion anzeigen/ausblenden
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonPreview_Click ( object sender , EventArgs e )
{
if ( panelPreview . Visible )
{
panelImageBackground . Height + = 100 ;
panelPreview . Visible = false ;
}
else
{
panelImageBackground . Height - = 100 ;
ShowPreviewImages ( ) ;
panelPreview . Visible = true ;
}
}
2023-08-10 09:11:56 +02:00
/// <summary>
/// Bildvorschau erzeugen und laden
/// </summary>
2023-08-11 10:30:48 +02:00
private void ShowPreviewImages ( bool left = false , bool right = false )
2022-08-15 16:34:55 +02:00
{
2023-08-10 09:15:19 +02:00
try
2023-08-10 09:11:56 +02:00
{
2023-08-10 09:15:19 +02:00
int panelWidthAvailable = panelPreview . Width - 11 ; //verfügbare breite abzüglich ränder links+rechts
int previewImageWidth = 80 ; //breite eines preview-bildes
int previewImageAbstand = 11 ; //abstand zwischen preview-bildern
int previewBildmitAbstand = previewImageWidth + previewImageAbstand ; //breite eines preview-bildes plus abstand
int previewNumber = panelWidthAvailable / previewBildmitAbstand ; //anzahl der möglichen preview-bilder
int bildAbstand = ( panelPreview . Width - 22 - ( previewNumber * previewImageWidth ) ) / previewNumber ; //errechneter Bildabstand für bessere verteilung
2023-08-11 10:30:48 +02:00
if ( left )
2023-08-10 09:11:56 +02:00
{
2023-08-11 10:30:48 +02:00
//links neues bild laden
//rechte pb entfernen
panelPreview . Controls . Remove ( panelPreview . Controls . OfType < PictureBox > ( ) . Last ( ) ) ;
int newPbX = panelPreview . Controls . OfType < PictureBox > ( ) . First ( ) . Location . X ;
//alle nach rechts verschieben
foreach ( PictureBox pb in panelPreview . Controls . OfType < PictureBox > ( ) )
{
pb . Location = new Point ( pb . Location . X + bildAbstand + previewImageWidth , pb . Location . Y ) ;
}
//links neue pb erstellen
int pIndex = imageIndex ;
pIndex + = 1 ;
if ( pIndex > = images . Count ( ) | | pIndex < 0 )
{
pIndex = 0 ;
}
PictureBox pbn = new PictureBox
2023-08-10 09:11:56 +02:00
{
2023-08-10 09:15:19 +02:00
Anchor = AnchorStyles . Top | AnchorStyles . Bottom | AnchorStyles . Left ,
BackgroundImageLayout = ImageLayout . Stretch ,
BorderStyle = BorderStyle . None ,
2023-08-11 10:30:48 +02:00
Location = new Point ( newPbX , previewImageAbstand ) ,
2023-08-10 09:15:19 +02:00
Size = new Size ( previewImageWidth , previewImageWidth ) ,
TabIndex = 0 ,
TabStop = false ,
2023-08-11 10:30:48 +02:00
SizeMode = PictureBoxSizeMode . Zoom ,
ImageLocation = images . ElementAt ( pIndex ) ,
Tag = pIndex
2023-08-10 09:15:19 +02:00
} ;
2023-08-11 10:30:48 +02:00
panelPreview . SuspendLayout ( ) ;
panelPreview . Controls . Add ( pbn ) ;
panelPreview . Controls . SetChildIndex ( pbn , 0 ) ;
panelPreview . ResumeLayout ( ) ;
pbn . Click + = new EventHandler ( LoadPictureFromPreview_Click ) ;
2023-08-10 09:11:56 +02:00
}
2023-08-11 10:30:48 +02:00
else if ( right )
{
//rechts neues bild laden
//linke pb entfernen
panelPreview . Controls . Remove ( panelPreview . Controls . OfType < PictureBox > ( ) . First ( ) ) ;
int newPbX = panelPreview . Controls . OfType < PictureBox > ( ) . Last ( ) . Location . X ;
//alle nach links verschieben
foreach ( PictureBox pb in panelPreview . Controls . OfType < PictureBox > ( ) )
{
pb . Location = new Point ( pb . Location . X - bildAbstand - previewImageWidth , pb . Location . Y ) ;
}
//rechts neue pb erstellen
int pIndex = imageIndex ;
2023-08-13 13:03:55 +02:00
pIndex + = previewNumber + 1 ;
2023-08-11 10:30:48 +02:00
if ( pIndex > = images . Count ( ) | | pIndex < 0 )
{
pIndex = 0 ;
}
PictureBox pbn = new PictureBox
{
Anchor = AnchorStyles . Top | AnchorStyles . Bottom | AnchorStyles . Left ,
BackgroundImageLayout = ImageLayout . Stretch ,
BorderStyle = BorderStyle . None ,
Location = new Point ( newPbX , previewImageAbstand ) ,
Size = new Size ( previewImageWidth , previewImageWidth ) ,
TabIndex = 0 ,
TabStop = false ,
SizeMode = PictureBoxSizeMode . Zoom ,
ImageLocation = images . ElementAt ( pIndex ) ,
Tag = pIndex
} ;
panelPreview . Controls . Add ( pbn ) ;
pbn . Click + = new EventHandler ( LoadPictureFromPreview_Click ) ;
}
else
2023-08-10 09:11:56 +02:00
{
2023-08-11 10:30:48 +02:00
panelPreview . Controls . Clear ( ) ;
for ( int i = 1 ; i < = previewNumber ; i + + )
2023-08-10 09:15:19 +02:00
{
2023-08-11 10:30:48 +02:00
int moveNext = ( i * previewImageWidth ) + ( bildAbstand * i ) - 80 ;
PictureBox pb = new PictureBox
2023-08-10 09:15:19 +02:00
{
2023-08-11 10:30:48 +02:00
Anchor = AnchorStyles . Top | AnchorStyles . Bottom | AnchorStyles . Left ,
BackgroundImage = Resources . no_picture ,
BackgroundImageLayout = ImageLayout . Stretch ,
BorderStyle = BorderStyle . None ,
Location = new Point ( moveNext , previewImageAbstand ) ,
Name = "pictureBoxPreview" + i ,
Size = new Size ( previewImageWidth , previewImageWidth ) ,
TabIndex = 0 ,
TabStop = false ,
SizeMode = PictureBoxSizeMode . Zoom
} ;
panelPreview . Controls . Add ( pb ) ;
2023-08-10 09:15:19 +02:00
}
2023-08-11 10:30:48 +02:00
int pIndex = imageIndex ;
foreach ( PictureBox pb in panelPreview . Controls . OfType < PictureBox > ( ) )
2023-08-10 09:15:19 +02:00
{
2023-08-11 10:30:48 +02:00
//preview laden
if ( images . Count ( ) > pIndex )
{
pIndex + = 1 ;
if ( pIndex > = images . Count ( ) | | pIndex < 0 )
{
pIndex = 0 ;
}
pb . ImageLocation = images . ElementAt ( pIndex ) ;
pb . BackgroundImage = null ;
pb . Tag = pIndex ;
pb . Click + = new EventHandler ( LoadPictureFromPreview_Click ) ;
}
else
{
pb . BackgroundImage = Resources . no_picture ;
}
2023-08-10 09:15:19 +02:00
}
2023-08-10 09:11:56 +02:00
}
}
2023-08-10 09:15:19 +02:00
catch ( Exception )
{
}
2023-08-10 09:11:56 +02:00
}
/// <summary>
/// Lädt Bilder, die in Vorschau angeklickt wurden
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void LoadPictureFromPreview_Click ( object sender , EventArgs e )
{
var pb = ( PictureBox ) sender ;
LoadPicture ( ( int ) pb . Tag ) ;
2022-08-15 16:34:55 +02:00
}
/// <summary>
/// Öffnet Seite zum Spenden
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonHeart_Click ( object sender , EventArgs e )
{
Process . Start ( "https://www.kmpr.at/donate.php" ) ;
}
/// <summary>
/// Öffnet Seite für Weihnachten
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonChristmas_Click ( object sender , EventArgs e )
{
Process . Start ( "https://www.kmpr.at/christmas.php" ) ;
}
2019-03-22 23:53:20 +01:00
}
}