|
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); } } }
This is my code.can any one please help me to fix the scroll bar accurately .using AutoScroll min size using C#
| | algates Tuesday, August 12, 2008 5:38 AM |
Hi algates,
Based on my understanding, the problem is “How to implement auto scroll when zooming pictures�
I have seen the article you have provided, and it’s good that theauthor tries to override the OnPaintBackground to avoid the flicks. However, I want to suggest you another article in which there is a project providing much more functionality than you want directly, including appearing AutoScrollBars when zooming pictures.
The project is written is VB.NET, but it is easy to understand. You can access the article from the following link: http://www.codeproject.com/KB/GDI-plus/PanZoomExample.aspx
If you have difficulty understanding VB language, try to use VBÂÂÂÂÃ C# link.
If you have further questions, don’t hesitate to tell me.
Best Regards,
Bruce Zhou
Windows Forms General FAQs Windows Forms Data Controls and Databinding FAQs
| | Bruce.Zhou Friday, August 15, 2008 7:45 AM | Alternatively, you might want to look at this: http://www.bobpowell.net/zoompicbox.htm | | Mick Doherty Friday, August 15, 2008 9:14 AM | Your code is quite verbose, and completelly lacking code. Could you please explain what do you exactly want to achieve, so we can help you find the right way to achieve it? Just with the code, without a well-explained intention, any attempt to answer would be a blind shot.
| | herenvardo Tuesday, August 12, 2008 1:29 PM | hi , Thanks for your quick replay. Actullay i am developing and implementing zoom operation from this article. http://www.codeproject.com/KB/graphics/PanZoom2.aspx?msg=2672101#xx2672101xxIn this article zoom opertion is working nice. But I want scroll bar in this.Since i want automatic scroll bars, i am trying to use AutoscrollMinSize and Autoscrollpositon .But Scroll bar is not working correctly .Please help me with source and concepts to implement scroll bars in this article.Thanks in advance. Cheers & regards, ALGATES. | | algates Wednesday, August 13, 2008 4:04 AM |
Hi algates,
Based on my understanding, the problem is “How to implement auto scroll when zooming pictures�
I have seen the article you have provided, and it’s good that theauthor tries to override the OnPaintBackground to avoid the flicks. However, I want to suggest you another article in which there is a project providing much more functionality than you want directly, including appearing AutoScrollBars when zooming pictures.
The project is written is VB.NET, but it is easy to understand. You can access the article from the following link: http://www.codeproject.com/KB/GDI-plus/PanZoomExample.aspx
If you have difficulty understanding VB language, try to use VBÂÂÂÂÃ C# link.
If you have further questions, don’t hesitate to tell me.
Best Regards,
Bruce Zhou
Windows Forms General FAQs Windows Forms Data Controls and Databinding FAQs
| | Bruce.Zhou Friday, August 15, 2008 7:45 AM | Alternatively, you might want to look at this: http://www.bobpowell.net/zoompicbox.htm | | Mick Doherty Friday, August 15, 2008 9:14 AM | hi , Thanks for your quick reply. This link is working fine. But i want to (view and zoom ) the particular area like this project http://www.codeproject.com/KB/graphics/PanZoom2.aspx?msg=2672101#xx2672101xxIn this i want scroll bar .Is it possible? Regards, ALGATES. | | algates Saturday, August 30, 2008 4:45 AM | The program is not very easy to extend. You'd better ask the author of this program to extend his own application. | | zamesking Sunday, August 31, 2008 12:00 PM |
|