Working with forms, objects at runtime, access there properties and delete them?

Hi iv been looking everywhere on how to add an instance of a rectangle object when i click a button. I'm using Visual studio2010, there is no sample code on the microsoft website. I've been adding dif code to the event procedure of click for some time now and still no go. this is wat im using now, it compiles without the system.drawing.size(3, 3) line

1
2
3
4
5
6
7
8
9
10
11
12
13
14
 Microsoft::VisualBasic::PowerPacks::ShapeContainer^  SCon2;
			 Microsoft::VisualBasic::PowerPacks::RectangleShape^ thisob;
			 
			 SCon2->Parent=this;
			 thisob->Parent = SCon2;
			 thisob->Location= Point(180, 620);
			 thisob->CornerRadius = 12;
/* wont let me -> */     thisob->Size =(3, 3);
//set the size
//have tried dif versions of this like..
//thisob->System.Drawing.Size(3, 3);
//and
//thisob->size(3, 3);


cant figure this out... any help would be awesome...
Last edited on
closed account (3hM2Nwbp)
Try
 
thisob->Size = System::Drawing::Size(3, 3); //<-- Use Scope Resolution Operator 


Be careful when using namespace(s) in C++/CLI - many of the namespace members are overshadowed by properties of the System::Windows::Forms::Control class, so they'll have to be properly qualified anyway.
Last edited on
thanks im getting an error when i click the button, "Object reference not set to an instance of an object"
this is the code
1
2
3
4
5
6
7
8
9
10
11
12

  Microsoft::VisualBasic::PowerPacks::ShapeContainer^  SCon2;
			 Microsoft::VisualBasic::PowerPacks::RectangleShape^ thisob;
			 thisob = (gcnew Microsoft::VisualBasic::PowerPacks::RectangleShape());
			 SCon2->Parent=this;
			 thisob->Parent = SCon2;
			 thisob->Size = System::Drawing::Size(3, 3);
			 thisob->Location= Point(180, 620);
			 //thisnegro->Size= Size(3,3);
			 thisob->CornerRadius = 12;
			 thisob->BorderColor = Color::Red;


if i was able to draw a couple pixles a different color then the form with user entered x,y cords id be set. like marking a marp with a thumbtak.
Last edited on
closed account (3hM2Nwbp)
Hi, you're probably getting that error because your ShapeContainer hasn't been initialized.

*Though if you explain what you're trying to do more fully, there might be other controls that would suit you better.
Last edited on
i want to plot marks at user determined locations(x,y) to represent cities. i put a bunch of lines on the form to form a grid. Its kind of a makeshift skatter chart. im using rectangles as points.
I just need to add marks at x,y cords on the form i dont care how, whether in a pitcture box, dont know if u can put multiple things in a picture box. i thought the easiest way was to make some objects and set location to the users input.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
this seems good for now. it plots the objects like i want. not sure if can erase them
 off the map yet. dont know how id do it. thanks fo the input guys now i 
figure out how to remove them, and access the container ther in i geuss..
private: System::Void button3_Click_1(System::Object^  sender, System::EventArgs^  e)
		 {
			 Microsoft::VisualBasic::PowerPacks::ShapeContainer^  SCon2;
			 SCon2 = gcnew Microsoft::VisualBasic::PowerPacks::ShapeContainer();
			 
			 if(gx < 50 || gx >800) 
				 gx = 50;
			 if(gy < 50 || gy >800) 
				 gy = 50;
			 for(int i = 0; i < 1; i++, gx+=30, gy+=40)
			 {
				 Microsoft::VisualBasic::PowerPacks::RectangleShape^ thisob;
				 thisob = (gcnew Microsoft::VisualBasic::PowerPacks::RectangleShape());
				 SCon2->Parent=this;
				 thisob->Parent = SCon2;
				 thisob->Size = System::Drawing::Size(3, 3);
				 thisob->Location= Point(gx, gy);
				 //thisnegro->Size= Size(3,3);
				 thisob->CornerRadius = 12;
				 thisob->BorderColor = Color::Red;
				 thisob->FillStyle = Microsoft::VisualBasic::PowerPacks::FillStyle::Solid;
				 thisob->FillColor = Color::Red;
				 thisob->Visible=true;
				 thisob->BorderWidth= 2;

			 }
			 
		 }
Last edited on
Topic archived. No new replies allowed.