label format with underline and bold in spots

Can you make a single label look like this
This is a test of what i want.


Answer this question

label format with underline and bold in spots

  • Pyush Kumar

    How about something along the following lines - using a RichtText control.

    <code>
    Local loForm
    loForm = CreateObject("clsForm")
    loForm.Show(1)
    loForm = Null

    Define Class clsForm As Form

     Add Object oRTF As OleControl ;
      With ;
        OleClass = "RichText.RichTextCtrl.1"
       
     Procedure oRTF.Init
     
      With This
       .Enabled = .F.
       .Height = 25
       .Width = 150
       .BorderStyle = 0
       .BackColor = .Parent.BackColor
       .Text = "Bold StrikeThru Underline"
       Store 0 To .SelStart, .SelLength
       .Find("Bold")
       .SelBold = .T.
       Store 0 To .SelStart, .SelLength
       .Find("StrikeThru")
       .SelStrikeThru = .T.
       Store 0 To .SelStart, .SelLength
       .Find("Underline")
       .SelUnderLine = .T.
       Store 0 To .SelStart, .SelLength
      EndWith
      
     EndProc
     
    EndDefine
    </code>

    HTH, Robbo.

     



  • Yozz

    If you are only talking about small portions of text, preferrably fixed text, you can use multiple labels instead of one. if the text is dynamic, you can use functions like TXTWIDTH() and FONTMETRIC() to determine how long each part. Here's a sample:

    Local lnPos
    lnPos = 0
    Write(@lnPos,"this is a",.f.)
    Write(@lnPos," test ",.t.)
    Write(@lnPos,"with bold.",.f.)

    Procedure Write( rnPos, tcText, tlBold )
        Local lcName, loLabel
        lcName = Sys(2015)
        _Screen.AddObject(m.lcName,"Label")
        loLabel = GetPem(_Screen,m.lcName)
        loLabel.Move(m.rnPos,0)
        loLabel.Caption = m.tcText
        loLabel.FontBold = m.tlBold
        loLabel.Visible = .T.
        rnPos = m.rnPos + ;
            Txtwidth(m.tcText,loLabel.FontName,loLabel.FontSize,Iif(m.tlBold,"B","N"))*;
            Fontmetric(6,loLabel.FontName,loLabel.FontSize,Iif(m.tlBold,"B","N"))
    EndProc




  • Sowbhagya

    You can set the font, underline, strikeout, etc, for a particular field on the label, but it would be applied to all words in the field. In VFP9, you might could do this with the use of a report listener. One of the report gurus will likely chime in on this one.

  • label format with underline and bold in spots