using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using Microsoft.Win32; namespace Picture_Viewer { public partial class frmViewer : Form { const bool c_prompt = false; string m_strUsername = ""; bool m_blnPromptOnExit = c_prompt; Color m_objPictureBoxColor; public frmViewer() { InitializeComponent(); } #region Event Handling private void btnSelectPicture_Click(object sender, EventArgs e) { this.openPicture(); } private void btnQuit_Click(object sender, EventArgs e) { // Close the window and exit the application this.Close(); } private void btnEnlarge_Click(object sender, EventArgs e) { this.Width = this.Width + 20; this.Height = this.Height + 20; } private void btnShrink_Click(object sender, EventArgs e) { if (this.Width <= 400 && this.Height <= 325) { MessageBox.Show("You can't shrink it any further!"); } else { this.Width = this.Width - 20; this.Height = this.Height - 20; } } private void btnDrawBorder_Click(object sender, EventArgs e) { this.drawBorder(); } private void picShowPicture_MouseMove(object sender, MouseEventArgs e) { lblX.Text = "X: " + e.X.ToString(); lblY.Text = "Y: " + e.Y.ToString(); } private void picShowPicture_MouseLeave(object sender, EventArgs e) { lblX.Text = ""; lblY.Text = ""; } private void frmViewer_Load(object sender, EventArgs e) { lblX.Text = ""; lblY.Text = ""; LoadDefaults(); } private void button1_Click(object sender, EventArgs e) { this.openOptions(); } private void mnuOpenPicture_Click(object sender, EventArgs e) { this.openPicture(); } private void mnuPromptOnExit_Click(object sender, EventArgs e) { mnuPromptOnExit.Checked = !(mnuPromptOnExit.Checked); m_blnPromptOnExit = mnuPromptOnExit.Checked; } private void mnuQuit_Click(object sender, EventArgs e) { this.Close(); } private void mnuDrawBorder_Click(object sender, EventArgs e) { this.drawBorder(); } private void mnuOptions_Click(object sender, EventArgs e) { this.openOptions(); } private void drawBorderToolStripMenuItem_Click(object sender, EventArgs e) { this.drawBorder(); } private void tbbOpenPicture_Click(object sender, EventArgs e) { this.openPicture(); } private void tbbDrawBorder_Click(object sender, EventArgs e) { this.drawBorder(); } private void tbbOptions_Click(object sender, EventArgs e) { this.openOptions(); } #endregion public void drawBorder() { Graphics objGraphics = null; objGraphics = this.CreateGraphics(); objGraphics.Clear(SystemColors.Control); objGraphics.DrawRectangle(Pens.Blue, picShowPicture.Left - 1, picShowPicture.Top - 1, picShowPicture.Width + 1, picShowPicture.Height + 1); objGraphics.Dispose(); } public void openPicture() { try { if (ofdSelectPicture.ShowDialog() == DialogResult.OK) { picShowPicture.Image = Image.FromFile(ofdSelectPicture.FileName); this.Text = string.Concat("Picture Viewer (" + ofdSelectPicture.FileName + ")"); sbrMyStatusStrip.Items[0].Text = ofdSelectPicture.FileName; } UpdateLog(ofdSelectPicture.FileName); } catch (System.OutOfMemoryException) { MessageBox.Show("The file you have selected is not an image file supported by this program.", "Invalid File", MessageBoxButtons.OK); } } private void UpdateLog(string strFileName) { System.IO.StreamWriter objFile = new System.IO.StreamWriter( System.AppDomain.CurrentDomain.BaseDirectory + @"\PictureLog.txt", true); objFile.WriteLine(DateTime.Now + " " + strFileName); objFile.Close(); objFile.Dispose(); } public void openOptions() { frmOptions frmOptionsDialog = new frmOptions(); frmOptionsDialog.ShowDialog(); LoadDefaults(); } private void frmViewer_FormClosing(object sender, FormClosingEventArgs e) { if (m_blnPromptOnExit) { if (MessageBox.Show("Close the Picture Viewer program?", "Confirm Exit", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { e.Cancel = true; } } } public void LoadDefaults() { m_blnPromptOnExit = Convert.ToBoolean(Registry.GetValue( @"HKEY_CURRENT_USER\Software\Draynor.net\PictureViewer\", "PromptOnExit", "false")); if (Convert.ToString(Registry.GetValue( @"HKEY_CURRENT_USER\Software\Draynor.net\PictureViewer\", "BackColor", "Gray")) == "Gray") m_objPictureBoxColor = System.Drawing.SystemColors.Control; else m_objPictureBoxColor = System.Drawing.Color.White; picShowPicture.BackColor = m_objPictureBoxColor; mnuPromptOnExit.Checked = m_blnPromptOnExit; } private void tbbGetFileAttributes_Click(object sender, EventArgs e) { // Make sure the file is opened if (ofdSelectPicture.FileName == "") { MessageBox.Show("There is no file open!"); return; } // Create the string builder object to concatenate strings. System.Text.StringBuilder stbProperties = new System.Text.StringBuilder(""); System.IO.FileAttributes fileAttributes; // Get the dates. stbProperties.Append("Created: "); stbProperties.Append(System.IO.File.GetCreationTime(ofdSelectPicture.FileName)); stbProperties.Append("\r\n"); stbProperties.Append("Accessed: "); stbProperties.Append(System.IO.File.GetLastAccessTime(ofdSelectPicture.FileName)); stbProperties.Append("\r\n"); stbProperties.Append("Modified: "); stbProperties.Append(System.IO.File.GetLastWriteTime(ofdSelectPicture.FileName)); // Get File Attributes fileAttributes = System.IO.File.GetAttributes(ofdSelectPicture.FileName); stbProperties.Append("\r\n"); // Use a binary AND to extract the specific attributes. stbProperties.Append("Normal: "); stbProperties.Append( Convert.ToBoolean((fileAttributes & System.IO.FileAttributes.Normal) == System.IO.FileAttributes.Normal)); stbProperties.Append("\r\n"); stbProperties.Append("Hidden: "); stbProperties.Append( Convert.ToBoolean((fileAttributes & System.IO.FileAttributes.Hidden) == System.IO.FileAttributes.Hidden)); stbProperties.Append("\r\n"); stbProperties.Append("ReadOnly: "); stbProperties.Append( Convert.ToBoolean((fileAttributes & System.IO.FileAttributes.ReadOnly) == System.IO.FileAttributes.ReadOnly)); stbProperties.Append("\r\n"); stbProperties.Append("System: "); stbProperties.Append( Convert.ToBoolean((fileAttributes & System.IO.FileAttributes.System) == System.IO.FileAttributes.System)); stbProperties.Append("\r\n"); stbProperties.Append("Temporary File: "); stbProperties.Append( Convert.ToBoolean((fileAttributes & System.IO.FileAttributes.Temporary) == System.IO.FileAttributes.Temporary)); stbProperties.Append("\r\n"); stbProperties.Append("Archive: "); stbProperties.Append( Convert.ToBoolean((fileAttributes & System.IO.FileAttributes.Archive) == System.IO.FileAttributes.Archive)); MessageBox.Show(stbProperties.ToString()); } private void tbbViewLog_Click(object sender, EventArgs e) { frmLogViewer objLog = new frmLogViewer(); objLog.ShowDialog(); } private void viewLogToolStripMenuItem_Click(object sender, EventArgs e) { frmLogViewer objLog = new frmLogViewer(); objLog.ShowDialog(); } } }