Initial picturebox configuration

Can now select a new wallpaper and have it appear in the wallpaper picturebox. Also can reopen the profilesettings and the wallpaper will be loaded back into the picturebox. Just need to sort out the clear button and the use current buttons.
This commit is contained in:
Terry MacDonald 2021-08-29 22:54:11 +12:00
parent 3781415dbd
commit a0646c2b8a
3 changed files with 96 additions and 32 deletions

View File

@ -189,6 +189,17 @@ namespace DisplayMagician {
logger.Error(ex, $"Program/StartUpNormally exception: Cannot create the Application Shortcut Folder {AppShortcutPath}");
}
}
if (!Directory.Exists(AppWallpaperPath))
{
try
{
Directory.CreateDirectory(AppWallpaperPath);
}
catch (Exception ex)
{
logger.Error(ex, $"Program/StartUpNormally exception: Cannot create the Application Wallpaper Folder {AppWallpaperPath}");
}
}
// Write the Application Name
Console.WriteLine($"{Application.ProductName} v{Application.ProductVersion}");

View File

@ -31,15 +31,15 @@ namespace DisplayMagician.UIForms
{
this.btn_back = new System.Windows.Forms.Button();
this.gb_general = new System.Windows.Forms.GroupBox();
this.btn_current = new System.Windows.Forms.Button();
this.btn_clear = new System.Windows.Forms.Button();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.pb_wallpaper = new System.Windows.Forms.PictureBox();
this.btn_select = new System.Windows.Forms.Button();
this.cb_set_wallpaper = new System.Windows.Forms.CheckBox();
this.label1 = new System.Windows.Forms.Label();
this.cmb_wallpaper_display_mode = new System.Windows.Forms.ComboBox();
this.btn_current = new System.Windows.Forms.Button();
this.gb_general.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pb_wallpaper)).BeginInit();
this.SuspendLayout();
//
// btn_back
@ -62,7 +62,7 @@ namespace DisplayMagician.UIForms
//
this.gb_general.Controls.Add(this.btn_current);
this.gb_general.Controls.Add(this.btn_clear);
this.gb_general.Controls.Add(this.pictureBox1);
this.gb_general.Controls.Add(this.pb_wallpaper);
this.gb_general.Controls.Add(this.btn_select);
this.gb_general.Controls.Add(this.cb_set_wallpaper);
this.gb_general.Controls.Add(this.label1);
@ -76,6 +76,22 @@ namespace DisplayMagician.UIForms
this.gb_general.TabStop = false;
this.gb_general.Text = "Wallpaper Settings";
//
// btn_current
//
this.btn_current.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btn_current.FlatAppearance.MouseDownBackColor = System.Drawing.Color.IndianRed;
this.btn_current.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Brown;
this.btn_current.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btn_current.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btn_current.ForeColor = System.Drawing.Color.White;
this.btn_current.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.btn_current.Location = new System.Drawing.Point(417, 158);
this.btn_current.Name = "btn_current";
this.btn_current.Size = new System.Drawing.Size(75, 23);
this.btn_current.TabIndex = 19;
this.btn_current.Text = "&Use Current";
this.btn_current.UseVisualStyleBackColor = true;
//
// btn_clear
//
this.btn_clear.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
@ -92,13 +108,17 @@ namespace DisplayMagician.UIForms
this.btn_clear.Text = "&Clear";
this.btn_clear.UseVisualStyleBackColor = true;
//
// pictureBox1
// pb_wallpaper
//
this.pictureBox1.Location = new System.Drawing.Point(28, 68);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(381, 212);
this.pictureBox1.TabIndex = 17;
this.pictureBox1.TabStop = false;
this.pb_wallpaper.BackColor = System.Drawing.Color.White;
this.pb_wallpaper.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
this.pb_wallpaper.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pb_wallpaper.Location = new System.Drawing.Point(28, 68);
this.pb_wallpaper.Name = "pb_wallpaper";
this.pb_wallpaper.Size = new System.Drawing.Size(381, 212);
this.pb_wallpaper.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pb_wallpaper.TabIndex = 17;
this.pb_wallpaper.TabStop = false;
//
// btn_select
//
@ -153,22 +173,6 @@ namespace DisplayMagician.UIForms
this.cmb_wallpaper_display_mode.TabIndex = 12;
this.cmb_wallpaper_display_mode.SelectedIndexChanged += new System.EventHandler(this.cmb_wallpaper_display_mode_SelectedIndexChanged);
//
// btn_current
//
this.btn_current.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btn_current.FlatAppearance.MouseDownBackColor = System.Drawing.Color.IndianRed;
this.btn_current.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Brown;
this.btn_current.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btn_current.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btn_current.ForeColor = System.Drawing.Color.White;
this.btn_current.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.btn_current.Location = new System.Drawing.Point(417, 158);
this.btn_current.Name = "btn_current";
this.btn_current.Size = new System.Drawing.Size(75, 23);
this.btn_current.TabIndex = 19;
this.btn_current.Text = "&Use Current";
this.btn_current.UseVisualStyleBackColor = true;
//
// ProfileSettingsForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -190,7 +194,7 @@ namespace DisplayMagician.UIForms
this.Load += new System.EventHandler(this.ProfileSettingsForm_Load);
this.gb_general.ResumeLayout(false);
this.gb_general.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pb_wallpaper)).EndInit();
this.ResumeLayout(false);
}
@ -203,7 +207,7 @@ namespace DisplayMagician.UIForms
private System.Windows.Forms.ComboBox cmb_wallpaper_display_mode;
private System.Windows.Forms.Button btn_select;
private System.Windows.Forms.Button btn_clear;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.PictureBox pb_wallpaper;
private System.Windows.Forms.Button btn_current;
}
}

View File

@ -3,6 +3,9 @@ using NHotkey;
using NHotkey.WindowsForms;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using WK.Libraries.BootMeUpNS;
@ -16,6 +19,7 @@ namespace DisplayMagician.UIForms
private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
private Dictionary<Wallpaper.Style, string> wallpaperStyleText = new Dictionary<Wallpaper.Style, string>();
Bitmap wallpaperImage = null;
private bool _profileSettingChanged = false;
public ProfileSettingsForm()
@ -60,10 +64,16 @@ namespace DisplayMagician.UIForms
logger.Info($"ProfileSettingsForm/ProfileSettingsForm_Load: Profile {Profile.Name} has loaded with Set Wallpaper enabled and Wallpaper Style {Profile.WallpaperStyle.ToString("G")} and Wallpaper Filename of {Profile.WallpaperBitmapFilename}.");
cb_set_wallpaper.Checked = true;
cmb_wallpaper_display_mode.SelectedIndex = cmb_wallpaper_display_mode.FindStringExact(wallpaperStyleText[Profile.WallpaperStyle]);
/*if (Profile.WallpaperBitmapFilename != "")
if (Profile.WallpaperBitmapFilename != "" && File.Exists(Profile.WallpaperBitmapFilename))
{
txt_wallpaper_filename.Text = Profile.WallpaperBitmapFilename;
}*/
// Load the existing Wallpaper into the PictureBox
//Read the contents of the file into a stream
//StreamReader streamReader = new StreamReader(Profile.WallpaperBitmapFilename);
FileStream fileStream = new FileStream(Profile.WallpaperBitmapFilename,FileMode.Open);
wallpaperImage = new Bitmap(fileStream);
pb_wallpaper.Image = wallpaperImage;
}
}
else
{
@ -81,6 +91,7 @@ namespace DisplayMagician.UIForms
private void btn_back_Click(object sender, EventArgs e)
{
wallpaperImage.Dispose();
this.Close();
}
@ -96,7 +107,45 @@ namespace DisplayMagician.UIForms
private void btn_select_wallpaper_Click(object sender, EventArgs e)
{
_profileSettingChanged = true;
_profileSettingChanged = true;
string filePath = string.Empty;
string wallpaperPath = string.Empty;
try
{
using (OpenFileDialog openFileDialog = new OpenFileDialog())
{
openFileDialog.InitialDirectory = "c:\\";
openFileDialog.Filter = "Image Files(*.bmp; *.jpg; *.gif; *.png; *.tiff)| *.bmp; *.jpg; *.gif; *.png; *.tiff | All files(*.*) | *.*";
openFileDialog.FilterIndex = 2;
openFileDialog.RestoreDirectory = true;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
//Get the path of specified file
filePath = openFileDialog.FileName;
// If The user selected a photo then we need to set the set wallpaper to yes
cb_set_wallpaper.Checked = true;
//Read the contents of the file into a stream
Stream fileStream = openFileDialog.OpenFile();
wallpaperImage = new Bitmap(fileStream);
wallpaperPath = Path.Combine(Program.AppWallpaperPath, $"wallpaper-{Profile.UUID}.jpg");
wallpaperImage.Save(wallpaperPath, ImageFormat.Png);
Profile.WallpaperBitmapFilename = wallpaperPath;
pb_wallpaper.Image = wallpaperImage;
}
}
}
catch (Exception ex)
{
// TODO: handle the exceptions
}
}
}
}