using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;namespace 实验程序 {
public partial class Form1 : Form { Image pbImg = null; Rectangle rect = new Rectangle(50, 50, 100, 100); public Form1() { InitializeComponent(); pbImg = new Bitmap(pictureBox1.Width, pictureBox1.Height); DrawSomething(Graphics.FromImage(pbImg), rect); pictureBox1.Image = pbImg; } private void DrawSomething(Graphics g,Rectangle rec) { g.Clear(pictureBox1.BackColor); g.DrawRectangle(new Pen(Color.Red, 1), rec); } private void btn_ZoomIn_Click(object sender, EventArgs e) { int x = rect.Left * 2 + (1 - 2) * pictureBox1.Width / 2; int y = rect.Top * 2 + (1 - 2) * pictureBox1.Height / 2; int w = rect.Width * 2; int h = rect.Height * 2; rect = new Rectangle(x, y, w, h); DrawSomething(Graphics.FromImage(pbImg), rect); pictureBox1.Image = pbImg; } private void btn_ZoomOut_Click(object sender, EventArgs e) { int x = (int)(rect.Left * 0.5 + (1 - 0.5) * pictureBox1.Width / 2); int y = (int)(rect.Top * 0.5 + (1 - 0.5) * pictureBox1.Height / 2); int w = (int)(rect.Width * 0.5); int h = (int)(rect.Height * 0.5); rect = new Rectangle(x, y, w, h); DrawSomething(Graphics.FromImage(pbImg), rect); pictureBox1.Image = pbImg; } }}
Graphics g = pictureBox.CreateGraphics();
System.Drawing.Graphics mydraw;
mydraw=pictureBox1.CreateGraphics();
mydraw.DrawLine(......)
绘出了一个分形图
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace 实验程序
{
public partial class Form1 : Form
{
Image pbImg = null;
Rectangle rect = new Rectangle(50, 50, 100, 100);
public Form1()
{
InitializeComponent();
pbImg = new Bitmap(pictureBox1.Width, pictureBox1.Height);
DrawSomething(Graphics.FromImage(pbImg), rect);
pictureBox1.Image = pbImg;
} private void DrawSomething(Graphics g,Rectangle rec)
{
g.Clear(pictureBox1.BackColor);
g.DrawRectangle(new Pen(Color.Red, 1), rec);
} private void btn_ZoomIn_Click(object sender, EventArgs e)
{
int x = rect.Left * 2 + (1 - 2) * pictureBox1.Width / 2;
int y = rect.Top * 2 + (1 - 2) * pictureBox1.Height / 2;
int w = rect.Width * 2;
int h = rect.Height * 2;
rect = new Rectangle(x, y, w, h);
DrawSomething(Graphics.FromImage(pbImg), rect);
pictureBox1.Image = pbImg;
} private void btn_ZoomOut_Click(object sender, EventArgs e)
{
int x = (int)(rect.Left * 0.5 + (1 - 0.5) * pictureBox1.Width / 2);
int y = (int)(rect.Top * 0.5 + (1 - 0.5) * pictureBox1.Height / 2);
int w = (int)(rect.Width * 0.5);
int h = (int)(rect.Height * 0.5);
rect = new Rectangle(x, y, w, h);
DrawSomething(Graphics.FromImage(pbImg), rect);
pictureBox1.Image = pbImg;
}
}}