This Question is Answered

15 "helpful" answers available (3 pts)
6 Replies Last post: Jul 8, 2008 6:19 AM by Kamal

Which control should I take on a Canvas just looks like a label,and it has font properties such as font-family,font-style,font-weight and so on.

Jul 6, 2008 9:47 PM

Click to view Mirror's profile Level 1 Mirror 12 posts since
Jul 2, 2008

Which control should I take on a Canvas just looks like a label,and it has font properties such as font-family,font-style,font-weight and so on.

e.g.

{let str:String = "abc"}
{let c:Canvas = {Canvas height = 5cm, width = 8cm,background = "silver"}}
{let lb:Label = {Label
{text
font-weight = "bold",
font-size = 10pt,
font-style = "italic",
{str.to-String}
}
}
}

{value
{c.add
lb,
x = c.width / 2,
y = c.height / 2
}
c
}

But in project,that's not good to change each property after defined the label.

How should I do? Please help me.

Click to view URPradhan's profile Level 7 URPradhan 141 posts since
Mar 6, 2008
1. Re: Which control should I take on a Canvas just looks like a label,and it has font properties such as font-family,font-style,font-weight and so on. Jul 6, 2008 10:18 PM
For label purpose I use {text font-size ="", font-weight ="", color = "", font-style =""} etc .... But the porblem is I'm not able to change it later on. But you may use the read-only {TextDisplay} and twick its UI object.
Click to view tdeng's profile Level 3 tdeng 35 posts since
Oct 17, 2007
2. Re: Which control should I take on a Canvas just looks like a label,and it has font properties such as font-family,font-style,font-weight and so on. Jul 7, 2008 1:03 AM
We often use textflowbox for this purpose. You could change it's font properties after being initialized.


{let tfb:TextFlowBox =
{TextFlowBox background="pink", width = 3cm,
border-width=1pt,

"Sample String"

}
}


Unfortunately, it doesn't have a property such as value containing the content, so when you want to change the content of this textflowbox, you need to do somethign like this:

{tfb.clear}
{tfb.add "new string"}

Click to view Kamal's profile Curl Kamal 139 posts since
Oct 17, 2007
3. Re: Which control should I take on a Canvas just looks like a label,and it has font properties such as font-family,font-style,font-weight and so on. Jul 7, 2008 8:35 AM
in response to: URPradhan
Here is how you can construct your label so that you can change the font info later. This works because font-style is a non-local option.

{curl 6.0 applet}
{curl-file-attributes character-encoding = "windows-latin-1"}
 
 
{def txt = {Frame font-style = "italic", {text  Hello!}}}
 
{value txt}
 
{CheckButton
    label = "normal?",
    {on e:ValueChanged at cb:CheckButton do
        set txt.font-style =
            {if cb.value then
                "normal"
             else
                "italic"
            }
    }
}
 
Click to view Kamal's profile Curl Kamal 139 posts since
Oct 17, 2007
4. Re: Which control should I take on a Canvas just looks like a label,and it has font properties such as font-family,font-style,font-weight and so on. Jul 7, 2008 8:46 AM
If you have multiple labels and you want to assign to them some properties that are same, you can have a proc that creates a Graphic (that you want to use for a Label ) and set the common properties there. You can then change these properties later too.


{curl 6.0 applet}
{curl-file-attributes character-encoding = "windows-latin-1"}
 
{define-proc package {make-label str:String}:Graphic
 
    {return
        {Label
            font-size = 10,
            font-style = "italic",
            str
        }
    }
}
 
    
 
{def label1 = {make-label "Hello There!"}}
 
{value label1}
 
{CheckButton
    label = "normal?",
    {on e:ValueChanged at cb:CheckButton do
        set label1.font-style =
            {if cb.value then
                "normal"
             else
                "italic"
            }
    }
}
 
 
Click to view Mirror's profile Level 1 Mirror 12 posts since
Jul 2, 2008
5. Re: Which control should I take on a Canvas just looks like a label,and it has font properties such as font-family,font-style,font-weight and so on. Jul 7, 2008 10:21 PM
in response to: Kamal

Thank you.

It's a useful method.

I just take Label to set font-properties.It can do the same thing like Frame.

It dosen't have font-properties,but it can use the font-properties just like Frame.

There are lots of methods and properties I don't know.Learning......

Click to view Kamal's profile Curl Kamal 139 posts since
Oct 17, 2007
6. Re: Which control should I take on a Canvas just looks like a label,and it has font properties such as font-family,font-style,font-weight and so on. Jul 8, 2008 6:19 AM
in response to: Mirror
You should use "Label" instead of Frame. Try this


{curl 6.0 applet}
 
{Frame "hello &There"}
 
{Label "hello &There"}
 


Note that when you use Label, "T" is underlined. You can now use Alt+T to move the focus to the next element that can take focus which is after the Label.