Dim enteredtext AS STRING = mytextbox.text
mylabel.content = enteredtext
如何使用户在文本框中输入的输入文本以粗体斜体或下划线打印到标签。应使用单选按钮启用这三个选项。
答案 0 :(得分:6)
您可以为它们设置字体样式。 e.g:
mylabel.FontStyle = FontStyles.Italic
答案 1 :(得分:1)
您可以参考以下代码。
<Grid>
<StackPanel>
<StackPanel Orientation="Horizontal">
<RadioButton x:Name="rdBold" Checked="RadioButton_Checked" Content="Bold" GroupName="format"/>
<RadioButton x:Name="rdItalics" Checked="rdItalics_Checked" Content="Italics" GroupName="format"/>
<RadioButton x:Name="rdUnderline" Checked="rdUnderline_Checked" Content="Underline" GroupName="format"/>
</StackPanel>
<TextBox x:Name="txtBx" Width="200" Height="20"/>
<TextBlock x:Name="txtBlk" Text="{Binding ElementName=txtBx,Path=Text}"/>
</StackPanel>
</Grid>
Class MainWindow
Private Sub RadioButton_Checked(sender As Object, e As RoutedEventArgs)
txtBlk.FontWeight = FontWeights.Bold
txtBlk.FontStyle = FontStyles.Normal
txtBlk.TextDecorations = Nothing
End Sub
Private Sub rdItalics_Checked(sender As Object, e As RoutedEventArgs)
txtBlk.FontWeight = FontWeights.Normal
txtBlk.FontStyle = FontStyles.Italic
txtBlk.TextDecorations = Nothing
End Sub
Private Sub rdUnderline_Checked(sender As Object, e As RoutedEventArgs)
txtBlk.FontWeight = FontWeights.Normal
txtBlk.FontStyle = FontStyles.Normal
txtBlk.TextDecorations = TextDecorations.Underline
End Sub
结束班
答案 2 :(得分:1)
如上所述,如果您有时只是这样做而希望在后面的代码中执行此操作,则可以使用mylabel.FontStyle = FontStyles.Italic
,或者如果标签始终需要加粗,您可以查看属性选项卡中的字体部分并选择colur,size,bold,italics,underline,strikeout等。