3
我使用Visual Studio 2008,我需要能夠使用表達式調整字體大小。 到目前爲止,我有,如何使用VB 2008調整字體?
IIf((Len(First(Fields!CardID.Value, "data"))> 30), "12 pt", "72 pt")
我知道我要引用LEN變量獲得總字符的大小,但我不知道怎麼樣。
任何意見,將不勝感激。
預先感謝
我使用Visual Studio 2008,我需要能夠使用表達式調整字體大小。 到目前爲止,我有,如何使用VB 2008調整字體?
IIf((Len(First(Fields!CardID.Value, "data"))> 30), "12 pt", "72 pt")
我知道我要引用LEN變量獲得總字符的大小,但我不知道怎麼樣。
任何意見,將不勝感激。
預先感謝
對於Winforms中,下面給出的是一個示例。這有點麻煩,但它工作得很好。在這個例子中,有一個帶有按鈕Button1
的窗體,文本框TextBox1
以及標籤Label1
。當單擊Button1
時,TextBox1
中的文本適用於Label1
的可用空間。
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text = "" Then
Exit Sub
End If
Dim fnt As New Font("Tahoma", 1, FontStyle.Regular)
Dim g As Graphics = Me.CreateGraphics
Dim i As Int32 = 0
Dim boxWidth As Integer = Label1.Width
Dim textWidth As Double = 0
Dim someSmallAmountToAccountForLabelPadding As Int16 = 5
Do While textWidth < boxWidth - someSmallAmountToAccountForLabelPadding
i += 1
fnt = New Font("Tahoma", i, FontStyle.Regular)
textWidth = g.MeasureString(TextBox1.Text, fnt).Width
Loop
Label1.Text = TextBox1.Text
Label1.Font = fnt
g.Dispose()
End Sub
對於WPF,你甚至不需要任何代碼,只是視框。下面顯示的XAML具有帶TextBox的窗口tbx1
和TextBlock。無論你在tbx1
類型自動適應TextBlock的這視框,然後或是放大縮小到適合的可用空間,在不在。
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<TextBox Margin="20,8" Name="tbx1"/>
<Viewbox Grid.Row="1" Stretch="Fill">
<TextBlock Text="{Binding ElementName=tbx1, Path=Text}" />
</Viewbox>
</Grid>
您可以視框的拉伸性,以達到不同的效果試驗。
我也有這個,, = str(60-len(First(Fields!Full_Name.Value,「data」)))+「pt」,但它對大多數時間起作用,但對於這個dosen't 。無論最大合適的尺寸是多少,我都需要填充該框 – Leigh 2012-02-09 11:01:19
您是使用Winforms還是WPF?你想填寫什麼樣的'盒子'? – Stewbob 2012-02-09 17:04:10