Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Let me tell you what I really want.

 

I have form1 and form2.

 

formm1 is the main form and form2 resides in form1.

in form2 there is a picturebox. the picture is shown in the picture box using a function.

 

I want to place a new picture in this picture box by clicking a button which is in form1.

 

If I create a new instance as dynamic_sysop

 

it does not work.

 

hope some one understand me.

 

sorry for the poor english.

  • Leaders
Posted

if you declare form2 first ( below the windows generated code area ) then i'm not sure what the problem seems to be.

Private frm2 As New Form2()

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
   frm2.Show()
   frm2.PictureBox1.Image = Image.FromFile("C:\Documents and Settings\den\My Documents\My Pictures\flammable.gif")
End Sub

that puts an image in a picturebox on form2 fine for me.

Posted

HI,

 

this is the code Iam using

----------------------------------------------

'in form1

 

Public Class Form1

Inherits System.Windows.Forms.Form

Dim pform As Form

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

 

CType(pform, Form2).abc()

 

End Sub

 

-----------------------------------------------------

'in form2

Public Class Form2

Inherits System.Windows.Forms.Form

 

Public Function abc()

pic1.image = the picture path

End Function

 

End Class

 

----------------------------------------------

 

Now I get this error

 

 

An unhandled exception of type 'System.NullReferenceException' occurred in WindowsApplication6.exe

 

Additional information: Object reference not set to an instance of an object.

  • Leaders
Posted

try changing this:

Inherits System.Windows.Forms.Form

Dim pform As Form

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

 

CType(pform, Form2).abc() <<<< this line

 

End Sub

to this:

Inherits System.Windows.Forms.Form
Dim pform As Form
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

frm2 = DirectCast(New Form2(), Form)'/// to like this , if you dont want to use Dim frm2 As New Form2()

End Sub

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