SHARE
TWEET

Zoomer.cs

a guest Nov 30th, 2012 12 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // User control class for the image display control
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Drawing;
  6. using System.Data;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Windows.Forms;
  10.  
  11. namespace ImageViewerLite
  12. {
  13.     public partial class Zoomer : UserControl
  14.     {
  15.         public Zoomer()
  16.         {
  17.             InitializeComponent();
  18.  
  19.             this.SetStyle(
  20.                 ControlStyles.AllPaintingInWmPaint |
  21.                 ControlStyles.UserPaint |
  22.                 ControlStyles.SupportsTransparentBackColor |
  23.                 ControlStyles.DoubleBuffer, true);
  24.         }
  25.  
  26.        
  27.         private Image image;
  28.         [ Category("Appearance"), Description("The image to display.") ]
  29.         public Image Image
  30.         {
  31.             get { return image; }
  32.             set
  33.             {
  34.                 image = value;
  35.                 this.Invalidate();
  36.             }
  37.         }
  38.  
  39.         private double zoom = 1;
  40.         [Category("Appearance"), Description("How much the image is zoomed.")]
  41.         public double Zoom
  42.         {
  43.             get { return zoom; }
  44.             set
  45.             {
  46.                 if (value < 0)
  47.                 {
  48.                     value = 0;
  49.                 }
  50.                 else if (value > 10)
  51.                 {
  52.                     value = 10;
  53.                 }
  54.                 else
  55.                 {
  56.                     zoom = value;
  57.                 }
  58.             }
  59.         }
  60.  
  61.         protected override void OnPaintBackground(PaintEventArgs e)
  62.         {
  63.             // Don't paint a background
  64.         }
  65.  
  66.         protected override void OnPaint(PaintEventArgs e)
  67.         {
  68.             double factor = (zoom);
  69.             this.Size = new Size(
  70.                 (int)(image.Size.Width * factor),
  71.                 (int)(image.Size.Height * factor));
  72.             e.Graphics.DrawImage(this.image, this.ClientRectangle,
  73.                 new Rectangle(0, 0, image.Width, image.Height), GraphicsUnit.Pixel);
  74.  
  75.             base.OnPaint(e);
  76.         }
  77.  
  78.     }
  79. }
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
 
Top