acezenitsu
asked on
Changing the size of the FillEllipse
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.
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)
{
}
}
;}
ASKER
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);
}
}
;}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
>> 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
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
ASKER
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
private: System::Void radioButton1_Click(System:
{
Graphics ^graphics = CreateGraphics();
graphics->FillEllipse(gcne
}
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.