WPF控件10

RadioButton:单选按钮。

XAMl

<StackPanel>

        <TextBox Name="txtb"/>

        <RadioButton Name="rb1" Checked="WriteText" Content="Yes"></RadioButton>

        <RadioButton Name="rb2" Checked="WriteText">

            <Image Source="tx/tx 06.jpg" Width="33"/>

        </RadioButton>

        <RadioButton Name="rb3" Checked="WriteText">No Opinion</RadioButton>

        <StackPanel>

            <RadioButton GroupName="sex"></RadioButton>

            <RadioButton GroupName="sex"></RadioButton>

            <RadioButton GroupName="numgrp"></RadioButton>

            <RadioButton GroupName="numgrp"></RadioButton>

        </StackPanel>

    </StackPanel>

C#

public partial class RadioButtonDemo : Window

    {

        public RadioButtonDemo()

        {

            InitializeComponent();

        }

        private void WriteText(object sender, RoutedEventArgs e)

        {

            RadioButton radio = (RadioButton)sender;

            txtb.Text = "You Clicked "+ radio.Content.ToString() + ".";

        }

    }

效果:

Rectangle:实心矩形。

XAML

<Rectangle Width="111" Height="111" Fill="AliceBlue" Stroke="Aquamarine" StrokeThickness="5" RadiusX="55" RadiusY="55"></Rectangle>

效果:

C#

public partial class RectangleDemo : Window

    {

        public RectangleDemo()

        {

            InitializeComponent();

            Init();

        }

        private void Init()

        {

            //添加举行元素

            Rectangle myRect = new Rectangle();

            myRect.Stroke = System.Windows.Media.Brushes.Black;//笔触(边框)颜色

            myRect.Fill = System.Windows.Media.Brushes.SkyBlue; ;//填充颜色

            myRect.HorizontalAlignment = HorizontalAlignment.Left;//水平对齐方式

            myRect.VerticalAlignment = VerticalAlignment.Center;//垂直对齐方式

            myRect.Width = 55;

            myRect.Height = 55;

            this.Content = myRect;

        }

    }

效果:

RichTextBox:富文本输入框。

XAML

<RichTextBox Name="richTB">

        <FlowDocument FontSize="24" Foreground="SkyBlue" Background="AliceBlue">

            <Paragraph>

                <Run>Paragraph 1</Run>

            </Paragraph>

            <Paragraph>

                <Run>Paragraph 2</Run>

            </Paragraph>

            <Paragraph>

                <Run>Paragraph 3</Run>

            </Paragraph>

        </FlowDocument>

    </RichTextBox>

效果:

C#

public partial class RichTextBoxDemo : Window

    {

        public RichTextBoxDemo()

        {

            Init();

            InitializeComponent();

        }

        private void Init()

        {

            //StackPanel myStackPanel = new StackPanel();

            //创建一个FlowDocument来包含RichTextBox的内容。

            FlowDocument myFlowDoc = new FlowDocument();

            RichTextBox myRichTextBox = new RichTextBox();

            //向RichTextBox添加初始内容

            myRichTextBox.Document = myFlowDoc;

            //向FlowDocument添加段落。

            myFlowDoc.Blocks.Add(new Paragraph(new Run("Paragraph 1")));

            myFlowDoc.Blocks.Add(new Paragraph(new Run("Paragraph 2")));

            myFlowDoc.Blocks.Add(new Paragraph(new Run("Paragraph 3")));

            //向StackPanel添加子集

            //myStackPanel.Children.Add(myRichTextBox);

            //设置页面内容为StackPanel

            //this.Content = myStackPanel;

            this.Content = myRichTextBox;

        }

    }

效果:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值