CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 1999
    Posts
    3,332

    getting Icon property causes form load

    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?


  2. #2
    Join Date
    Jul 1999
    Location
    Athens, Hellas
    Posts
    769

    Re: getting Icon property causes form load

    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

  3. #3
    Join Date
    May 1999
    Posts
    3,332

    Re: getting Icon property causes form load

    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.


  4. #4
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: getting Icon property causes form load

    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

  5. #5
    Join Date
    May 1999
    Posts
    3,332

    Re: getting Icon property causes form load

    Ok, you are right - as always :-)
    - thanks.
    Still, I hate globals.

    picIcon.picture = Forms(1).icon




    ...works, too.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured