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;

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

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

  begin
   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;
  end;

  begin
                        _wt := wt;

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

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

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

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

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

             begin
    if MouseIn then  (*Not Pushed + Mouse In + not Down*)
                                Offscreen.Canvas.Brush.Color:=$000000AA;
{Color for the crosshatch pattern}
                                Offscreen.Canvas.Brush.style:=bsdiagcross;
{code for the crosshatch pattern}

OffScreen.Canvas.FillRect(Rect(1,1,Width-1,Height-1));
                 if (Length(Caption) > 0) then
                                Offscreen.Canvas.Font.Color:=clred;
    DrawTheText(OffScreen.Canvas, TempRect, TempCaption);
                                end
                            else    (*Not Pushed + Mouse out + not Down*)
                                DrawOutline(OffScreen.Canvas, True);
    if (Length(Caption) > 0) then
    DrawTheText(OffScreen.Canvas, TempRect, TempCaption)
                                end
   else
       begin     (* Pushed state *)
         DrawOutline(OffScreen.Canvas, True);
    if  (Length(Caption) > 0) then
         DrawTheText(OffScreen.Canvas, TempRect, TempCaption)
           end;
     Canvas.CopyRect(Rect(0,0,Width,Height), OffScreen.Canvas,
Rect(0,0,Width,Height));
     OffScreen.Free;
end;

Thank in advance,

AJ

 

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