// Programmer: Janet Joy // Show advice using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Advice { public partial class Form1 : Form { List advice= new List { "Eat right", "Drink lots of water" }; Random random = new Random(); //declare random just once public Form1() { InitializeComponent(); } private void timer1_Tick(object sender, EventArgs e) { // Move the lblAdvice 1 position to the left. int yPos = lblAdvice.Location.Y; int xPos = lblAdvice.Location.X-1; // If the label has moved off the form on the left // restart on the right. if (xPos < 0 - lblAdvice.Width) { xPos = this.Width; newAdvice(); } lblAdvice.Location = new Point(xPos, yPos); } public void newAdvice() { // Select one of the items in advice list randomly int num= random.Next(0, advice.Count); lblAdvice.Text=advice.ElementAt(num); } private void btnAdd_Click(object sender, EventArgs e) { string s = txtAdvice.Text; if(s!="") { advice.Add(s); txtAdvice.Text = ""; } } } }