Board index » delphi » Brush Styles. WIN95/98 vs NT

Brush Styles. WIN95/98 vs NT

Howdy All.

I hope someone can help me.

I am programming my first delphi component (a button) with some of the code
listed below.
My problem is that I have developed it on NT4 and it works exaxtly how I
want it to,
ie. Black background with a light red crosshatch (Brush.Style:=DiagCross)
when the mouse is over it, but when I run it on WIN95/98 the colour of the
Brush.Color setting is all  stuffed up and I can,t seem to get it to work.
The color of the background is white when it is supposed to be set to black
and the color of the DiagCross is not what I set in the code.  At first I
thought it was a color resolution on the different computers but after
setting all similar and different combinations on 4 different computers I
still have the same problem!

Can anyone suggest why and provide a solution?

Paint code

procedure TAJButton2.Paint;
var xt, yt, wt, _wt, ht: Integer;
 TempCaption : Array[0..256] of char;
 TempRect    : TRect;
 OffScreen: TBitmap;

 if visible or (csDesigning in ComponentState) then
        OffScreen := TBitmap.Create;
        OffScreen.Width := Width;
        OffScreen.Height := Height;;
        Offscreen.Canvas.Brush.Color := clblack;  {This is the initial color
of the button. Black}
        DrawOutline(OffScreen.Canvas, True); {original code }

  OffScreen.Canvas.Brush.Style :=bssolid;
  OffScreen.Canvas.Font := Self.Font;

   TempRect.Top := 0;
   TempRect.Left := 0;
   TempRect.Right := Width - 4;
   TempRect.Bottom := 0;
   StrPCopy(TempCaption, Caption);
   ComputeExtent(TempCaption, TempRect, OffScreen.Canvas);
   wt := TempRect.Right;
   ht := TempRect.Bottom;

                        _wt := wt;

   yt := (Height - ht) div 2;
   case Alignment of
    taLeftJustify:  xt := 3;
    taRightJustify: xt := Width - _wt - 3;
    taCenter:   xt := (Width - _wt) div 2

   if csDesigning in ComponentState then
   OffScreen.Canvas.Pen.Color := clred;
   OffScreen.Canvas.Pen.Style := psSolid;
                       OffScreen.Canvas.Brush.Style := bssolid;
   OffScreen.Canvas.Rectangle(0, 0, Width, Height);

  if WordWrap and (xt + wt > width - 5) then
   wt := width - xt - 5;

  with TempRect do
   left := xt;
   top  := yt;
   right:= xt + wt;
   bottom:= yt + ht;

  if Enabled then     (*Enabled set in the Component Properties*)
                     if not (Pushed and MouseIn) and not Down then

    if MouseIn then  (*Not Pushed + Mouse In + not Down*)
{Color for the crosshatch pattern}
{code for the crosshatch pattern}

                 if (Length(Caption) > 0) then
    DrawTheText(OffScreen.Canvas, TempRect, TempCaption);
                            else    (*Not Pushed + Mouse out + not Down*)
                                DrawOutline(OffScreen.Canvas, True);
    if (Length(Caption) > 0) then
    DrawTheText(OffScreen.Canvas, TempRect, TempCaption)
       begin     (* Pushed state *)
         DrawOutline(OffScreen.Canvas, True);
    if  (Length(Caption) > 0) then
         DrawTheText(OffScreen.Canvas, TempRect, TempCaption)
     Canvas.CopyRect(Rect(0,0,Width,Height), OffScreen.Canvas,

Thank in advance,



Re:Brush Styles. WIN95/98 vs NT

Hi AJ,

    Without actually building your compont to verify, how about this..NT &
Win95+ use different defaults for various settings, and I think the transparency
of text is one that differs.  I would certainly experiment with the use of
SetBkMode prior to drawing text.    Use it after setting the canvas font &
brush.  SetBkMode sets the transparency of text & can be found in the WinAPI
help.    I don't know if it will fix your problem, but its a new angle to try?

..Laurie  :-)

Other Threads