Using Paint Event during runtime C++/cli

Hi i'm quite new with c++/cli and im using it for my college project

I've had a few problems which have now been fixed (thank god) but i've ran into another problem which i'm hoping is quite a simple fix.

I need to draw an object (rectangle or circle) directly onto MyForm, however i need the object to be drawn after the type is selected from a combobox.

Atm i have managed to get the selection process from the comboBox sorted and once selected it sets some variables in a seperate class called Projectile.
2 of these variables are the width and the height of the object so i'm then passing them into a OnPaint event to paint the object i need however i've noticed that the OnPaint and the MyForm_Paint events only seem to run at first load.

i've tried calling Invalidate() and Update() to no avail so now im here looking for help :P

here's the code from MyForm

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
private: System::Void comboBox1_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) {
			 SelectedIndex = comboBox1->SelectedIndex;
			 Projectile1.setProjectile(SelectedIndex);
			 Invalidate();
			 Update();
		 }

// Display the chosen Projectile

public:
	virtual void OnPaint(PaintEventArgs^ e) override {
		Form::OnPaint( e );
		Graphics^ g = e->Graphics; 
	g->SmoothingMode = Drawing2D::SmoothingMode::HighQuality;
	
	switch(Projectile1.Type){
	case 'Rect':
		g->DrawRectangle(Pens::Black, Projectile1.ProjectilePos.X, Projectile1.ProjectilePos.Y, Projectile1.width, Projectile1.height);
		g->FillRectangle(Brushes::Red, Projectile1.ProjectilePos.X, Projectile1.ProjectilePos.Y, Projectile1.width, Projectile1.height);
		break;
	case 'Circ':
		g->DrawEllipse(Pens::Black,Projectile1.ProjectilePos.X, Projectile1.ProjectilePos.Y, Projectile1.width, Projectile1.height);
		g->FillEllipse(Brushes::Red, Projectile1.ProjectilePos.X, Projectile1.ProjectilePos.Y, Projectile1.width, Projectile1.height);
		break;
		 }
	}


and here's the code from Projectile

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using namespace System::Drawing;

ref class Projectile
{
	
public:
	Projectile(void);
	int width;
	int height;
	float PFF;
	float projectileRest;
	float SurfaceArea;
	char Type;
	Point ProjectilePos;
public:	void setProjectile(int chosen){
		switch (chosen){
		case 0: //Arrow
			width =25;
			height =5;
			PFF = 0.2;
			projectileRest = 0;
			Type = 'Rect';
			break;
		case 1: //Basketball
			width =20;
			height =20;
			PFF=0.6;
			projectileRest = 0.6;
			Type = 'Circ';
			break;
		case 2: //BouncyBall
			width =10;
			height =10;
			PFF=0.1;
			projectileRest = 0.8;
			Type = 'Circ';
			break;
		case 3: //Cannonball
			width = 18;
			height = 18;
			PFF = 0.8;
			projectileRest = 0.001;
			Type = 'Circ';
			break;
		case 4: //Football
			width = 19;
			height = 19;
			PFF = 0.5;
			projectileRest = 0.4;
			Type = 'Circ';
			break;
		case 5: //frisby
			width = 19;
			height = 5;
			PFF = 0.05;
			projectileRest = 0.001;
			Type = 'Rect';
			break;
		case 6: //tennisball
			width = 13;
			height = 13;
			PFF = 0.3;
			projectileRest = 0.2;
			Type = 'Circ';
			break;
			}
		SurfaceArea = width*height;

	}



Thanks for any help
Last edited on
bump because still havn't figured this out (bypassing it for the moment)
Topic archived. No new replies allowed.