We help IT Professionals succeed at work.

I need a help to transfer a text to a scrollbox creating edits and labes

hidrau
hidrau asked
on
460 Views
Last Modified: 2014-08-31
Hello guys,

I have a text in a memoedit and I have scrollbox. I would like to transfer my text to scrollbox where
each word will turn into in a label or edit inside of my scrollbox.  

For exemple

Well, to create all words as label or edit in a scrollbox it is ok for me, I developed the code as you can see over here but I am having  a problem, if I change the scrollbox font size, some labels is over to another.

I don't know how to workaround with it, that is, how to consider the font size of my scrollbox and to give
the right space between labels and edits. Esq is a variable where is passed the value of left space.

Take a look at part of my code where my function create the labels and edits

  Function CriaObj(Obj: TWinControl; Esq, Topo, idx :Integer; Word, Tipo: String):Integer;
  var
    L   : TsLabel;
    Tam :Integer;
  begin

    if Tipo = 'Label' then
    begin
      L:=TsLabel.Create(Self);
      L.Parent  := Obj;
      L.Caption := UpperCase(Word);
      If ckDica.Checked Then
      Begin
        L.Hint := BuscaPalavraDicionario(IdiomaAtivo, Word);
      End;

      L.Tag := 1;
      L.Name := 'L' + IntToStr(idx);
      // L.Font.Style := [fsBold];
      L.SetBounds(Esq,Topo,100,15);
      // L.OnDblClick := TraduzPalavra;
      // L.OnMouseDown := LabelExpressao;
      Result:=Esq+Canvas.TextWidth(L.Caption)+10;
    end
    else
    begin
      SetLength(Edits,ContEdits+1);
      Edits[ContEdits]:=TsEdit.Create(Obj);
      Edits[ContEdits].Parent:=Obj;
      Edits[ContEdits].BorderStyle:=bsSingle;
      Edits[ContEdits].Text:='';
      // Edits[ContEdits].Font.Style := [fsBold];
      Edits[ContEdits].OnEnter := OnEnter;

      If ckDica.Checked Then
      Begin
        Edits[ContEdits].Hint := BuscaPalavraDicionario(IdiomaAtivo, Palavra);
        Edits[ContEdits].ShowHint := false;
      End;

      Edits[ContEdits].Ctl3D := False;
      Edits[ContEdits].Tag   := ContEdits;
      Edits[ContEdits].MaxLength:=Length(Palavra);
      Tam:=Canvas.TextWidth(Palavra)+10;
      Edits[ContEdits].SetBounds(Esq+3,Topo,Tam,15);
      Inc(ContEdits);
      Result:=Esq+Tam+10;
    End
  End;

Open in new window


I'd like a help on this
Thanks
Alex
Comment
Watch Question

Sinisa VukSoftware architect
CERTIFIED EXPERT
Top Expert 2012
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
ok, I will try it.

Author

Commented:
Sinisav, your answer it is not what I need to do.

When I create the labes and edit in the scrollbox on the fontsize 8, all the labes and edits go on fine.

but when I change the scrollbox fontsize to 10, it starts the error, some labes is being created over another.

if I increase the fontsize, the problem increase.

I need a way to take into account the fontsize of my scrollbox. Please, check the images that is small part of my screen where is the scrollbox with labels.
image1.fw.png

Author

Commented:
see the other images
image2.fw.png
image3.fw.png
Geert GOracle dba
CERTIFIED EXPERT
Top Expert 2009
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Hello Geert Gruwez,

I use Delphi XE4.

I tried your example, it worked as you told but there was a problem, when my text is long, the floatpanel doesn't

allow scrollbar to scroll the text, please, see the image:

The problem
Geert GOracle dba
CERTIFIED EXPERT
Top Expert 2009

Commented:
ugh ... so you need a flowpanel with a scrollbar ?
drat ... it's not descending from TScrollingWinControl
... i'll figure that out tomorrow

Author

Commented:
Well, I was creating all labels and edits directly on the scrollbox, but flowPanel gives me a right and easy way to create the labels and edits without any calculations. The problem is that I have some long text when created the labels and edits they will go beyond the button of my FlowPanel. With a scrollbox, it creates automatically the vertical scroll-bar.

Did you get it?
Sinisa VukSoftware architect
CERTIFIED EXPERT
Top Expert 2012
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
hummm, I didn't think on this possibility. I will try something, let me see.
Geert GOracle dba
CERTIFIED EXPERT
Top Expert 2009

Commented:
i was thinking of adding scrollbars to the flowpanel
and optionally resize ... but if you set this to align = alClient and use the form resize the flowpanel should resize accordingly
Oracle dba
CERTIFIED EXPERT
Top Expert 2009
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Geert GOracle dba
CERTIFIED EXPERT
Top Expert 2009

Commented:
and here is an image
without scrollbar
no scrollbar
and with scrollbar
with scrollbar

Author

Commented:
Hello Geert Gruwez,

Yeah, your idea is valid, but I need to adjust it in my program.

Only one flowPanel is not a good idea because the text isn't displayed as

it is in my memoedit. If you see my text, you will notice that is a music and I need

to display it the way it is, that is, Line by Line.

Author

Commented:
thanks very much,

all of you helped me to reach the result :)
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.