Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

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

Edited by scorpin
  • *Experts*
Posted

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

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Posted

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

  • *Experts*
Posted

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.

 

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

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Posted

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

Posted

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

  • Administrators
Posted
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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted (edited)
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 Edited by scorpin

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