在VB中,Picturebox控件可以根据picturebox的大小来显示完整的图片吗?当单击任意图片框时,生成一个新的picturebox并显示图片的实际大小?

解决方案 »

  1.   

    如果想根据图片的大小来调整picturebox的大小,可以设置picturebox的autosize属性为true
    如果要根据picturebox的大小来调整图片大小以显示完整的图片,可以这样 
    Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
    Private Sub Command1_Click()
    StretchBlt Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Picture2.hdc, 0, 0, Picture2.ScaleWidth, Picture2.ScaleHeight, vbSrcCopy
    End Sub
    其中picture2是第一种方法岁所得到的图片。
      

  2.   

    打开PICTUREBOX的AUTOSIZE属性就好。
      

  3.   

    可以搞两个picture控件,一个隐藏,一个显示,先把图像调入到隐藏的那个picture控件中间,然后通过图像复制的缩小来把图像复制到第二个控件里面
      

  4.   

    laviewpbt(人一定要靠自己)的方法不错,有没有只用一个picturebox控件的方法。我想实现图像浏览的功能。请指教
      

  5.   

    浏览的话应该在图片大于picture框的时候添加滚动条比较好这样的代码多的是
    http://community.csdn.net/Expert/topic/3318/3318669.xml?temp=.8738062
      

  6.   

    也可以,不过理论上速度慢一点
    Private Sub Command1_Click()
    Picture2.PaintPicture Picture1, 0, 0, Picture2.Width, Picture2.Height, 0, 0, Picture1.Width, Picture1.Height, vbSrcCopy
    End Sub
      

  7.   

    谢谢各位了,问题解决了。Image控件就可以了。谢了