Shared Picturebox?

scorpin

Newcomer
Joined
Oct 6, 2003
Messages
24
Can i share a picture box so i can access it from other modules? i am getting my *** kicked? how do i do it?
 
I want to make a picturebox on a form 'shared' so i can pass it into my d3d class, from another module

I have it working now, i editied the designer generated code for the picturebox i changed 'friend' to 'public shared', so it works, but when i am in the form designer window its not shown, and i have a caution thing down in the buiild error/debug window that says "the variable 'PicX' is either undeclared or was never assigned'

but when i run my program it is present

then when i go and edit anything on the form designed the picture box is deleated
 
Last edited:
You don't need to make the control "shared"... this means something totally different
than how you're using it. Just make the control Public. You can change this scope in
design view under the property "Modifiers."
 
well when its public it outputs the error
"Reference to a non-shared member requires an object refernce"

what does that mean? and by the way object is longer passed and the program dosnt work
 
Ah, I see your dilema. The way you're handling form variables is probably in the VB6
style, but the name of the game has changed in VB.NET. You need to pass an
initialized instance of your first form to your method.

For example, to access Form1.TextBox1 from Moo(), I need to pass the form as a parameter.

Visual Basic:
' Your method in some other module:
Public Sub Moo(callingForm As Form1)
  callingForm.TextBox1.Text = "Whatever"
End Sub

' And on Form1:
SomeOtherClass.Moo(Me)

I hate to plug, but here's a tutorial on passing form instances between each other.
 
this is the constructor for my class
Public Sub New(ByVal Target As System.Windows.Forms.PictureBox)

this is where the class is declared (module1)
Public Graphics As New Squid3D9(Form1.PicX)

the picture box resides in form1, as a public it will not work, it must be a shared public for it to work, but if i change anything on the form it erases my picturebox
 
i replaced the declaration in the module with Public Graphics As New Squid3D9(Form1.PicX As System.Windows.Forms.PictureBox)

that works, but i get an error down in my debug "Comma, ')', or a valid expression continuation expected." its considered a build error by the compiler and gives me an option to continue, i can also leave it as Public Graphics As New Squid3D9(Form1.PicX)

it works if i continue from the build error... but build errors are bad
 
Did you name the Form 'Form1' though - if so that is the class name - you need to declare an instance of the form; I recomend reading through the tutorial bucky posted above to get a better understanding as these things have changed drastically since VB6.
 
well i changed my code, so when the module sub is called from the form load it passes the picturebox in... not what i wanted but it works with out error
 
Last edited:
Back
Top