Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Reverses an input string and displays it in a text box.
- // WinForms - create a new form with these controls:
- // textboxes: textInput, textOutput
- // buttons: buttonCopy, buttonClear, buttonProcess
- using System;
- using System.Windows.Forms;
- namespace Reverse_A_String
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void ButtonProcess_Click(object sender, EventArgs e)
- {
- if (textInput.Text.Length < 2)
- {
- MessageBox.Show("Enter at least two characters and try again.");
- return;
- }
- string str = textInput.Text;
- textOutput.Text = Reverse(str);
- labelStatus.Text = "Processed";
- }
- public static string Reverse(string str)
- {
- char[] c = str.ToCharArray();
- Array.Reverse(c);
- str = string.Concat(c);
- return str;
- }
- private void ButtonClear_Click(object sender, EventArgs e)
- {
- textInput.Clear();
- textOutput.Clear();
- labelStatus.Text = ".....";
- textInput.Focus();
- }
- private void ButtonCopy_Click(object sender, EventArgs e)
- {
- try
- {
- Clipboard.SetText(textOutput.Text);
- labelStatus.Text = "Copied";
- }
- catch (Exception)
- {
- labelStatus.Text = "Error";
- }
- }
- private void TextOutput_TextChanged(object sender, EventArgs e)
- {
- labelStatus.Text = ".....";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement