请教GDI+编程怎么使得图像显示时可有滚动条?
显示的图像比屏幕要大,所以需要滚动条,不过问题是:
滚动条出现了,而且可以滚动,但是菜单跟着图片一起滚动了,
还没有见过这种情况呢?怎么让图像滚动而菜单不动?
具体的代码如下,谢谢:
private void InitializeComponent()
{
this.mainMenu = new System.Windows.Forms.MenuStrip();
this.fileMenu = new System.Windows.Forms.ToolStripMenuItem();
...
this.mainMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.fileMenu,this.editMenu,this.expMenu, this.viewMenu, this.helpMenu});
this.mainMenu.Location = new System.Drawing.Point(0, 0);
this.mainMenu.Name = "mainMenu";
this.mainMenu.Size = new System.Drawing.Size(992, 24);
...
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoScroll = true;
this.ClientSize = new System.Drawing.Size(992, 723);
...
}
private void fileOpen_Click(object sender, EventArgs e)
{
OpenFileDialog openDlg = new OpenFileDialog();
if (openDlg.ShowDialog() == DialogResult.OK)
{
curFileName = openDlg.FileName;
curImage = Image.FromFile(curFileName);
this.AutoScroll = true;
this.AutoScrollMinSize = new Size(
(int)(curImage.Width),(int)(curImage.Height));
this.Invalidate();
}
....
}
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
this.Invalidate();
}
....
}
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
if (curImage != null)
{
g.DrawImage(curImage, new Rectangle(this.AutoScrollPosition.X,
this.AutoScrollPosition.Y,
(int)(curRect.Width * curZoom),
(int)(curRect.Height * curZoom)));
}
g.Dispose();
}