?
Solved

Changing the size of the FillEllipse

Posted on 2009-04-28
6
Medium Priority
?
537 Views
Last Modified: 2012-06-27
I am writing my first windows forms program in C++ and I am suppose to be making a simple mouse draw program. But I am currently having trouble tagging a way to change the size of the radius of the Fill Ellipse to radio buttons.

I have tried to just work the same code I used in the movemouse event but I am getting errors that are saying the X and Y values are not members.

error C2039: 'X' : is not a member of 'System::EventArgs'      

The code of the form is bellow.

#pragma once
 
 
namespace WindowsForms1 {
 
	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;
 
	/// <summary>
	/// Summary for Form1
	///
	/// WARNING: If you change the name of this class, you will need to change the
	///          'Resource File Name' property for the managed resource compiler tool
	///          associated with all .resx files this class depends on.  Otherwise,
	///          the designers will not be able to interact properly with localized
	///          resources associated with this form.
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}
 
	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
 
	private:
		static bool shouldPaint = false;
	private: System::Windows::Forms::RadioButton^  radioButton1;
	private: System::Windows::Forms::RadioButton^  radioButton2;
	private: System::Windows::Forms::RadioButton^  radioButton3;
	private: System::Windows::Forms::Label^  label1;
	private: System::Windows::Forms::ListView^  listView1;
			 /// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;
 
#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->radioButton1 = (gcnew System::Windows::Forms::RadioButton());
			this->radioButton2 = (gcnew System::Windows::Forms::RadioButton());
			this->radioButton3 = (gcnew System::Windows::Forms::RadioButton());
			this->label1 = (gcnew System::Windows::Forms::Label());
			this->listView1 = (gcnew System::Windows::Forms::ListView());
			this->SuspendLayout();
			// 
			// radioButton1
			// 
			this->radioButton1->AutoSize = true;
			this->radioButton1->Location = System::Drawing::Point(70, 92);
			this->radioButton1->Name = L"radioButton1";
			this->radioButton1->Size = System::Drawing::Size(50, 17);
			this->radioButton1->TabIndex = 0;
			this->radioButton1->TabStop = true;
			this->radioButton1->Text = L"Small";
			this->radioButton1->UseVisualStyleBackColor = true;
			this->radioButton1->Click += gcnew System::EventHandler(this, &Form1::radioButton1_Click);
			// 
			// radioButton2
			// 
			this->radioButton2->AutoSize = true;
			this->radioButton2->Location = System::Drawing::Point(70, 131);
			this->radioButton2->Name = L"radioButton2";
			this->radioButton2->Size = System::Drawing::Size(62, 17);
			this->radioButton2->TabIndex = 1;
			this->radioButton2->TabStop = true;
			this->radioButton2->Text = L"Medium";
			this->radioButton2->UseVisualStyleBackColor = true;
			this->radioButton2->Click += gcnew System::EventHandler(this, &Form1::radioButton2_Click);
			// 
			// radioButton3
			// 
			this->radioButton3->AutoSize = true;
			this->radioButton3->Location = System::Drawing::Point(70, 166);
			this->radioButton3->Name = L"radioButton3";
			this->radioButton3->Size = System::Drawing::Size(52, 17);
			this->radioButton3->TabIndex = 2;
			this->radioButton3->TabStop = true;
			this->radioButton3->Text = L"Large";
			this->radioButton3->UseVisualStyleBackColor = true;
			this->radioButton3->Click += gcnew System::EventHandler(this, &Form1::radioButton3_Click);
			// 
			// label1
			// 
			this->label1->AutoSize = true;
			this->label1->Location = System::Drawing::Point(67, 59);
			this->label1->Name = L"label1";
			this->label1->Size = System::Drawing::Size(27, 13);
			this->label1->TabIndex = 3;
			this->label1->Text = L"Size";
			// 
			// listView1
			// 
			this->listView1->BackColor = System::Drawing::Color::FromArgb(static_cast<System::Int32>(static_cast<System::Byte>(224)), static_cast<System::Int32>(static_cast<System::Byte>(224)), 
				static_cast<System::Int32>(static_cast<System::Byte>(224)));
			this->listView1->Location = System::Drawing::Point(58, 65);
			this->listView1->Name = L"listView1";
			this->listView1->Size = System::Drawing::Size(86, 134);
			this->listView1->TabIndex = 4;
			this->listView1->UseCompatibleStateImageBehavior = false;
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->BackColor = System::Drawing::Color::FromArgb(static_cast<System::Int32>(static_cast<System::Byte>(224)), static_cast<System::Int32>(static_cast<System::Byte>(224)), 
				static_cast<System::Int32>(static_cast<System::Byte>(224)));
			this->ClientSize = System::Drawing::Size(672, 264);
			this->Controls->Add(this->label1);
			this->Controls->Add(this->radioButton3);
			this->Controls->Add(this->radioButton2);
			this->Controls->Add(this->radioButton1);
			this->Controls->Add(this->listView1);
			this->Name = L"Form1";
			this->Text = L"Mouse Draw";
			this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
			this->MouseUp += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::Form1_MouseUp);
			this->MouseDown += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::Form1_MouseDown);
			this->MouseMove += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::Form1_MouseMove);
			this->ResumeLayout(false);
			this->PerformLayout();
 
		}
#pragma endregion
	private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
			 }
	private: System::Void Form1_MouseDown(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) 
			 {
				 { shouldPaint = true; }
			}
	private: System::Void Form1_MouseMove(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) 
			 {
				{ if(shouldPaint)
{
Graphics ^graphics = CreateGraphics();
graphics->FillEllipse(gcnew SolidBrush(Color::Crimson), e->X, e->Y, 4, 4);
}
}
			}
	private: System::Void Form1_MouseUp(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) 
			 {
{shouldPaint =false;}
}
private: System::Void radioButton1_Click(System::Object^  sender, System::EventArgs^  e) 
		 {
			 Graphics ^graphics = CreateGraphics();
graphics->FillEllipse(gcnew SolidBrush(Color::Crimson), e->X, e->Y, 4, 4);
		 }
private: System::Void radioButton2_Click(System::Object^  sender, System::EventArgs^  e) 
		 {
 
		 }
private: System::Void radioButton3_Click(System::Object^  sender, System::EventArgs^  e) 
		 {
 
		 }
}
;}

Open in new window

0
Comment
Question by:acezenitsu
  • 3
  • 3
6 Comments
 
LVL 40

Expert Comment

by:evilrix
ID: 24257864
I assume you refer to this event handler?

private: System::Void radioButton1_Click(System::Object^  sender, System::EventArgs^  e)
{
      Graphics ^graphics = CreateGraphics();
      graphics->FillEllipse(gcnew SolidBrush(Color::Crimson), e->X, e->Y, 4, 4);
}


The event args for this handler do not include any mouse details. Look at the mouse event handlers, they are passed MouseEventArgs that do contain X/Y coordinates, which is why that code works.
0
 
LVL 1

Author Comment

by:acezenitsu
ID: 24264003
So I switched the event handler to a MouseClick which added those parameters I needed. But it is still not applying it to the mouse, all it is doing is putting sized dots in a corner.
private: System::Void radioButton1_MouseClick(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) 
		 {
			 			 Graphics ^graphics = CreateGraphics();
graphics->FillEllipse(gcnew SolidBrush(Color::Crimson), e->X, e->Y, 4, 4);
		 }
private: System::Void radioButton2_MouseClick(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) 
		 {
			 			 Graphics ^graphics = CreateGraphics();
graphics->FillEllipse(gcnew SolidBrush(Color::Crimson), e->X, e->Y, 6, 6);
		 }
private: System::Void radioButton3_MouseClick(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) 
		 {
			 			 Graphics ^graphics = CreateGraphics();
graphics->FillEllipse(gcnew SolidBrush(Color::Crimson), e->X, e->Y, 8, 8);
		 }
}
;}

Open in new window

0
 
LVL 40

Accepted Solution

by:
evilrix earned 1000 total points
ID: 24264049
>> So I switched the event handler to a MouseClick
You can't just do that... the event passed in isn't a MouseEventArgs type, so this won't work :)

You probably want to use Cursor.Position
http://msdn.microsoft.com/en-us/library/system.windows.forms.cursor.position.aspx
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 1

Author Comment

by:acezenitsu
ID: 24266877
Arg! I'm still not able to get this to work, I looked over the Cursor.Position but I couldn't get it implemented properly.
0
 
LVL 40

Expert Comment

by:evilrix
ID: 24267496
>> I  couldn't get it implemented properly.
Why not? If it was problems translating the X,Y coordinates, you might need to look at

Control..::.PointToClient Method

"Computes the location of the specified screen point into client coordinates."
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.pointtoclient.aspx
0
 
LVL 1

Author Comment

by:acezenitsu
ID: 24275895
I got it working with just a simple MousClick event on the radio buttons and then just using a variable in the events to change the font. XD
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question