如何让图片实时滚动? 请问大伙儿如和让pictruebox里的图片随着滚动条滚动而滚动图片。(picturebox放在panel里面的),谢谢各位啊! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 PictureBox没有这个功能,你需要自已定义一个这样的控件,可以参考下面的代码:public class ImageCtr : ScrollableControl{ private Image m_Img; public Image Img { get { return m_Img; } set { if (value != this.m_Img) { m_Img = value; if (this.m_Img != null) { this.AutoScrollMinSize = this.m_Img.Size; } else { this.AutoScrollMinSize = Size.Empty; } this.Invalidate(); } } } public ImageCtr() { this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer, true); } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (this.m_Img != null) { e.Graphics.DrawImage(this.m_Img, this.AutoScrollPosition.X, this.AutoScrollPosition.Y, this.m_Img.Width, this.m_Img.Height); } } protected override void OnPrint(PaintEventArgs e) { if (this.m_Img != null) { e.Graphics.DrawImage(this.m_Img, 0, 0, this.m_Img.Width, this.m_Img.Height); } }} panel的autoscroll属性设置成truepicturebox的location设置成0,0 size设置成1,1 sizemode设置成autosize if (是Windows应用程序){ 我的意思是在显示一个大的图片需要使用滚动条的时候可以不必使用PictureBox,因为这 个控件不能很好的支持滚动功能,可以按我上面的代码做一个显示图片的控件,这个控件 是带自动滚动条的。试试便知。更没有必要放到一个Panel控件里来模拟这个效果。}else{ 算我没有说。} hbxtlhx(平民百姓-自已动手,丰衣足食)但是你这个控件并不能达到实时滚动的效果啊 。OMG,原来这么简单~那弱弱的问下怎么通过代码来实现这个呢。。 是拖动时显示窗口内容这个功能吗?那只能是调用API了。不过最好不改,尊重客户原来的习惯。 可是为什么有的程序我没有将“拖动时显示窗口内容”选上它还是能拖动时显示呢,比如说Windows自带的画图程序。 自定义一个panel,重写WndProc方法public class MyPanel : System.Windows.Forms.Panel{ protected override void WndProc(ref Message m) { System.Drawing.Point p = new Point(); if ((m.Msg & 0x114) == 0x114) { int i = (m.WParam.ToInt32() >> 16); if ((m.WParam.ToInt32() & 0xffff) == 5) { if (m.Msg == 0x114) p.X = i; else p.Y = i; this.AutoScrollPosition = p; } } base.WndProc (ref m); }}在Form中拖一个panel控件,再拖一个picturebox控件放入panel中属性如下设置panel的autoscroll属性设置成truepicturebox的location设置成0,0 size设置成1,1 sizemode设置成autosize将代码中的panel的定义和实例化代码改掉private System.Windows.Forms.Panel panel1;改为private MyPanel panel1;this.panel1 = new System.Windows.Forms.Panel();改为this.panel1 = new MyPanel(); 如果要做成这样的,那么就要使用Scrollbar控件了,然后在滚动条的事件Scroll里编写代码。但是对于标准的Windows来说,默认的应该就是按用户的设置来的。 如果要自己添加ScrollBar控件,那么处理的问题可能很多,比如可能要滚动窗口,可能使用ScrollWindow这个API,要计算滚动的位置大小等等一系统问题。但对于默认的滚动条则简单的多了。 非常感谢 hbxtlhx 祝你工作愉快! checkbox为啥 我的状态设置为true了以后还是没有小勾 在小方框里只有绿色 vs2005form中dataGridView的内容怎么打印 asp.net局部刷新updatepanel哪里有问题? 怎么样把几张表,汇总到一张表中,求一SQL语句,这次的确是有点急了,啊,主呀,帮帮我吧~` 请教! Word转Pdf 如何用vb.net 调用C#的dll 在visual.net上无法调试存储过程。急。求救 请问如何在iis服务启动时执行一个后台的应用程序? 如何双方取得焦点 关于request. 为何要用单件?
{
private Image m_Img; public Image Img
{
get { return m_Img; }
set
{
if (value != this.m_Img)
{
m_Img = value;
if (this.m_Img != null)
{
this.AutoScrollMinSize = this.m_Img.Size;
}
else
{
this.AutoScrollMinSize = Size.Empty;
}
this.Invalidate();
}
}
}
public ImageCtr()
{
this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer, true);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if (this.m_Img != null)
{
e.Graphics.DrawImage(this.m_Img, this.AutoScrollPosition.X, this.AutoScrollPosition.Y, this.m_Img.Width, this.m_Img.Height);
}
}
protected override void OnPrint(PaintEventArgs e)
{
if (this.m_Img != null)
{
e.Graphics.DrawImage(this.m_Img, 0, 0, this.m_Img.Width, this.m_Img.Height);
}
}
}
picturebox的location设置成0,0
size设置成1,1
sizemode设置成autosize
{
我的意思是在显示一个大的图片需要使用滚动条的时候可以不必使用PictureBox,因为这
个控件不能很好的支持滚动功能,可以按我上面的代码做一个显示图片的控件,这个控件
是带自动滚动条的。试试便知。更没有必要放到一个Panel控件里来模拟这个效果。
}
else
{
算我没有说。
}
但是你这个控件并不能达到实时滚动的效果啊
那弱弱的问下怎么通过代码来实现这个呢。。
{
protected override void WndProc(ref Message m)
{
System.Drawing.Point p = new Point();
if ((m.Msg & 0x114) == 0x114)
{
int i = (m.WParam.ToInt32() >> 16);
if ((m.WParam.ToInt32() & 0xffff) == 5)
{
if (m.Msg == 0x114)
p.X = i;
else
p.Y = i;
this.AutoScrollPosition = p;
}
}
base.WndProc (ref m);
}}在Form中拖一个panel控件,再拖一个picturebox控件放入panel中
属性如下设置
panel的autoscroll属性设置成true
picturebox的location设置成0,0
size设置成1,1
sizemode设置成autosize将代码中的panel的定义和实例化代码改掉private System.Windows.Forms.Panel panel1;改为
private MyPanel panel1;this.panel1 = new System.Windows.Forms.Panel();改为
this.panel1 = new MyPanel();