zoukankan      html  css  js  c++  java
  • Base64 Converter

    <Window x:Class="Base64Convertor.MainWindow"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    Title="MainWindow" Height="387" Width="629">

    <Grid>

    <Grid.RowDefinitions>

    <RowDefinition/>

    <RowDefinition Height="auto"/>

    <RowDefinition/>

    </Grid.RowDefinitions>

    <GroupBox Grid.Row="0" Header="Input" HorizontalAlignment="Stretch" Margin="0,0,0,0" Name="groupBox1" VerticalAlignment="Stretch">

    <TextBox Name="txtInput" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="Yellow" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" AcceptsReturn="True" />

    </GroupBox>

     

    <TabControl Grid.Row="1">

    <TabItem Header="Encode" >

    <StackPanel Grid.Row="1" Orientation="Horizontal">

    <Button Name="btnEncodeInputText" Content="From Input Text" Height="25" Margin="5" Click="btnEncodeInputText_Click" />

    <Button Name="btnEncodeInputFile" Content="From Input File" Height="25" Margin="5" Click="btnEncodeInputFile_Click" />

    <Button Name="btnCopyToClipboard" Content="Copy to Clipboard" Height="25" Margin="5" Click="btnCopyToClipboard_Click" />

    </StackPanel>

    </TabItem>

    <TabItem Header="Decode">

    <StackPanel Grid.Row="1" Orientation="Horizontal">

    <Button Name="btnDecodeToOutput" Content="Decode to Output" Margin="5" Height="25" Click="btnDecodeToOutput_Click" />

    <Button Name="btnDecodeToFile" Content="Decode to File" Height="25" Margin="5" Click="btnDecodeToFile_Click" />

    </StackPanel>

    </TabItem>

    </TabControl>

     

    <GroupBox Grid.Row="2" Header="Output" HorizontalAlignment="Stretch" Margin="0,0,0,0" Name="groupBox2" VerticalAlignment="Stretch">

    <TextBox Name="txtOutput" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="Yellow" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" AcceptsReturn="True" />

    </GroupBox>

    </Grid>

    </Window>

     

    public partial class MainWindow : Window

    {

    public MainWindow()

    {

    InitializeComponent();

    }

     

    private void btnEncodeInputText_Click(object sender, RoutedEventArgs e)

    {

    txtOutput.Text = Convert.ToBase64String(Encoding.UTF8.GetBytes(txtInput.Text.Trim()));

    }

     

    private void btnDecodeToOutput_Click(object sender, RoutedEventArgs e)

    {

    txtOutput.Text = Encoding.UTF8.GetString(Convert.FromBase64String(txtInput.Text.Trim()));

    }

     

    private void btnEncodeInputFile_Click(object sender, RoutedEventArgs e)

    {

    OpenFileDialog ofd = new OpenFileDialog();

    if (ofd.ShowDialog().Value == true)

    {

    var fileContent = File.ReadAllBytes(ofd.FileName);

    txtOutput.Text = Convert.ToBase64String(fileContent);

    MessageBox.Show("done!");

    }

    }

     

    private void btnCopyToClipboard_Click(object sender, RoutedEventArgs e)

    {

    Clipboard.SetText(txtOutput.Text);

    }

     

    private void btnDecodeToFile_Click(object sender, RoutedEventArgs e)

    {

    SaveFileDialog sfd = new SaveFileDialog();

    if (sfd.ShowDialog().Value == true)

    {

    var fileContent = Convert.FromBase64String(txtInput.Text.Trim());

    File.WriteAllBytes(sfd.FileName, fileContent);

    MessageBox.Show("done!");

    }

    }

    }

  • 相关阅读:
    【Django】CSRF token missing or incorrect问题处理
    【Go】Hello World!
    【Element UI】axios 与 request.js配置
    【Element UI】 使用弹窗组件关闭时的传值修改 / 报错:Avoid mutating a prop directly since the value will be overwritten
    【Pyqt5】QT designer与 pycharm的配置
    Python 冒泡排序的优化
    skywalking/8.5部署
    nginx缓存加速笔记
    记拼多多快团团api php 调用接口类
    记拼多多 快团团 php 快团团创建团购接口 增加商品库存接口 规格创建 上传商品图等接口
  • 原文地址:https://www.cnblogs.com/teamleader/p/4192216.html
Copyright © 2011-2022 走看看