reference a picturebox in Form2

  • Thread starter Thread starter makai
  • Start date Start date
M

makai

Guest
In VB6 no problem

from Form1:
Form2.Picture1.Picture = LoadPicture("c:\my.jpg")

in .Net you can't even reference Form2.Picture1

why not? (I know it is declared as Friend - how do you fix it so you can reference it from another form?)
 
Wyrd : It does not work if the form is already loaded.
It will operate the changes on a virtual form that can't be shown twice.
I am stuck with the same problem and this is starting to give me headache
 
My guess is that you're declaring it and creating your instance in the same method/event handler. If that's the case, just declare the variable for form2 outside the routine you create the instance with. Sounds like your pointer to form2 is out of scope when that routine completes. Something like this...
Visual Basic:
Class form1
 Inherits Form
  Private frm2 As Form2

  Sub CreateForm2()
    frm2 = New Form2
  End Sub

  Sub ChangeForm2()
   frm2.Picture1.Picture = LoadPicture("c:\my.jpg")
  End Sub
End Class
 
There is certainly something I don't understand...

Dim frm as new Form1

frm.setheight(200)

The code does not generates any error but they are no changes made on the hieght of the form.
I declared my function Public and Friend on Form1 with no results...Does this have something to do with NEW Keywork ?
I created Form2 from Form1 :

Dim frm as new Form2

frm.ShowDialog()

Is there any parameter I am missing ?
Please note that Form1 is an MDI Parent form and that form2 is a modal form used to log to the program ( username, password )

thx !
 
I tried it any possible way, nothing works ! :(
Actually, I led. I am not trying to update the height of FOrm1 but trying to set the menu item enabled property ti true once the log when username and password.
I looked in my debugger, they all convert to enabled = True but no changes occurs
My thoughts are that I am operating the changes only on a virtual version of FOrm1 :(
 
Here it is :)

In my MDIForm

Public Class MDIForm1
Inherits System.Windows.Forms.Form

Private tmpLogin As frmConnexion

(...)


Private Sub mnuConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuConnect.Click
tmpLogin = New frmConnexion()
tmpLogin.ShowDialog()

(...)

In my frmConnexion :

Public Class frmConnexion
Inherits System.Windows.Forms.Form
Private tmpMDIForm As MDIForm1

(...)

BUtton1_click

tmpMDIForm = New MDIForm1()
tmpMDIForm.EnableMenus()
Me.Close()

(...)
 
Visual Basic:
Public Class MDIForm1
Inherits System.Windows.Forms.Form

Private tmpLogin As frmConnexion

(...)


Private Sub mnuConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuConnect.Click
tmpLogin = New frmConnexion()
'Add a reference to the parent since you're using
'  ShowDialog, I don't think you can do it using the 
'  normal mdiparent/child relationship.
tmpLogin.tmpMDIForm = Me
tmpLogin.ShowDialog()

(...)

In my frmConnexion :

Public Class frmConnexion
Inherits System.Windows.Forms.Form
Private tmpMDIForm As MDIForm1

(...)

BUtton1_click
'commented new stuff.  if it helps, your hunch was correct.
' your creating a whole new form that never gets shown. 
'tmpMDIForm = New MDIForm1()

tmpMDIForm.EnableMenus()
Me.Close()

(...)
 
Yes yes yes :)
The only change I made was to declare tmpMDIForm Public instead of private.
Thanx for taking the time to go through all this.
As a VB6 user, I am having some trouble to get acclimated to my new environment :)
Your help was welcomed ;)
 
Back
Top