在VFP中显示图片的一个方法
附件为独立运行EXE程序,下载后将扩展名.zip删掉,有VFP9运行库即可。
test.exe.zip
(2.79 MB)
程序代码:
#INCLUDE "Const.h" CLEAR ALL CLOSE DATABASES ALL CLEAR SET SAFETY OFF goForm = CREATEOBJECT("C_Form") goForm.Show READ EVENTS CLOSE DATABASES ALL CLEAR ALL RETURN *----------------------------- * 建立图片数据库 *----------------------------- FUNCTION CreateDBF() AS Boolean LOCAL laFiles[1,5] LOCAL lnIndex LOCAL lbSuccess lbSuccess = .F. IF ADIR(laFiles, "Pictures\*.*") > 0 CREATE TABLE Pictures FREE (P01 C(20), P02 M) SELECT Pictures FOR lnIndex = 1 TO ALEN(laFiles,1) APPEND BLANK REPLACE P01 WITH PADL(lnIndex, 3, '0'), P02 WITH FILETOSTR("Pictures\" + laFiles[lnIndex,1]) NEXT USE IN Pictures lbSuccess = .T. ELSE MESSAGEBOX("图片目录中没有文件", 64) ENDIF RETURN lbSuccess ENDFUNC *----------------------------- * 主窗体 *----------------------------- DEFINE CLASS C_Form AS my_Form Caption = "测试例程" ShowWindow = 2 ADD OBJECT Grid1 AS Grid ADD OBJECT Image1 AS Image WITH Stretch = 1 PROCEDURE Load USE Pictures EXCLUSIVE IN 0 ENDPROC PROCEDURE Unload USE IN Pictures ENDPROC PROCEDURE Arrange WITH ThisForm.Grid1 .Top = 5 .Left = 5 .Height = ThisForm.Height - .Top - 5 .Width = 100 ENDWITH WITH ThisForm.Image1 .Top = 5 .Left = ThisForm.Grid1.Left + ThisForm.Grid1.Width + 5 .Height = ThisForm.Height - .Top - 5 .Width = ThisForm.Width - .Left - 5 ENDWITH ENDPROC PROCEDURE Grid1.Init WITH This .DeleteMark = .F. .RecordSourceType = 1 .RecordSource = "Pictures" .ColumnCount = 1 WITH .Columns(1) WITH .Header1 .Caption = "图片标题" .FontBold = .T. .Alignment = 2 ENDWITH .ControlSource = "Pictures.P01" .Width = 80 ENDWITH ENDWITH ENDPROC PROCEDURE Grid1.AfterRowColChange(tnColumn) WITH ThisForm.Image1 .PictureVal = Pictures.P02 ENDWITH ENDPROC ENDDEFINE *----------------------------- * 自定义窗体类 * 备注:继承窗体必须存在Arrange方法 *----------------------------- DEFINE CLASS my_Form AS Form MinWidth = 800 MinHeight = 600 AutoCenter = .T. KeyPreview = .T. PROCEDURE Activate ThisForm.Arrange ENDPROC PROCEDURE Resize ThisForm.Arrange ENDPROC PROCEDURE KeyPress(tnKeyCode, tnShiftAltCtrl) IF tnKeyCode == K_ESC RELEASE ThisForm ENDIF ENDPROC PROCEDURE Destroy CLEAR EVENTS ENDPROC ENDDEFINE
[ 本帖最后由 TonyDeng 于 2011-10-18 13:33 编辑 ]