|
-
December 1st, 2000, 02:48 PM
#1
How to create Image control at run time?
hello,
how do i use createobject to create an image control in vb? i cant find the type name of the object
thanks,
p
-
December 1st, 2000, 03:36 PM
#2
Re: How to create Image control at run time?
With controls you should use Controls.Add, not createobject. Most VB controls cannot be created like other objects, because they require some container (e.g. form).
private Sub Form_Load()
Dim i as Integer, ctl as Image
for i = 0 to 10
set ctl = Controls.Add("VB.Image", "ctl" & i)
ctl.Move i * 500 + 60, 60 * i
set ctl.Picture = me.Icon
ctl.Visible = true
next
End Sub
-
December 1st, 2000, 03:44 PM
#3
Re: How to create Image control at run time?
will this work inside a COM object? my goal is to get the width and height of .gifs.
-
December 1st, 2000, 04:00 PM
#4
Re: How to create Image control at run time?
>will this work inside a COM object?
Yes, if your COM object has some control container - form, user control.
You don't need a control to measure picture.
Dim pic As StdPicture
Set pic = LoadPicture("c:\picture.gif")
MsgBox pic.Height & " " & pic.Width
I think dimensions are not in pixels ... I'll check this later.
-
December 1st, 2000, 04:17 PM
#5
Re: How to create Image control at run time?
Dimensions in pixels, without image control:
Dim pic as StdPicture
set pic = LoadPicture("c:\aper6.bmp")
MsgBox "width=" & ScaleX(pic.Width, vbHimetric, vbPixels) & " pixels" & _
vbCrLf & "height=" & ScaleX(pic.Height, vbHimetric, vbPixels) & " pixels"
-
December 1st, 2000, 04:25 PM
#6
Re: How to create Image control at run time?
kick ***! thanks a lot!!!!
-
December 1st, 2000, 06:44 PM
#7
Re: How to create Image control at run time?
... or, if you don't want to use an image control to capture this information ....
option Explicit
'
' Copy this into a separate BAS Module - or change the 'publics' to
' their relevant types
'
public Type BITMAPINFO ' used simply to identify the size of the picture
Width as Long
Height as Long
End Type
'
public Function GetGIFInfo(byval FileName as string) as BITMAPINFO
Dim bChar as Byte
Dim i as Integer
Dim DotPos as Integer
Dim Header as string
Dim blExit as Boolean
Dim a as string, b as string
Dim ImgWidth as Integer
Dim ImgHeight as Integer
Dim ImgSize as string
Dim fnum as Integer
Dim ImageInfo as BITMAPINFO
'
on error resume next
fnum = FreeFile
Open FileName for binary as #fnum
'
ImgSize = LOF(fnum) / 1024
'
DotPos = InStr(ImgSize, ",")
ImgSize = Left(ImgSize, DotPos - 1)
'
for i = 0 to 5
get #fnum, , bChar
Header = Header + Chr(bChar)
next i
'
If Left(Header, 3) <> "GIF" then
MsgBox FileName & ": not a GIF file"
Close #fnum
Exit Function
End If
'
get #fnum, , bChar
a = a + Chr(bChar)
get #fnum, , bChar
a = a + Chr(bChar)
'
ImgWidth = CInt(Asc(Left(a, 1)) + 256 * Asc(Right(a, 1)))
'
get #fnum, , bChar
b = b + Chr(bChar)
get #fnum, , bChar
b = b + Chr(bChar)
'
ImgHeight = CInt(Asc(Left(b, 1)) + 256 * Asc(Right(b, 1)))
'
Close #fnum
'
With ImageInfo
.Width = ImgWidth
.Height = ImgHeight
End With
'
GetGIFInfo = ImageInfo
End Function
Chris Eastwood
CodeGuru - the website for developers
http://codeguru.developer.com/vb
-
December 1st, 2000, 07:12 PM
#8
Re: How to create Image control at run time?
Reading first 10 bytes from file is certainly much faster than using StdPicture.
I didn't expect that simple header. Thanks for great info!
-
December 1st, 2000, 07:14 PM
#9
Re: How to create Image control at run time?
I completely forgot about that piece of code (it's not mine) - I found it on the VB newsgroups about 2 years ago !
Very useful information though - I've got some similar code that does the same for BMP files - probably worth posting to the site at some point.
Chris Eastwood
CodeGuru - the website for developers
http://codeguru.developer.com/vb
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|