I am “having fun” with Visual C++ some time already. And today i decided, i want to draw some colored pixel inside “panel”. The goal is – later, when i will learn how to do that – draw pixels inside panel, taking colors from array. But for now, i just want to create few pixel inside panel.
Lets say i got a panel 20×20, and i want put there 3 pixels somewhere not near edge. And let say every pixel gonna be other color. I was reading a bit and found some ideas, but didnt get anything to work.
Do i need to use that to put single pixel? (i am guessing 3,3,3,3 are cords, corners of rectangle).
Color aColor = Color::Green;
SolidBrush^ aBrush = gcnew SolidBrush(aColor);
e->Graphics->FillRectangle(Brush, 3, 3, 3, 3);
Also, then how to make it draw a pixel into “panel1” WHEN PRESSING A button. Cuz if i put that code directly in panel1, it should draw these pixel right after compiling right? And i want draw pixels after pressing a button.
Don’t be too rough for me, i am learning it 😉
To set a single pixel, draw a 1-by-1 rectangle.
The last two parameters are width and height.
This code needs to be in a
Painthandler.It will then draw the pixel at all times.
To only draw the pixel once you click a button, set a flag in your class when you click the button, and put the drawing code in an
ifstatement.You should then call
panel->Invalidate()to force the panel to repaint so that your drawing appears.