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!");

    }

    }

    }

  • 相关阅读:
    ExtJS4 动态生成grid出口excel(纯粹的接待)
    oracle10g获得Date类型字段无分,秒的解决方案!
    ubuntu13.10 下一个 g++和gcc 4.8不兼容的问题不能被安装
    简单的导航
    Duanxx的C++学习 : 数字转换String
    图widget--jqplot样品和参数描述的简单演示
    m_Orchestrate learning system---三十、项目中的dist文件一般是做什么的
    开放windows服务器端口-----以打开端口8080为例
    phpstudy一个域名配置两个网站(一个是thinkphp5,一个是原生php)
    双向绑定的具体应用场景有哪些
  • 原文地址:https://www.cnblogs.com/teamleader/p/4192216.html
Copyright © 2011-2022 走看看