Note that there are some explanatory texts on larger screens.

plurals
  1. PODraw on Button click- Visual C++
    primarykey
    data
    text
    <p>I need to create rectangles when the button is clicked. I have tried the given code but its not working. i have tried to create a flag "mdraw" that becomes true when a button is clicked. a condition is out in the form_paint where the rectangle will created only when the "mdraw" becomes true. But after clicking the button, nothing comes!</p> <p>I m using windows forms application (CLR). Microsoft visual c++ 2008.</p> <pre><code> #pragma once namespace try1 { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; /// &lt;summary&gt; /// 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. /// &lt;/summary&gt; public ref class Form1 : public System::Windows::Forms::Form { public: Form1(void) { InitializeComponent(); // //TODO: Add the constructor code here // } protected: /// &lt;summary&gt; /// Clean up any resources being used. /// &lt;/summary&gt; ~Form1() { if (components) { delete components; } } private: System::Windows::Forms::Button^ button1; protected: private: /// &lt;summary&gt; /// Required designer variable. /// &lt;/summary&gt; System::ComponentModel::Container ^components; private: System::Windows::Forms::Label^ label1; public: bool mdraw; #pragma region Windows Form Designer generated code /// &lt;summary&gt; /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// &lt;/summary&gt; void InitializeComponent(void) { this-&gt;button1 = (gcnew System::Windows::Forms::Button()); this-&gt;label1 = (gcnew System::Windows::Forms::Label()); this-&gt;SuspendLayout(); // // button1 // this-&gt;button1-&gt;Location = System::Drawing::Point(98, 35); this-&gt;button1-&gt;Name = L"button1"; this-&gt;button1-&gt;Size = System::Drawing::Size(75, 23); this-&gt;button1-&gt;TabIndex = 0; this-&gt;button1-&gt;Text = L"button1"; this-&gt;button1-&gt;UseVisualStyleBackColor = true; this-&gt;button1-&gt;Click += gcnew System::EventHandler(this, &amp;Form1::button1_Click); // // label1 // this-&gt;label1-&gt;AutoSize = true; this-&gt;label1-&gt;Location = System::Drawing::Point(51, 77); this-&gt;label1-&gt;Name = L"label1"; this-&gt;label1-&gt;Size = System::Drawing::Size(0, 13); this-&gt;label1-&gt;TabIndex = 1; // // Form1 // this-&gt;AutoScaleDimensions = System::Drawing::SizeF(6, 13); this-&gt;AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this-&gt;ClientSize = System::Drawing::Size(284, 262); this-&gt;Controls-&gt;Add(this-&gt;label1); this-&gt;Controls-&gt;Add(this-&gt;button1); this-&gt;Name = L"Form1"; this-&gt;Text = L"Form1"; this-&gt;Load += gcnew System::EventHandler(this, &amp;Form1::Form1_Load); this-&gt;Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &amp;Form1::Form1_Paint); this-&gt;ResumeLayout(false); this-&gt;PerformLayout(); } #pragma endregion private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { mdraw=true; label1-&gt;Text=button1-&gt;Text; } private: System::Void Form1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) { Pen^ redPen = gcnew Pen(Color::Red); int i,n; i=20; n=0; if(mdraw) { while(n&lt;=50) { e-&gt;Graphics-&gt;DrawRectangle(redPen,i,140,10,60); i=i+20; n+=1; } } } }; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload