Homework 1_A

Create, in both languages C# and VB.NET, a program which does the following simple tasks:

  • When a button is pressed some text appears in a richtexbox on the startup form
  • When another button is pressed the richtextbox is cleared
  • When the mouse enters the richtextbox, the richtext backcolor is switched to another color
  • When the mouse leaves the richtextbox, the richtext backcolor is reset to its original state

VB.NET

Public Class Form1
    Private Sub BtnAppears_Click(sender As Object, e As EventArgs) Handles BtnAppears.Click
        Me.TxtGeneral.AppendText("Some text appears" & Environment.NewLine)
    End Sub

    Private Sub BtnClear_Click(sender As Object, e As EventArgs) Handles BtnClear.Click
        Me.TxtGeneral.Clear()
    End Sub

    Private Sub TxtGeneral_MouseEnter(sender As Object, e As EventArgs) Handles TxtGeneral.MouseEnter
        Me.TxtGeneral.BackColor = Color.Blue
    End Sub

    Private Sub TxtGeneral_MouseLeave(sender As Object, e As EventArgs) Handles TxtGeneral.MouseLeave
        Me.TxtGeneral.BackColor = SystemColors.Window
    End Sub
End Class

C#

namespace Application1_C
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void BtnAppears_Click(object sender, EventArgs e)
        {
            this.TxtGeneral.AppendText("Some text appears" + Environment.NewLine);
        }

        private void BntClear_Click(object sender, EventArgs e)
        {
            this.TxtGeneral.ResetText();
        }

        private void TxtGeneral_MouseEnter(object sender, EventArgs e)
        {
            this.TxtGeneral.BackColor = Color.Red;
        }

        private void TxtGeneral_MouseLeave(object sender, EventArgs e)
        {
            this.TxtGeneral.BackColor = default(Color);
        }
    }
}

Lascia un commento