码迷,mamicode.com
首页 > 其他好文 > 详细

Base64 Converter

时间:2014-12-29 19:50:48      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:

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

}

}

}

Base64 Converter

标签:

原文地址:http://www.cnblogs.com/teamleader/p/4192216.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!