const wxPen& GetPen() const;
wxPen pen = dc.GetPen(); // get the current pen object wxColour colour = pen.GetColour(); // get the current pen colour wxPenStyle style = pen.GetStyle(); // get the current pen style int width = pen.GetWidth(); // get the current pen width
wxPen pen(wxColour(255, 0, 0), 2, wxPENSTYLE_DOT); // create a red dotted pen dc.SetPen(pen); // set the custom pen dc.DrawLine(10, 10, 100, 100); // draw a diagonal line with the penThis code creates a custom pen with a red colour, 2-pixel width, and dotted style using the pen constructor. It then sets this pen to the device context dc using the SetPen method. Finally, it draws a diagonal line from (10, 10) to (100, 100) with the current pen using the DrawLine method. Package library: wxWidgets.