Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace ImageViewerLite
- {
- public partial class ImageForm : Form
- {
- Timer animationTimer;
- const int animSpeed = 10; // In milliseconds
- public ImageForm()
- {
- InitializeComponent();
- animationTimer = new Timer();
- animationTimer.Tick += new EventHandler(animationTimer_Tick);
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- buttonTrayAreaPanel.Location = buttonTray.Location;
- buttonTrayAreaPanel.Size = buttonTray.Size;
- try
- {
- openFileDialog.InitialDirectory = @"H:\Documents\";
- }
- catch
- {
- openFileDialog.InitialDirectory = @"C:\";
- }
- }
- // Other code ambiguous to this issue was cut out
- private void zoomTextBox_KeyUp(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- {
- try
- {
- Zoom(float.Parse(zoomTextBox.Text.Substring(0, zoomTextBox.TextLength - 1)));
- }
- catch (FormatException)
- {
- Zoom(zoomTextBox.Text);
- }
- _image.Focus();
- }
- }
- private void Zoom(float percent)
- {
- _image.Zoom = percent * 0.01;
- CenterImage();
- }
- private void Zoom(string level)
- {
- if (level.ToLower() == "fit")
- {
- }
- else if (level.ToLower() == "full")
- {
- _image.Zoom = 1;
- }
- CenterImage();
- }
- private void CenterImage()
- {
- Point halfSize = new Point(_image.Image.Size.Width / 2, _image.Image.Size.Height / 2);
- Point center = new Point(this.Width / 2, this.Height / 2);
- _image.Location = new Point(center.X - halfSize.X, center.Y - halfSize.Y);
- }
- private void zoomTextBox_TextChanged(object sender, EventArgs e)
- {
- try
- {
- zoomUpDown.Value = decimal.Parse(zoomTextBox.Text);
- }
- catch
- {
- zoomUpDown.Value = (decimal)_image.Zoom;
- }
- }
- private void zoomUpDown_ValueChanged(object sender, EventArgs e)
- {
- zoomTextBox.Text = zoomUpDown.Value.ToString();
- Zoom(float.Parse(zoomTextBox.Text));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement