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

    }

    }

    }

  • 相关阅读:
    POJ 1795 DNA Laboratory
    CodeForces 303B Rectangle Puzzle II
    HDU 2197 本源串
    HDU 5965 扫雷
    POJ 3099 Go Go Gorelians
    CodeForces 762D Maximum path
    CodeForces 731C Socks
    HDU 1231 最大连续子序列
    HDU 5650 so easy
    大话接口隐私与安全 转载
  • 原文地址:https://www.cnblogs.com/teamleader/p/4192216.html
Copyright © 2011-2022 走看看