[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Statusbar doesn't resize with the form

Posted on 2006-04-27
11
Medium Priority
?
503 Views
Last Modified: 2010-04-05
Hello,

I am still working on a Terminal-emulation component.
Now I have made a statusbar, that looks like this:

procedure TDSP3270.ShowStatus;
var
  StatY, SepX, SepY: integer ;
begin
  SepX := FSCRCOLS * FFontWidthPix ;
  SepY := FSCRROWS * FFontHeightPix ;
  StatY := FSCRROWS * FFontHeightPix + (FFontHeightPix+2) ;
  with Canvas do
    begin
      { draw seperator line }
      Pen.Mode := pmCopy ;
      Pen.Color := FColorWhite ;
      Brush.Style := bsClear ;
      Brush.Color := FColorBlack ;
      MoveTo(0,SepY) ;
      LineTo(SepX,SepY) ;

          { display row and column indicator }
          Font.Color := FColorWhite ;
         TextOut(FFontWidthPix*74,SepY+2,Format('%.2d/%.3d',  
         [FCsrRow,FCsrCol])) ;
        end ;
  end ;

Now my problem is when i resize the form the statusbar
doesn't resize with it.

How can I make my statusbar resizeable, and what do
I have to put in the Resize-event.

Greetings,

Peter Kiers
0
Comment
Question by:peterkiers
  • 5
  • 5
11 Comments
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 16560166
Is this status bar aligned to the bottom of the form and it doesnt resize?
0
 
LVL 28

Expert Comment

by:2266180
ID: 16560285
is your statusbar part of the display component? if so, you will have to track the resize of the component (when the component resizez you also resize your statusbar)

if the statusbar is a descendant of TStatusBar, then as mike suggested, you need to make the statusbar align at the bottom; if you don't want that, then just resize the statusbar when the form/component resizez.

byt better give out full information as not everybody knows what you are doing ;)
0
 
LVL 1

Author Comment

by:peterkiers
ID: 16562100
Yes, the statusbar is aligned to the bottom of the form.

procedure TDSP3270.Paint;
var
  TxMetric: TTextMetric ;
begin
  Canvas.Font.Size := FFontSize ;
  Canvas.Font.Name := FFontName ;
  GetTextMetrics(Canvas.Handle,TxMetric) ;
  FFontWidthPix := TxMetric.tmMaxCharWidth ;
  FFontHeightPix := TxMetric.tmHeight ;
  Height := fSCRROWS * fFontHeightPix + (fFontHeightPix+2) ;
  Width := fSCRCOLS * fFontWidthPix ;
  ClearBuf ;
  ShowBuf ;
end;

procedure TDSP3270.ShowBuf;
  var
  i, j: integer ;
begin
  with Canvas do
    begin
      Brush.Style := bsSolid ;
      Brush.Color := FColorBlack ;
      FillRect(ClipRect) ;
    end ;
  for i := 1 to fSCRROWS do
    for j := 1 to fSCRCOLS do
      DispCell(j,i,false) ;  
    DrawCursor(FCsrCol,FCsrRow) ;
  ShowStatus ;
end;

p.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 28

Expert Comment

by:2266180
ID: 16562221
can you confirm/infirm that the statusbar is the same thing as delphi's TStatusBar? because it looks ackward that procedure TDSP3270.ShowStatus; accesses teh canvas directly to display the status information.
0
 
LVL 1

Author Comment

by:peterkiers
ID: 16562262
No, I have not use the TStatusbar, I have draw my own on the canvas.

Peter
0
 
LVL 1

Author Comment

by:peterkiers
ID: 16563124
Oke, I try another approach:

I have found an good example on the internet:

Procedure TDSP5250.Paint;
 var
  r:TRect;
  a,c:char;
  l1,l2,c1,c2:integer;
  x,y,o:integer;
  s:string;
 begin
  r:=Canvas.ClipRect;
  if r.Bottom>=fStatusRect.Top then begin
   Canvas.Brush.Color:=fStatusColor;
   Canvas.FillRect(fStatusRect);
   x:=fFontWidth div 2;
   y:=fStatusRect.Top;
   TextAttr:=$22;
   Canvas.TextOut(x,y,fStatus);
   if fInsert then Canvas.TextOut(Width div 2,y,'I');
   s:=IntToStr(WhereX)+'/'+IntToStr(WhereY);
   Canvas.TextOut(Width-Canvas.TextWidth(s)-x,y,s);
   dec(y);
   Canvas.Pen.Color:=clWhite;
   Canvas.MoveTo(0,y);
   Canvas.LineTo(Width,y);
  end;
end;

How can I implement the code below (where the column and row indicator is drawn) in
the code above?

  with Canvas do
    begin
          { display row and column indicator }
          Font.Color := FColorWhite ;
         TextOut(FFontWidthPix*74,SepY+2,Format('%.2d/%.3d',  
         [FCsrRow,FCsrCol])) ;
        end ;
  end ;

Peter
0
 
LVL 28

Expert Comment

by:2266180
ID: 16563194
what is 74? since it's hardcoded, it is likely to cause the issue.
0
 
LVL 1

Author Comment

by:peterkiers
ID: 16563365
I don't know either!

0
 
LVL 28

Expert Comment

by:2266180
ID: 16563436
well 74 is in YOUR code, you should know about it. from what it looks to me, it influences the position of the separator on teh x axis but that's all I can say about it.

also, I need you to confirm/infirm the following:  you resize the component, but the statusbar does not resize. true?

can you post the code that takes care of component resizeing?

0
 
LVL 1

Author Comment

by:peterkiers
ID: 16563486
TRUE.

procedure TDSP3270.WMSize(var Msg: TWMSize);
begin
   inherited;
  Resize;
end;

procedure TDSP3270.Resize;
begin
  inherited;
  fFontWidthPix :=ClientWidth  div (fSCRCOLS);
  fFontHeightPix:=(ClientHeight-2) div (fSCRROWS+1);
end;

0
 
LVL 28

Accepted Solution

by:
2266180 earned 750 total points
ID: 16564113
well, for the future, try naming your variables so that they are understandable because it is very hard to follow the logic/flow of stuff :) (for example, if you wrote fFontWidthPix it's pretty long as it is, so no one would have gone mad if you named it  fFontWidthPixel .. only 2 more chars. and thius is an example that I understand. there are other names I just can't make out what they do)
also, as a naming convention, you should name your variables in consideration with what they do or are used for. this helps a lot in debugging logical issues ;)

now getting into your problem. I hope I followed it well :)
I see 1 issue:
- every time the component gets painted, you assign a value to   FFontWidthPix and  FFontHeightPix .
- everytime you resize the component, another value is assigned to those variables (and right after resizeing, the component gets repaonted).
so basically those assignments are either eronuos or not necessary (and can be made once at component creation and then modified every time as needed)

the above might be the thing causing your issue. now I couldn't figure out what exactly you are using those two variables, but as a general rule, you should draw teh statusbar in respect to the component's dimensions. that will ensure among other things, that it is displayed correctly.

so instead of doing:

procedure TDSP3270.ShowStatus;
var
  StatY, SepX, SepY: integer ;
begin
  SepX := FSCRCOLS * FFontWidthPix ;
  SepY := FSCRROWS * FFontHeightPix ;
  StatY := FSCRROWS * FFontHeightPix + (FFontHeightPix+2) ;
  with Canvas do
    begin
      { draw seperator line }
      Pen.Mode := pmCopy ;
      Pen.Color := FColorWhite ;
      Brush.Style := bsClear ;
      Brush.Color := FColorBlack ;
      MoveTo(0,SepY) ;
      LineTo(SepX,SepY) ;

          { display row and column indicator }
          Font.Color := FColorWhite ;
         TextOut(FFontWidthPix*74,SepY+2,Format('%.2d/%.3d',  
         [FCsrRow,FCsrCol])) ;
        end ;
  end ;

do

procedure TDSP3270.ShowStatus;
var
//  StatY, not used
SepX, SepY: integer ;
begin
  SepX := FSCRCOLS * FFontWidthPix ;
  SepY := FSCRROWS * FFontHeightPix ;
//  StatY := FSCRROWS * FFontHeightPix + (FFontHeightPix+2) ; not used
  with Canvas do
    begin
      { draw seperator line }
      Pen.Mode := pmCopy ;
      Pen.Color := FColorWhite ;
      Brush.Style := bsClear ;
      Brush.Color := FColorBlack ;
      MoveTo(0,component heigh - statusbar height) ;
      LineTo(component width, component heigh - statusbar height) ;

          { display row and column indicator }
          Font.Color := FColorWhite ;
         TextOut(FFontWidthPix*74,SepY+2,Format('%.2d/%.3d',   // this one you calculate somehow according to your needs
         [FCsrRow,FCsrCol])) ;
        end ;
  end ;

of course, if you fix the issue I mentioned, it might also fix the statusbar not being resized correctly, but I cannot say for sure, since the statusbar is using those variables, but the component is overwriteing the values set by teh resize procedure.

cheers
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question