webmaster wrote:
> Hi,
>
> I am using the following code to draw 2 line on a window (one above the
> other).
> $Window->BeginPaint();
> $Window->MoveTo(0, 5);
> $Window->LineTo(200, 5);
> $Window->MoveTo(0, 7);
> $Window->LineTo(200, 7);
> $Window->EndPaint();
>
> Can anyone please tell me how I can change the colors of the lines (e.g. the
> top line grey and the bottom line white).
> Is this the best method for drawing simple lines on a window.
no, you should create a Win32::GUI::Graphic object and then provide
a Paint() event for it. Example:
$Window->AddGraphic(
-name => "Graphic",
-pos => [ 0, 0 ],
-size => [ $Window->ScaleWidth, $Window->ScaleHeight ],
);
sub Graphic_Paint {
my($DC) = @_;
my $grey = new Win32::GUI::Pen(
-color => [ 128, 128, 128 ]
);
my $white = new Win32::GUI::Pen(
-color => [ 255, 255, 255 ]
);
$DC->SelectObject($grey);
$DC->MoveTo(0, 5);
$DC->LineTo(200, 5);
$DC->SelectObject($white);
$DC->MoveTo(0, 7);
$DC->LineTo(200, 7);
$DC->Validate();
}
as you can see from the example, the way to draw in colors is to create
the pen objects you need and select them before drawing; remember to
Validate the Device Context before leaving the Paint() event or your
window will flicker badly :-)
cheers,
Aldo