+ 1

How to get an access to an object of form in another class?

C#, Windows Forms Hello everyone! I have got a really annoying problem. I have got my class "World_Class" and method "Create_World()" in it. Also i have Form1 with picturebox. "Create_World" has Form1 form1 = new Form1(); form1.picturebox.Location = new Point(100,100); And on button press in form1.cs I wrote World_Class world = new World_Class(); world.Create_World(); And i expected that for my picturebox will be set new location, but nothing happened. Picturebox has "public" access modifier. I tried many ideas from internet but nothing helped. Thank you in advance. P.s. sorry for my bad eng(

19th Mar 2019, 4:39 PM
ПризракTM
ПризракTM - avatar
2 Respostas
+ 1
Many questions in a short text. Your english is understable Does it work when you change the location on form1 itself. Put a button on form1 and try to change the location of the picturebox in the onclick event Actually it is bad practice to change a form-control propertie in another form. Make a public method on form1. public PictureBoxChangeLocation (int x, int y) { form1.picturebox.Location = new Point(x,y); } Call this in your other form form1.PictureBoxChangeLocation (100,100); Does it work when you call invalidate or refresh. To force the picturebox to be redrawn
19th Mar 2019, 9:42 PM
sneeze
sneeze - avatar
0
It helped me, thanks a lot !)
20th Mar 2019, 4:48 AM
ПризракTM
ПризракTM - avatar