写了如下代码,可不知道哪出问题了,大家帮帮我~
namespace WindowsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
pictureBox1.Image = Image.FromFile("E:\\Picture\\DSC04720.JPG");
vScrollBar1.Maximum = pictureBox1.Height - this.ClientSize.Height + hScrollBar1.Height;
hScrollBar1.Maximum = pictureBox1.Width - this.ClientSize.Width + vScrollBar1.Width;
} private void vScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
System.Drawing.Point mypos = new Point(0, 0);
mypos.X = pictureBox1.Location.X;
mypos.Y = -vScrollBar1.Value;
pictureBox1.Location = mypos;
} private void hScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
System.Drawing.Point mypos = new Point(0, 0);
mypos.Y = pictureBox1.Location.Y;
mypos.X = -hScrollBar1.Value;
pictureBox1.Location = mypos;
} private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked)
{
pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
}
else
{
pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
}
}
}
}
namespace WindowsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
pictureBox1.Image = Image.FromFile("E:\\Picture\\DSC04720.JPG");
vScrollBar1.Maximum = pictureBox1.Height - this.ClientSize.Height + hScrollBar1.Height;
hScrollBar1.Maximum = pictureBox1.Width - this.ClientSize.Width + vScrollBar1.Width;
} private void vScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
System.Drawing.Point mypos = new Point(0, 0);
mypos.X = pictureBox1.Location.X;
mypos.Y = -vScrollBar1.Value;
pictureBox1.Location = mypos;
} private void hScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
System.Drawing.Point mypos = new Point(0, 0);
mypos.Y = pictureBox1.Location.Y;
mypos.X = -hScrollBar1.Value;
pictureBox1.Location = mypos;
} private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked)
{
pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
}
else
{
pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
}
}
}
}
public partial class Form1: Form
{
private VScrollBar vScrollBar1;
private HScrollBar hScrollBar1;
private CheckBox checkBox1;
private PictureBox pictureBox1;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
pictureBox1.Location = Point.Empty;
pictureBox1.Image = Image.FromFile("E:\\Picture\\DSC04720.JPG");
vScrollBar1.Maximum = pictureBox1.Height - this.ClientSize.Height + hScrollBar1.Height+vScrollBar1.LargeChange+1;
hScrollBar1.Maximum = pictureBox1.Width - this.ClientSize.Width + vScrollBar1.Width+hScrollBar1.LargeChange+1;
} private void vScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
pictureBox1.Top= -e.NewValue;
} private void hScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
pictureBox1.Left= -e.NewValue;
} private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked)
{
pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
}
else
{
pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
}
} private void InitializeComponent()
{
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.vScrollBar1 = new System.Windows.Forms.VScrollBar();
this.hScrollBar1 = new System.Windows.Forms.HScrollBar();
this.checkBox1 = new System.Windows.Forms.CheckBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.Location = new System.Drawing.Point(12, 12);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(300, 222);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// vScrollBar1
//
this.vScrollBar1.Dock = System.Windows.Forms.DockStyle.Right;
this.vScrollBar1.Location = new System.Drawing.Point(185, 0);
this.vScrollBar1.Name = "vScrollBar1";
this.vScrollBar1.Size = new System.Drawing.Size(17, 159);
this.vScrollBar1.TabIndex = 1;
this.vScrollBar1.Scroll += new System.Windows.Forms.ScrollEventHandler(this.vScrollBar1_Scroll);
//
// hScrollBar1
//
this.hScrollBar1.Dock = System.Windows.Forms.DockStyle.Bottom;
this.hScrollBar1.Location = new System.Drawing.Point(0, 142);
this.hScrollBar1.Name = "hScrollBar1";
this.hScrollBar1.Size = new System.Drawing.Size(185, 17);
this.hScrollBar1.TabIndex = 2;
this.hScrollBar1.Scroll += new System.Windows.Forms.ScrollEventHandler(this.hScrollBar1_Scroll);
//
// checkBox1
//
this.checkBox1.AutoSize = true;
this.checkBox1.Location = new System.Drawing.Point(40, 24);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(78, 16);
this.checkBox1.TabIndex = 3;
this.checkBox1.Text = "checkBox1";
this.checkBox1.UseVisualStyleBackColor = true; this.ClientSize = new System.Drawing.Size(202, 159);
this.Controls.Add(this.checkBox1);
this.Controls.Add(this.hScrollBar1);
this.Controls.Add(this.vScrollBar1);
this.Controls.Add(this.pictureBox1);
this.Name = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
this.PerformLayout(); }
}
picture.Image=Image.FromFile(@"c:\1.bmp");
picture.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; Panel panel =new Panel(); panel.Size=new Size(100,100);
panel.Location=new Point(0,0);
panel.AutoScroll=true;
panel.Controls.Add(picture); this.Controls.Add(panel);
不知道对你有用没