zoukankan      html  css  js  c++  java
  • WPF RichTextBox 常用工具栏

    <Grid.Resources>
    <Style TargetType="{x:Type Button}" x:Key="formatTextStyle">
    <Setter Property="FontFamily" Value="Palatino Linotype"></Setter>
    <Setter Property="Width" Value="30"></Setter>
    <Setter Property="FontSize" Value ="14"></Setter>
    <Setter Property="CommandTarget" Value="{Binding ElementName=mainRTB}"></Setter>
    </Style>

    <Style TargetType="{x:Type Button}" x:Key="formatImageStyle">
    <Setter Property="Width" Value="30"></Setter>
    <Setter Property="CommandTarget" Value="{Binding ElementName=mainRTB}"></Setter>
    </Style>
    </Grid.Resources>
    <ToolBar Name="mainToolBar" Grid.Row="2" Grid.ColumnSpan="2">

    <Button Style="{StaticResource formatImageStyle}" Command="ApplicationCommands.Cut" ToolTip="剪切">
    <Image Source="..\Images\EditCut.png"></Image>
    </Button>
    <Button Style="{StaticResource formatImageStyle}" Command="ApplicationCommands.Copy" ToolTip="复制">
    <Image Source="..\Images\EditCopy.png"></Image>
    </Button>
    <Button Style="{StaticResource formatImageStyle}" Command="ApplicationCommands.Paste" ToolTip="粘贴">
    <Image Source="..\Images\EditPaste.png"></Image>
    </Button>
    <Button Style="{StaticResource formatImageStyle}" Command="ApplicationCommands.Undo" ToolTip="撤销">
    <Image Source="..\Images\EditUndo.png"></Image>
    </Button>
    <Button Style="{StaticResource formatImageStyle}" Command="ApplicationCommands.Redo" ToolTip="重做">
    <Image Source="..\Images\EditRedo.png"></Image>
    </Button>

    <Button Style="{StaticResource formatTextStyle}" Command="EditingCommands.ToggleBold" ToolTip="加粗">
    <TextBlock FontWeight="Bold">B</TextBlock>
    </Button>

    <Button Style="{StaticResource formatTextStyle}" Command="EditingCommands.ToggleItalic" ToolTip="斜体">
    <TextBlock FontStyle="Italic" FontWeight="Bold">I</TextBlock>
    </Button>
    <Button Style="{StaticResource formatTextStyle}" Command="EditingCommands.ToggleUnderline" ToolTip="下划线">
    <TextBlock TextDecorations="Underline" FontWeight="Bold">U</TextBlock>
    </Button>
    <Button Style="{StaticResource formatTextStyle}" ToolTip="加红" Click="tbnRed_Click">
    <TextBlock Foreground="Red"></TextBlock>
    </Button>
    <Button Style="{StaticResource formatImageStyle}" Command="EditingCommands.IncreaseFontSize" ToolTip="增大字体">
    <Image Source="..\Images\CharacterGrowFont.png"></Image>
    </Button>
    <Button Style="{StaticResource formatImageStyle}" Command="EditingCommands.DecreaseFontSize" ToolTip="缩小字体">
    <Image Source="..\Images\CharacterShrinkFont.png"></Image>
    </Button>

    <Button Style="{StaticResource formatImageStyle}" Command="EditingCommands.ToggleBullets" ToolTip="项目符号">
    <Image Source="..\Images\ListBullets.png"></Image>
    </Button>
    <Button Style="{StaticResource formatImageStyle}" Command="EditingCommands.ToggleNumbering" ToolTip="项目编号">
    <Image Source="..\Images\ListNumbering.png"></Image>
    </Button>
    <Button Style="{StaticResource formatImageStyle}" Command="EditingCommands.AlignLeft" ToolTip="居左">
    <Image Source="..\Images\ParagraphLeftJustify.png"></Image>
    </Button>
    <Button Style="{StaticResource formatImageStyle}" Command="EditingCommands.AlignCenter" ToolTip="居中">
    <Image Source="..\Images\ParagraphCenterJustify.png"></Image>
    </Button>
    <Button Style="{StaticResource formatImageStyle}" Command="EditingCommands.AlignRight" ToolTip="居右">
    <Image Source="..\Images\ParagraphRightJustify.png"></Image>
    </Button>
    <Button Style="{StaticResource formatImageStyle}" Command="EditingCommands.AlignJustify" ToolTip="两端对齐">
    <Image Source="..\Images\ParagraphFullJustify.png"></Image>
    </Button>



    </ToolBar>
      private void tbnBold_Click(object sender, RoutedEventArgs e)
    {
    if ((FontWeight)rtbContent.Selection.GetPropertyValue(TextElement.FontWeightProperty) == FontWeights.Bold)
    rtbContent.Selection.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Normal);
    else

    rtbContent.Selection.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold);
    //ToolBarContentCenter.Command = System.Windows.Documents.EditingCommands.AlignCenter;
    }

    private void tbnRed_Click(object sender, RoutedEventArgs e)
    {
    if ((Brush)rtbContent.Selection.GetPropertyValue(TextElement.ForegroundProperty) == Brushes.Red)
    rtbContent.Selection.ApplyPropertyValue(TextElement.ForegroundProperty,Brushes.Black );
    else

    rtbContent.Selection.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Red);
    }



    转载请注明出处。
  • 相关阅读:
    leetcode:Invert Binary Tree
    leetcode:Excel Sheet Column Number
    Unicode与ASCiI之间有什么区别?java当中的转义字符 Character类的使用 String类的使用
    Java程序设计第四次作业内容 第五次作业10月9号发布,为第三章全部例题
    RuPengGame游戏引擎 精灵 createSprite 创建 setSpritePosition 设置位置 playSpriteAnimate 播放动画 setSpriteFlipX设置翻转 精灵图片下载地址
    Java第六次作业:RuPengGame setGameSize setGameTitle alert loadBgView playSound pause closeSound confirm input createText setTextPosition setTextColor setTextFontSize hideText showText CreateImage(number)
    eclipse 导出Runnable JAR file ,双击无法执行原因与解决 双击后闪退的原因 批处理java打包文件 @echo off start javaw -jar *.jar
    c++ 作业 10月13日 进制转换最简单方法,控制c++输出格式方法 教材50的表格自己实践一下 例题3.1 setfill() setw()
    c++ 软件下载 Dev cpp下载
    使用 RuPengGame游戏引擎包 建立游戏窗体 如鹏游戏引擎包下载地址 Thread Runnable 卖票实例
  • 原文地址:https://www.cnblogs.com/Laro/p/2436292.html
Copyright © 2011-2022 走看看