C#窗体滚动条问题

来源:百度知道 编辑:UC知道 时间:2024/05/09 15:43:33
Bitmap bmap = new Bitmap(1300, 900);
Graphics gph = Graphics.FromImage(bmap);
我画了一个图 长1300高900

我的窗体必须长高必须是 580,580

但是要让窗体带滚动条怎么弄 高手指点下

可以加个PictureBox,然后把图片放到里面.再把窗体的AutoScroll 设成true
Bitmap bmap = new Bitmap(1300, 900);
Graphics gph = Graphics.FromImage(bmap);
gph.DrawLine(new Pen(Color.Blue), 0, 0, 100, 100);
PictureBox pb = new PictureBox();
pb.Image = bmap;
pb.Size = bmap.Size;
this.Controls.Add(pb);
this.AutoScroll = true;

progressbar不是一个滚动条的控件吗,直接用算了.如果你要用LEFT WIDTH来算也可以,可以控制窗体大小啊
在load事件里
this.maxsize=new size(580,580);
this.minsize=new size(580,580);
这样就OK了

这个有点麻烦的

加个滚动条,在它的事件里掉用Invalid...方法(方法名忘了~:P)

然后重写OnPaint方法
在方法里根据滚动条的值,在窗体上画一部分图片(具体画哪部分要根据窗体大小和滚动条的值进行计算),造成滚动的效果

在《C#高级编程》上有例子,以前做的,记不清了~

给你个例子,图片名字和窗口尺寸自己换掉
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

public class Sizer : System.Windows.Forms.Form {
private System.Windows.Forms.PictureBox picCritter;
private Sy