Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // User control class for the image display control
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace ImageViewerLite
- {
- public partial class Zoomer : UserControl
- {
- public Zoomer()
- {
- InitializeComponent();
- this.SetStyle(
- ControlStyles.AllPaintingInWmPaint |
- ControlStyles.UserPaint |
- ControlStyles.SupportsTransparentBackColor |
- ControlStyles.DoubleBuffer, true);
- }
- private Image image;
- [ Category("Appearance"), Description("The image to display.") ]
- public Image Image
- {
- get { return image; }
- set
- {
- image = value;
- this.Invalidate();
- }
- }
- private double zoom = 1;
- [Category("Appearance"), Description("How much the image is zoomed.")]
- public double Zoom
- {
- get { return zoom; }
- set
- {
- if (value < 0)
- {
- value = 0;
- }
- else if (value > 10)
- {
- value = 10;
- }
- else
- {
- zoom = value;
- }
- }
- }
- protected override void OnPaintBackground(PaintEventArgs e)
- {
- // Don't paint a background
- }
- protected override void OnPaint(PaintEventArgs e)
- {
- double factor = (zoom);
- this.Size = new Size(
- (int)(image.Size.Width * factor),
- (int)(image.Size.Height * factor));
- e.Graphics.DrawImage(this.image, this.ClientRectangle,
- new Rectangle(0, 0, image.Width, image.Height), GraphicsUnit.Pixel);
- base.OnPaint(e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement