如何让图片实时滚动?

Mars感知 2007-09-04 01:06:08
请问大伙儿如和让pictruebox里的图片随着滚动条滚动而滚动图片。(picturebox放在panel里面的),谢谢各位啊!
...全文
281 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
Mars感知 2007-09-04
  • 打赏
  • 举报
回复
同样非常感谢 a523194491 祝你工作愉快!
Mars感知 2007-09-04
  • 打赏
  • 举报
回复
非常感谢 hbxtlhx 祝你工作愉快!
北京的雾霾天 2007-09-04
  • 打赏
  • 举报
回复
如果要自己添加ScrollBar控件,那么处理的问题可能很多,比如可能要滚动窗口,可能使用ScrollWindow这个API,要计算滚动的位置大小等等一系统问题。但对于默认的滚动条则简单的多了。
北京的雾霾天 2007-09-04
  • 打赏
  • 举报
回复
如果要做成这样的,那么就要使用Scrollbar控件了,然后在滚动条的事件Scroll里编写代码。但是对于标准的Windows来说,默认的应该就是按用户的设置来的。
a523194491 2007-09-04
  • 打赏
  • 举报
回复
自定义一个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属性设置成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();
Mars感知 2007-09-04
  • 打赏
  • 举报
回复
可是为什么有的程序我没有将“拖动时显示窗口内容”选上它还是能拖动时显示呢,比如说Windows自带的画图程序。
北京的雾霾天 2007-09-04
  • 打赏
  • 举报
回复
是拖动时显示窗口内容这个功能吗?

那只能是调用API了。不过最好不改,尊重客户原来的习惯。
Mars感知 2007-09-04
  • 打赏
  • 举报
回复
。。。。OMG,原来这么简单~
那弱弱的问下怎么通过代码来实现这个呢。。
北京的雾霾天 2007-09-04
  • 打赏
  • 举报
回复
你查看一下你的系统是这样的设置吗:

1:在桌面上点右键弹出桌面属性对话框
2:切换到“外观页”,点“效果”按钮
3:查看是否“拖动时显示窗口内容”为未选状态,如果未选,选上就是实时的了。如果不想这么设置,那么可能要手动的来管理滚动条了。
Mars感知 2007-09-04
  • 打赏
  • 举报
回复
hbxtlhx(平民百姓-自已动手,丰衣足食)
但是你这个控件并不能达到实时滚动的效果啊
Mars感知 2007-09-04
  • 打赏
  • 举报
回复
实时滚动啊实时啊
北京的雾霾天 2007-09-04
  • 打赏
  • 举报
回复
if (是Windows应用程序)
{
我的意思是在显示一个大的图片需要使用滚动条的时候可以不必使用PictureBox,因为这
个控件不能很好的支持滚动功能,可以按我上面的代码做一个显示图片的控件,这个控件
是带自动滚动条的。试试便知。更没有必要放到一个Panel控件里来模拟这个效果。
}
else
{
算我没有说。
}
a523194491 2007-09-04
  • 打赏
  • 举报
回复
panel的autoscroll属性设置成true
picturebox的location设置成0,0
size设置成1,1
sizemode设置成autosize
Mars感知 2007-09-04
  • 打赏
  • 举报
回复
1楼的或许没搞清楚问题,我要的是跟浏览器一样滚动的同时滚动内容,是同时哦~
sadever 2007-09-04
  • 打赏
  • 举报
回复
学习!帮顶
best8625 2007-09-04
  • 打赏
  • 举报
回复
路过
北京的雾霾天 2007-09-04
  • 打赏
  • 举报
回复
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);
}
}
}

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧