Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to display any picture format on a form

Graphics

How to display any picture format on a form

by  Mike Gagnon  Posted    (Edited  )
This requires the Imaging Control Activex that shipped with Win95 and up. Cut and paste this code into a program and run.

Code:
PUBLIC frmImage
frmMyForm = CREATEOBJECT('images_demo')  && Create a Form
frmMyForm.SHOW()  && Display the form
READ EVENTS
DEFINE CLASS images_demo AS FORM
	AUTOCENTER = .T.
	TOP = 0
	LEFT = 19
	HEIGHT =450
	WIDTH = 485
	DOCREATE = .T.
	CAPTION = "Show picture demo"
	NAME = "Form1"
	ADD OBJECT command2 AS COMMANDBUTTON WITH ;
		TOP = 372, ;
		LEFT = 26, ;
		HEIGHT = 34, ;
		WIDTH = 431, ;
		CAPTION = "Select Image file to show", ;
		NAME = "Command2"
	ADD OBJECT optiongroup1 AS OPTIONGROUP WITH ;
		AUTOSIZE = .F., ;
		BUTTONCOUNT = 4, ;
		VALUE = 1, ;
		HEIGHT = 27, ;
		LEFT = 26, ;
		TOP = 339, ;
		WIDTH = 431, ;
		NAME = "Optiongroup1", ;
		Option1.CAPTION = "Best fit", ;
		Option1.VALUE = 1, ;
		Option1.HEIGHT = 17, ;
		Option1.LEFT = 5, ;
		Option1.TOP = 5, ;
		Option1.WIDTH = 55, ;
		Option1.AUTOSIZE = .T., ;
		Option1.NAME = "Option1", ;
		Option2.CAPTION = "Fit to width", ;
		Option2.HEIGHT = 17, ;
		Option2.LEFT = 98, ;
		Option2.TOP = 5, ;
		Option2.WIDTH = 76, ;
		Option2.AUTOSIZE = .T., ;
		Option2.NAME = "Option2", ;
		Option3.CAPTION = "Fit to height", ;
		Option3.HEIGHT = 17, ;
		Option3.LEFT = 215, ;
		Option3.TOP = 5, ;
		Option3.WIDTH = 81, ;
		Option3.AUTOSIZE = .T., ;
		Option3.NAME = "Option3", ;
		Option4.CAPTION = "Actual size", ;
		Option4.HEIGHT = 17, ;
		Option4.LEFT = 330, ;
		Option4.TOP = 5, ;
		Option4.WIDTH = 76, ;
		Option4.AUTOSIZE = .T., ;
		Option4.NAME = "Option4"
	ADD OBJECT label1 AS LABEL WITH ;
		AUTOSIZE = .T., ;
		CAPTION = "Height", ;
		HEIGHT = 17, ;
		LEFT = 254, ;
		TOP = 412, ;
		VISIBLE = .F., ;
		WIDTH = 38, ;
		NAME = "Label1"
	ADD OBJECT label2 AS LABEL WITH ;
		AUTOSIZE = .T., ;
		CAPTION = "Width", ;
		HEIGHT = 17, ;
		LEFT = 381, ;
		TOP = 410, ;
		VISIBLE = .F., ;
		WIDTH = 33, ;
		NAME = "Label2"
	PROCEDURE INIT
	THISFORM.ADDOBJECT('olecontrol1','OleControl','Imaging.EditCtrl.1')
	THISFORM.olecontrol1.TOP = 2
	THISFORM.olecontrol1.LEFT = 26
	THISFORM.olecontrol1.HEIGHT = 333
	THISFORM.olecontrol1.WIDTH = 431
	THISFORM.olecontrol1.NAME = "Olecontrol1"
	THISFORM.olecontrol1.VISIBLE = .T.

	IF !EMPTY(THISFORM.olecontrol1.IMAGE) AND FILE(THISFORM.olecontrol1.IMAGE)
		THISFORM.olecontrol1.DISPLAY
	ENDIF
ENDPROC

	PROCEDURE DESTROY
	THISFORM.REMOVEOBJECT("olecontrol1")
	DODEFAULT()
	RELEASE ALL
	CANC
ENDPROC

	PROCEDURE command2.CLICK
	LOCAL lcFile
	m.lcFile = GETPICT()
	IF FILE(m.lcFile)
		THISFORM.olecontrol1.IMAGE = m.lcFile
		THISFORM.olecontrol1.DISPLAY
	ENDIF
ENDPROC
	PROCEDURE optiongroup1.CLICK
	THISFORM.olecontrol1.FitTo(THIS.VALUE-1)
ENDPROC
ENDDEFINE

Mike Gagnon

Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top