zooming using mouse wheel using C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alarock
    New Member
    • Jan 2008
    • 14

    zooming using mouse wheel using C#

    how can i do Zooming of a particular area using OnMouseWheel (that is zooming a mouse wheel point that should come into view with zoom ) using C#

    Regards,
    ALGATES
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #2
    What have you tried so far. We can help you help yourself, but we can't do your work for you.

    MODERATOR

    Comment

    • alarock
      New Member
      • Jan 2008
      • 14

      #3
      Dear Moderator(INSER T ALIAS)
      This is the concept I am trying but i want scroll bar in that .how can acheive it .?
      http://www.codeproject .com/KB/graphics/PanZoom2.aspx?m sg=2672101#xx26 72101xx 01xx

      I tried the concept of Autoscrollminsi ze and autoscrollposit ion but output is not working.
      Please help me .If any thing which i done wrong in the previous post please forgive me.

      Regards,
      ALGATES

      Comment

      • Curtis Rutland
        Recognized Expert Specialist
        • Apr 2008
        • 3264

        #4
        You can download the working source code from the top of the page that you linked. Try to download the source, study it, see if you can't figure out what you are doing differently, and then let us know.

        Comment

        • alarock
          New Member
          • Jan 2008
          • 14

          #5
          Originally posted by insertAlias
          You can download the working source code from the top of the page that you linked. Try to download the source, study it, see if you can't figure out what you are doing differently, and then let us know.
          Code:
          using System;
          using System.Collections.Generic;
          using System.ComponentModel;
          using System.Data;
          using System.Drawing;
          using System.Text;
          using System.Windows.Forms;
          
          namespace zoom_aug12
          {
              public partial class Form1 : Form
              {
                  private Bitmap bmp;
                  Graphics grfbmp;
                  public Form1()
                  {
                      InitializeComponent();
                     
                      bmp = new Bitmap(1000, 1000);
                      grfbmp = Graphics.FromImage(bmp);
                      Zoom =3F;
                  }
                  float _zoom = 1F;
                  public float Zoom
                  {
                      get
                      {
                          return _zoom;
                      }
                      set
                      {
                          _zoom = value;
                          UPDA();
                      }
                  }
                  public void UPDA()
                  {
                      this.AutoScrollMinSize = new Size((int)(bmp.Width*Zoom),(int)(bmp.Height*Zoom));
                      Refresh();
                  }
                  protected override void OnLoad(EventArgs e)
                  {
                      Rectangle rect = new Rectangle(0, 0, 999, 999);
                      Pen penblue = new Pen(Color.Blue);
                      grfbmp.DrawRectangle(penblue,rect);
                      base.OnLoad(e);
                  }
                  private Rectangle _drawrect = new Rectangle(0, 0, 1000, 1000);
                  public Rectangle DRAWRECT
                  {
                      get
                      {
                          return _drawrect;
                      }
                      set
                      {
                          _drawrect = value;
                          Refresh();
                      }
                  }
                  private PointF _viewportcenter;
                  PointF ViewPortCenter
                  {
                      get
                      {
                          return _viewportcenter;
                      }
                      set
                      {
                          _viewportcenter = value;
                      }
                  }
                  protected override void OnMouseWheel(MouseEventArgs e)
                  {
          
          
                      Zoom += Zoom * (e.Delta / 1200.0f);
                      if (e.Delta > 0)
                      
                          ViewPortCenter = new PointF(ViewPortCenter.X + ((e.X - (Width / 2)) / (2 * Zoom)), ViewPortCenter.Y + ((e.Y - (Height / 2)) / (2 * Zoom)));
                       // DRAWRECT = new Rectangle((int)ViewPortCenter.X,(int)(ViewPortCenter.Y),(int)(Width/Zoom),(int)(Height/Zoom));
                     
                    
                      //base.OnMouseWheel(e);
                  }
                  protected override void OnScroll(ScrollEventArgs se)
                  {
                      DRAWRECT = new Rectangle(0, 0, 1000, 1000);
                      base.OnScroll(se);
                  }
                  protected override void OnPaint(PaintEventArgs e)
                  {
                      Graphics g = e.Graphics;
                      g.DrawImage(bmp, this.DisplayRectangle, DRAWRECT, GraphicsUnit.Pixel);
                      base.OnPaint(e);
                  }
                  }
          }

          I studied well and i am trying with autoScrollminsi ze ,but scroll bar is not coming accurately.plea se help me.
          Regards,
          ALGATES.

          Comment

          Working...