Click here to Skip to main content
14,694,330 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hi,
i have already image in picturebox1 where ihave another form in same project which is picturebox2 whenever trying use this code as per my knowledge its not working need help..thank you..

Form2.picturebox2.image=Form1(Me).picturebox1,.image //copying image picture box1 image to picturebox2 this i am doing in FORM1

please help me to do this
Posted
Updated 17-Aug-20 6:08am
Comments
SREENATH GANGA 13-May-15 1:53am
   
Did your second form opens after the first form? like when clicking on the picture box of first one or any other control on the form?
Ralf Meier 13-May-15 2:09am
   
When is this code-line called ?
With which Event ?
lakshjoshi 13-May-15 2:16am
   
sir,
its just a typing mistake just trying to do this...
Form2.picturebox2.image=Form1.picturebox1.image
this thing i am doing in form1 in which when i click on submit button
form2 has to open and it should display form1 picturebox image in form2 picturebox2..thats it i am trying to do but result is not as expected..thank you..

It makes no sense at all. There is no such concept as "open PictireBox". It's not clear what did you mean by Form1(Me), it also makes no sense. Also pay attention for pictirebox1,.image. It cannot even compile.

You need to understand what are types and what are instances of the types, objects. Assuming Form2 and Form1 are types, and picture boxes are instance members (non-static), only one conclusion can be made: you have no clue on programming, in the most elementary and basic things. Not to worry: with appropriate effort and slow methodical approach, it can be learned without big problems.

There is nothing to fix here, except one thing: stop thinking that you can get to UI. You are not ready yet. Get to the very basics, learn what are types, objects, members, methods, parameters, and so on. For this purpose, exercises with the simplest console-only application is the very it. :-)

[EDIT]

See also my article Many Questions Answered at Once — Collaboration between Windows Forms or WPF Windows[^].

It is directly related to your question. But try to understand, not just copy the code. Understand what are types and instances. (Sigh…)

—SA
   
v3
Comments
lakshjoshi 13-May-15 2:15am
   
sir,
its just a typing mistake just trying to do this...
Form2.picturebox2.image=Form1.picturebox1.image
this thing i am doint in form1 in which when i click on button
form2 has to open and it should display form1 picturebox image in form2 picturebox2..thats it i am trying to do but result is not as expected..thank you..
   
After a fix, it's not much better.
Are Form1 and Form2 types? are the picture boxes the instance member?

Look, listen to a good friendly advice: stop trying UI development for now; you are not yet ready. You will come to it later...

—SA
lakshjoshi 13-May-15 3:12am
   
yes i did it just picture size is the problem
picturebox1.size=500,29
but
picturebox2.size=148,38
so make equal size of picture box its solves the problem thank you...so much..problem solved....as per your advice i will learn basics thank you....
   
You did not ask about the size. You asked about copy image. And you don't have to clone it, you can copy the reference. Do you understand it? I'm not sure...
—SA
lakshjoshi 13-May-15 3:31am
   
ok sir,problem solved,thanks for helping me to improve my basics..thank you once again...
   
My pleasure. See also my update to the question, after [EDIT].
Will you accept the answer formally?
—SA
to copy from one picture box to another picture box
condition:-
1.both picture box image size shold be same then use the below code:-

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
       Form2.Show()
       PictureBox1.Size = New Size(148, 38)
       Form2.PictureBox2.Image = Me.PictureBox1.Image
   End Sub
   
Comments
Ralf Meier 13-May-15 3:38am
   
... or you set the SizeMode of the second PictureBox (or of both) to 'Zoom'
lakshjoshi 19-May-15 8:10am
   
my picturebox1 size is 500,29 and picturebox2 size is 148,38 so i converted picturebox1 size 500,29 to 148,39 to store in picturebox2 that's it...happy coding...
okay! my answer:
on form 2: you have a picturebox and you need set: Modifies = Public
comeback form 1 code:

Form2 dis = new Form2();
dis.pictureBox1.Image = pictureBox1.Image;
dis.Show();

done! hope help for you! :)
   
v3
Function insideImage(ByVal srcImage As PictureBox, ByVal overImage As PictureBox, ByVal x As Integer, ByVal y As Integer) 'by Korobeiniki xD
        Dim vector2 = New Point(x, y)
        overImage.Parent = srcImage
        overImage.BackColor = Drawing.Color.Transparent
        overImage.Location = vector2
End Function

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim x = srcImage.left - overImage.left
        Dim y = srcImage.top - overImage.top
        insideImage(srcImage, overImage, x, y)
End Sub
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900