I've got an assignment due very soon that I can't for the life of me figure out.
the basic idea is to create a program that allows the user to paint with large dots.
If the R key is down the dot should be red, if the B key is down the Dot should be blue, etc. The dot (size, color, everything) is defined in a separate header file.

So far I can make it paint the dots but only of a single color and with no key pressed. how would i go about changing the color based on a key press? I've tried storing the color name in a string but i couldn't seem to get that to work

If you're not sure what the goal is, this page has my professors example as a java applet
http://cs.ua.edu/351/S2012/Assignments/P2.htm

Any suggestions would be greatly appreciated.


This is the header file containing the dot class

using namespace System;
using namespace System::Drawing;

public ref class CMyDot {
public:
	CMyDot(int x, int y) {
		X=x;
		Y=y;
	}
	
	int getX() { return X; }
	void setX(int x) { X=x; }
	int getY() { return Y; }
	void setY(int y) { X=y; }
	Color myColor = Color::White;
	
	
	double distanceTo(int x, int y) {
		return Math::Sqrt((X-x)*(X-x)+(Y-y)*(Y-y));
	}

	void draw(Graphics^ g) {
		g->FillEllipse( gcnew SolidBrush(Color::Red ), X, Y, 50, 50 ); // Draw Color
	}

private:
	int X;
	int Y;
};

Recommended Answers

All 5 Replies

Perhaps a better way to word my question would be how do i test whether a key is down AND the mouse has been clicked?

I'm afraid I still cant seem to figure it out.
I can't figure out how to test for both the key down and mouse click together. I can get both to work separately but i'm not sure how to go about combining the two events

I'm afraid I still cant seem to figure it out.
I can't figure out how to test for both the key down and mouse click together. I can get both to work separately but i'm not sure how to go about combining the two events

In my code, I've set up the following GLOBAL variables:
Pen^
Rectangle
Color
bool bMouseClick which is initialized to false

In my MouseDown event handler, I check for a depressed left mouse button. If it is depressed, I set my global boolean bMouseClick to true. I also fill in my global Rectangle with the mouse cursor X and Y coordinates and the size of the desired circle.

I have also created a KeyPress event handler. In this handler, I'm checking the KeyChar property for the appropriate depressed character AND determining that bMouseClick is true. If both these conditions exist, I create the Pen^ and ColorInput. I also invalidate the Rectangle built in the MouseDown event.

Now we have to accomodate the Rectangle invalidation by creating a Paint event handler. In this handler, you will call DrawEllipse with the global Pen^ and global Rectangle. You will also call Fillellipse with the global Color.

Finally, a MouseUp event handler is needed to change the global bMouseClick to false.

Thank you so much, with your suggestions i was able to get it finally.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.