Click to See Complete Forum and Search --> : getting Icon property causes form load
Lothar Haensler
July 26th, 1999, 08:13 AM
In my about box I want to display the same icon that is used for the main formwindow.
Thus, I coded
Sub Form_Load()
picIcon.Icon = frmmain.Icon
End Sub
in the frm module of my about box.
This works, of course, but it causes the main form to load again.
In fact, even printing "?frmmain.icon" in the immediate window causes the form window to be loaded again.
I use VB 6 and SP 2.
Yes, I could load the same Icon into the picture box of my about box, but that's not really what I want, because then I'd have to change the icon twice, whenever I decide to change it.
Any hints?
Dr_Michael
July 26th, 1999, 08:47 AM
Whenever you reference on a control of a form then be sure that this form will be loaded if not. So if you don't wish this to happen you must NOT reference to this form. For example: If you would like to get a value from a textbox, you should pass this value to a public variable and then just reference to this public variable. In this case we don't talk about values but about icons, so I don't have an answer right now, but I'll try some ideas and let you informed...
Michael Vlastos
Company MODUS SA
Development Department
Athens, Greece
Tel: +3-01-9414900
Lothar Haensler
July 26th, 1999, 08:53 AM
Ok, I forgot to mention that frmMain is of course the first form that's loaded.
So, before I reach the statement in the about box form, frmMain is loaded already. That's why I get to instances of that form.
Chris Eastwood
July 26th, 1999, 09:04 AM
Hi Lothar
It's happening because you are explicitly referencing the physical class name of the Form, not the instance name of the form, eg:
'
' Global instance of frmMain - this is in a Code Module
'
Dim gfrmMain as frmMain
'
Sub Main()
set gfrmMain = new frmMain
Load gfrmMain
gfrmMain.Show
End Sub
You could then use your existing code to point to 'gfrmMain' to get the icon.
You could instead, pass in the Picture Property of the frmMain icon into your about box - eg.
Sub Button_Click() ' or what ever
Dim oFrmAbout as frmAbout
set oFrmAbout = new frmAbout
Load oFrmAbout
set oFrmAbout.AboutIcon = me.Icon
oFrmAbout.Show vbModal
End Sub
.. Where in your frmAbout you have a routine :
public property set AboutIcon(oPic as Picture)
set me.Icon = oPic
End property
- works fine here !
Chris Eastwood
CodeGuru - the website for developers
http://www.codeguru.com/vb
Lothar Haensler
July 26th, 1999, 09:11 AM
Ok, you are right - as always :-)
- thanks.
Still, I hate globals.
picIcon.picture = Forms(1).icon
...works, too.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.