pictureBox滚动 去 msdn 查ScrollBar , 里面有解决问题的例子 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 把PictureBox 放到一个 Panel里面, 设置PictureBox的父控件为那个Panel,然后Panel的AutoScroll属性为true 我的ScrollBar是放在了里面好使,仅供参考:private void pictureBox2_DoubleClick(object sender, System.EventArgs e) { if(openFileDialog1.ShowDialog() != DialogResult.Cancel) { pictureBox2.Image = Image.FromFile(openFileDialog1.FileName); this.DisplayScrollBars(); this.SetScrollBarValues(); } } public void DisplayScrollBars() { if (pictureBox2.Width > pictureBox2.Image.Width - this.vScrollBar1.Width) { hScrollBar2.Visible = false; } else { //在picturebox控件中添加一个水平滚动条 pictureBox2.Controls.Add (hScrollBar2); hScrollBar2.Left =0; hScrollBar2.Width =pictureBox2.Width ; hScrollBar2.Dock =System.Windows .Forms .DockStyle .Bottom ; hScrollBar2.Visible = true; } if (pictureBox2.Height > pictureBox2.Image.Height - this.hScrollBar2.Height) { vScrollBar2.Visible = false; } else { //在picturebox控件中添加一个垂直滚动条 pictureBox2.Controls.Add (vScrollBar2); vScrollBar2.Top =0; vScrollBar2.Height =pictureBox2.Height ; vScrollBar2.Dock =System.Windows .Forms .DockStyle.Right; vScrollBar2.Visible = true; } } public void SetScrollBarValues() { this.vScrollBar2.Minimum = 0; this.hScrollBar2.Minimum = 0; if( (this.pictureBox2.Image.Size.Width - pictureBox2.ClientSize.Width) > 0) { this.hScrollBar2.Maximum = this.pictureBox2.Image.Size.Width - pictureBox2.ClientSize.Width; } if(this.vScrollBar2.Visible) { this.hScrollBar2.Maximum += this.vScrollBar2.Width; } this.hScrollBar2.LargeChange = this.hScrollBar2.Maximum / 10; this.hScrollBar2.SmallChange = this.hScrollBar2.Maximum / 20; this.hScrollBar2.Maximum += this.hScrollBar2.LargeChange; if( (this.pictureBox2.Image.Size.Height - pictureBox2.ClientSize.Height) > 0) { this.vScrollBar2.Maximum = this.pictureBox2.Image.Size.Height - pictureBox2.ClientSize.Height; } if(this.hScrollBar2.Visible) { this.vScrollBar2.Maximum += this.hScrollBar2.Height; } this.vScrollBar2.LargeChange = this.vScrollBar2.Maximum / 10; this.vScrollBar2.SmallChange = this.vScrollBar2.Maximum / 20; this.vScrollBar2.Maximum += this.vScrollBar2.LargeChange; } private void HandleScroll(Object sender, ScrollEventArgs se) { Graphics g = pictureBox2.CreateGraphics(); g.DrawImage(pictureBox2.Image, new Rectangle(0, 0, pictureBox2.Right - vScrollBar2.Width,pictureBox2.Bottom - hScrollBar2.Height), new Rectangle(hScrollBar2.Value, vScrollBar2.Value,pictureBox2.Right - vScrollBar2.Width,pictureBox2.Bottom - hScrollBar2.Height), GraphicsUnit.Pixel); pictureBox2.Update(); } 鼠标模拟问题急问 多线程访问数据库 请教一个C#读串口的问题 问个linq to sql 的 怎样用循环对Session赋值 一个窗体继承产生的问题! 請教:怎樣返回存儲過程的多個輸出字段字段 C#中的重难点(2) C#编码标准--编码习惯 使用C#调用GDAL的OGR读取s57文件,中文乱码问题 sqlDataAdpter 的parameter的问题!急需解决! 请教使用参数的oledbcommand时,怎么能看到最终向数据库中执行的sql? 关于dataGrid中显示记录的问题???(急)
private void pictureBox2_DoubleClick(object sender, System.EventArgs e)
{
if(openFileDialog1.ShowDialog() != DialogResult.Cancel)
{
pictureBox2.Image = Image.FromFile(openFileDialog1.FileName);
this.DisplayScrollBars();
this.SetScrollBarValues();
} } public void DisplayScrollBars()
{
if (pictureBox2.Width > pictureBox2.Image.Width - this.vScrollBar1.Width)
{
hScrollBar2.Visible = false;
}
else
{
//在picturebox控件中添加一个水平滚动条
pictureBox2.Controls.Add (hScrollBar2);
hScrollBar2.Left =0;
hScrollBar2.Width =pictureBox2.Width ;
hScrollBar2.Dock =System.Windows .Forms .DockStyle .Bottom ;
hScrollBar2.Visible = true;
}
if (pictureBox2.Height > pictureBox2.Image.Height - this.hScrollBar2.Height)
{
vScrollBar2.Visible = false;
}
else
{
//在picturebox控件中添加一个垂直滚动条
pictureBox2.Controls.Add (vScrollBar2);
vScrollBar2.Top =0;
vScrollBar2.Height =pictureBox2.Height ;
vScrollBar2.Dock =System.Windows .Forms .DockStyle.Right;
vScrollBar2.Visible = true;
}
}
public void SetScrollBarValues()
{
this.vScrollBar2.Minimum = 0;
this.hScrollBar2.Minimum = 0;
if( (this.pictureBox2.Image.Size.Width - pictureBox2.ClientSize.Width) > 0)
{
this.hScrollBar2.Maximum = this.pictureBox2.Image.Size.Width - pictureBox2.ClientSize.Width;
}
if(this.vScrollBar2.Visible)
{
this.hScrollBar2.Maximum += this.vScrollBar2.Width;
}
this.hScrollBar2.LargeChange = this.hScrollBar2.Maximum / 10;
this.hScrollBar2.SmallChange = this.hScrollBar2.Maximum / 20;
this.hScrollBar2.Maximum += this.hScrollBar2.LargeChange;
if( (this.pictureBox2.Image.Size.Height - pictureBox2.ClientSize.Height) > 0)
{
this.vScrollBar2.Maximum = this.pictureBox2.Image.Size.Height - pictureBox2.ClientSize.Height;
}
if(this.hScrollBar2.Visible)
{
this.vScrollBar2.Maximum += this.hScrollBar2.Height;
}
this.vScrollBar2.LargeChange = this.vScrollBar2.Maximum / 10;
this.vScrollBar2.SmallChange = this.vScrollBar2.Maximum / 20;
this.vScrollBar2.Maximum += this.vScrollBar2.LargeChange;
} private void HandleScroll(Object sender, ScrollEventArgs se)
{
Graphics g = pictureBox2.CreateGraphics();
g.DrawImage(pictureBox2.Image,
new Rectangle(0, 0, pictureBox2.Right - vScrollBar2.Width,pictureBox2.Bottom - hScrollBar2.Height),
new Rectangle(hScrollBar2.Value, vScrollBar2.Value,pictureBox2.Right - vScrollBar2.Width,pictureBox2.Bottom - hScrollBar2.Height),
GraphicsUnit.Pixel);
pictureBox2.Update();
}