VC++ Rysowanie obiektu na formie, pomoc.

0

Cześć!

#pragma once


namespace zsx {

	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: System::Windows::Forms::Timer^  timer1;
	protected: 

	protected: 
	private: System::ComponentModel::IContainer^  components;

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>


#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->components = (gcnew System::ComponentModel::Container());
			this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));
			this->SuspendLayout();
			// 
			// timer1
			// 
			this->timer1->Interval = 900;
			this->timer1->Tick += gcnew System::EventHandler(this, &Form1::timer1_Tick_1);
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(292, 273);
			this->Name = L"Form1";
			this->Text = L"Form1";
			this->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &Form1::Form1_Paint);
			this->MouseMove += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::Form1_MouseMove);
			this->ResumeLayout(false);

		}
#pragma endregion

	int x; int y;
	bool inv;
	void pnt (System::Windows::Forms::PaintEventArgs^  e) {
		Graphics^ g = e->Graphics;
		Pen^ p = gcnew Pen(System::Drawing::Color::Red, 3);
		g->DrawEllipse(p, x, y, 45, 45);
		timer1->Start();
	}
	private: System::Void Form1_MouseMove(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) {
				 x = e->X;
				 y = e->Y;		
	}
	private: System::Void Form1_Paint(System::Object^  sender, System::Windows::Forms::PaintEventArgs^  e) {
				 pnt(e);			
	}
	
	private: System::Void timer1_Tick(System::Object^  sender, System::EventArgs^  e) {
			
			 }
	private: System::Void timer1_Tick_1(System::Object^  sender, System::EventArgs^  e) {
				
			 }
	};
}


Napisałem kod, który w zamierzeniu ma po prostu przesuwać koło zgodnie z kursorem tj. rysować koło o współrzędnych zgodnych ze współrzędnymi kursora. Problem tylko w tym, że zbyt często dochodzi do przerysowania i cały czas koło jakby migało. Jak poprawić ten program aby po prostu przerysowywać obiekt?

0

U mnie twój kod nie działa (nic się nie rusza).
Ale spróbuj ustawić DoubleBuffered na true, może trochę pomoże.

1 użytkowników online, w tym zalogowanych: 0, gości: 1