Jump to content
Xtreme .Net Talk

reference a picturebox in Form2


Recommended Posts

Posted

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?)

  • 2 months later...
Posted

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

What I don't know keeps me excited...
  • Leaders
Posted

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...

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


--tim
Posted

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 !

What I don't know keeps me excited...
Posted

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 :(

What I don't know keeps me excited...
Posted
I did some other tests and my feelings were right. The enabled property on Form1 is still false even if it gives me true when setting it to true in Form2
What I don't know keeps me excited...
Posted

Yes, I am setting it before calling for the changes...

DO I have to delcare MDIForm as Public Shared or something and if so, how can I do that ?

 

thx

What I don't know keeps me excited...
Posted

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()

 

(...)

What I don't know keeps me excited...
  • Leaders
Posted
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()

(...)

--tim
Posted

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 ;)

What I don't know keeps me excited...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...