我想在command中放置图片,但又想在上面显示不同的字,请问除了在做图片的时候叠加文字外,能直接将它caption中的内容和图片叠加到一起吗?

解决方案 »

  1.   

    很久没碰VB,记得好像是可以。如果不行,可以用API把文字绘到按钮上。
      

  2.   

    其实很简单,用扩展控件Forms 2.0 Object Librayr中的CommandButton控件,图片和按钮一样大,在图片上打上文字即可(用动态更换的办法,文字可以用GDI+绘制)。
      

  3.   

    GDI+绘制的貌似不好,因为一旦刷新一下,图片就没有了,你还得重绘,这样会有闪烁感的
      

  4.   

    经过测试,简单几行即OK了:
    Option Explicit
    'Form1上添加一个图片框控件Picture1,一个命令按钮Command1
    Private Sub Form_Load()
        
       Picture1.Picture = LoadPicture("F:\资料\My Pictures\2006Spring2-西湖美景.jpg")
       Command1.Caption = "我的图片按钮"
       
       Picture1.AutoRedraw = True
       With Picture1.Font
            .Name = Command1.Caption
            .Bold = True
            .Size = 24
       End With
       
       Picture1.CurrentX = (Picture1.Width - Picture1.TextWidth(Command1.Caption)) / 2
       Picture1.CurrentY = (Picture1.Height - Picture1.TextHeight(Command1.Caption)) / 2
       Picture1.ForeColor = RGB(255, 255, 255)
       Picture1.Print Command1.Caption
       
       Command1.Caption = ""
       Set Command1.Picture = Picture1.Image
       
    End Sub
    效果图如下:
      

  5.   

    这行.Name = Command1.Caption 改成: .Name = "宋体" 
      

  6.   

    的确,使用 Forms 2.0 Object Librayr 中的 CommandButton 控件,可以使这个问题简单化。