SHARE
TWEET

ImageForm.cs

a guest Nov 30th, 2012 8 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace ImageViewerLite
  11. {
  12.     public partial class ImageForm : Form
  13.     {
  14.         Timer animationTimer;
  15.         const int animSpeed = 10; // In milliseconds
  16.  
  17.         public ImageForm()
  18.         {
  19.             InitializeComponent();
  20.             animationTimer = new Timer();
  21.             animationTimer.Tick += new EventHandler(animationTimer_Tick);
  22.         }
  23.  
  24.         private void Form1_Load(object sender, EventArgs e)
  25.         {
  26.             buttonTrayAreaPanel.Location = buttonTray.Location;
  27.             buttonTrayAreaPanel.Size = buttonTray.Size;
  28.  
  29.             try
  30.             {
  31.                 openFileDialog.InitialDirectory = @"H:\Documents\";
  32.             }
  33.             catch
  34.             {
  35.                 openFileDialog.InitialDirectory = @"C:\";
  36.             }
  37.         }
  38.        
  39.         // Other code ambiguous to this issue was cut out
  40.        
  41.         private void zoomTextBox_KeyUp(object sender, KeyEventArgs e)
  42.         {
  43.             if (e.KeyCode == Keys.Enter)
  44.             {
  45.                 try
  46.                 {
  47.                     Zoom(float.Parse(zoomTextBox.Text.Substring(0, zoomTextBox.TextLength - 1)));
  48.                 }
  49.                 catch (FormatException)
  50.                 {
  51.                     Zoom(zoomTextBox.Text);
  52.                 }
  53.                 _image.Focus();
  54.             }
  55.            
  56.         }
  57.  
  58.         private void Zoom(float percent)
  59.         {
  60.             _image.Zoom = percent * 0.01;
  61.  
  62.             CenterImage();
  63.         }
  64.         private void Zoom(string level)
  65.         {
  66.             if (level.ToLower() == "fit")
  67.             {
  68.                
  69.             }
  70.             else if (level.ToLower() == "full")
  71.             {
  72.                 _image.Zoom = 1;
  73.             }
  74.  
  75.             CenterImage();
  76.         }
  77.  
  78.         private void CenterImage()
  79.         {
  80.             Point halfSize = new Point(_image.Image.Size.Width / 2, _image.Image.Size.Height / 2);
  81.             Point center = new Point(this.Width / 2, this.Height / 2);
  82.  
  83.             _image.Location = new Point(center.X - halfSize.X, center.Y - halfSize.Y);
  84.         }
  85.  
  86.         private void zoomTextBox_TextChanged(object sender, EventArgs e)
  87.         {
  88.             try
  89.             {
  90.                 zoomUpDown.Value = decimal.Parse(zoomTextBox.Text);
  91.             }
  92.             catch
  93.             {
  94.                 zoomUpDown.Value = (decimal)_image.Zoom;
  95.             }
  96.         }
  97.  
  98.         private void zoomUpDown_ValueChanged(object sender, EventArgs e)
  99.         {
  100.             zoomTextBox.Text = zoomUpDown.Value.ToString();
  101.             Zoom(float.Parse(zoomTextBox.Text));
  102.         }
  103.     }
  104. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top