Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Ask Question
I don't understand why the
Gdiplus::Graphics
object assigned to the pointer data member in the constructor draws on the
TForm
object, but does not draw on the
TImage
or
TPaintBox
objects? However, the
Gdiplus::Graphics
object draws well on
TImage
or
TPaintBox
objects provided that the
Gdiplus::Graphics
object was assigned to the pointer data member before calling
Gdiplus::Graphics
functions for drawing.
Here is the code:
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
Gdiplus::GdiplusStartupInput GdiplusStartupInput;
Gdiplus::GdiplusStartup(&mGdiplusToken, &GdiplusStartupInput, NULL);
// If the Gdiplus::Graphics object is created and assigned to pointer data member here it draws on TForm but does not draw on //TImage or TPaintBox
// mGraph = new Gdiplus::Graphics{Image1->Canvas->Handle};
void __fastcall TForm2::Button1Click(TObject *Sender)
Gdiplus::Status Status;
Gdiplus::Color Red {Gdiplus::Color::Red};
Gdiplus::Color Blue {Gdiplus::Color::Blue};
Gdiplus::Color Green {Gdiplus::Color::Green};
Gdiplus::Pen RedPen{Red, 2};
Gdiplus::Pen BluePen{Blue, 2};
Gdiplus::Pen GreenPen{Green, 2};
Gdiplus::Graphics Graph1{Image1->Canvas->Handle};
Gdiplus::Graphics* Graph2 = new Gdiplus::Graphics{Image1->Canvas->Handle};
Status = Graph1.DrawLine(&RedPen, 50, 50, 100, 50);
Status = Graph2->DrawLine(&BluePen, 50, 100, 100, 100);
//If Gdiplus::Graphics object is created and assigned to the pointer data member here it draws on TForm or TImage or TPaintBox
mGraph = new Gdiplus::Graphics{Image1->Canvas->Handle};
Status = mGraph->DrawLine(&GreenPen, 50, 150, 100, 150);
Image1->Repaint();
–
–
–
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.