C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Graphics »

Zooming in C#


Posted Date: 26 Nov 2008    Resource Type: Code Snippets    Category: Graphics
Author: srinidhi.m.gMember Level: Silver    
Rating: 1 out of 5Points: 8



This sample code ssnippet shows how to zoom a page using C#.


public partial class Form1 : Form
{
Rectangle rubberBand,zoom_Rect;
Bitmap bmp,bmp_cut;
float m_Scalef = 1.0f;
Image image,myImage;

public Form1()
{
InitializeComponent();
bmp = (Bitmap)pictureBox1.Image;

}

private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
Point pt = pictureBox1.PointToScreen(new Point(e.X, e.Y));
rubberBand = new Rectangle(pt.X, pt.Y, 1, 1);
ControlPaint.DrawReversibleFrame(rubberBand, pictureBox1.BackColor, FrameStyle.Dashed);
this.Invalidate();
}

private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left)
return;

ControlPaint.DrawReversibleFrame(rubberBand, pictureBox1.BackColor, FrameStyle.Dashed);

Point pt = pictureBox1.PointToScreen(new Point(e.X, e.Y));
rubberBand = new Rectangle(rubberBand.X, rubberBand.Y, pt.X - rubberBand.X, pt.Y - rubberBand.Y);

ControlPaint.DrawReversibleFrame(rubberBand, pictureBox1.BackColor, FrameStyle.Dashed);

pictureBox1.Invalidate();

}

private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ControlPaint.DrawReversibleFrame(rubberBand, Color.Black, FrameStyle.Thick);
}

}


private void button2_Click(object sender, EventArgs e)
{
zoom_Rect = pictureBox1.RectangleToClient(rubberBand);
bmp_cut = new Bitmap(zoom_Rect.Width, zoom_Rect.Height);

Graphics g = Graphics.FromImage(bmp_cut);
image = pictureBox1.Image;
g.DrawImage(image, 0, 0, zoom_Rect, GraphicsUnit.Pixel);
pictureBox1.Image = bmp_cut;
g.Dispose();


}

private void button3_Click(object sender, EventArgs e)
{

panel1.Refresh();
if (comboBox1.SelectedIndex == 0)
m_Scalef = .25f;
if (comboBox1.SelectedIndex == 1)
m_Scalef = .5f;
if (comboBox1.SelectedIndex == 2)
m_Scalef = .75f;
if (comboBox1.SelectedIndex == 3)
m_Scalef = 1.0f;
if (comboBox1.SelectedIndex == 4)
m_Scalef = 2.0f;

m_Scalef = m_Scalef * 2.0f;

int a_Width, b_Height;
a_Width = (int)(rubberBand.Width * m_Scalef);
b_Height = (int)(rubberBand.Height * m_Scalef);
panel1.Size = new Size(a_Width, b_Height);


myImage = pictureBox1.Image;
Graphics g = panel1.CreateGraphics();


g.DrawImage(myImage, 0, 0, rubberBand.Width * m_Scalef, rubberBand.Height * m_Scalef);




Invalidate();
}
}

It really helps in basic zooming concept,so any one can make use of this code...:)



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Zooming in C#  .  Zoom  .  Watch out!!!  .  C# zooming  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Name Shaped Form
Previous Resource: color dropdown
Return to Discussion Resource Index
Post New Resource
Category: Graphics


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use