I'm making a program that was created to send text as you set it at a certain delay with a stop and start button etc.

I finished my GUI first, then went on to creating the controls and functionality portion of the program, and I've come to a halt.

Theres a few problems. Heres the main piece of code that my few problems are located in -

public GUI()
        {
            InitializeComponent();
            //This is the part needed to create a custom shaped Form
            this.FormBorderStyle = FormBorderStyle.None;
            this.Width = this.BackgroundImage.Width;
            this.Height = this.BackgroundImage.Height;
            this.TransparencyKey = Color.FromArgb(0, 255, 0); //Can be your own color 
                   Timer Clock;
                   Clock=new Timer();
	           Clock.Interval=5000;
 		   Clock.Tick+=new EventHandler(Timer_Tick);
        }
        
        public void START_Click(object sender, EventArgs e)
        {
					Clock.Start();	
        }
        public void STOP_Click(object sender, EventArgs e)
        {
					Clock.Stop();
        }
			 public void Timer_Tick(object sender,EventArgs eArgs)
  			{
			
                        SendKeys.Send(textBox1.Text);
			SendKeys.Send("{ENTER}");
			SendKeys.Send(textBox2.Text);
			SendKeys.Send("{ENTER}");
			SendKeys.Send(textBox3.Text);
			SendKeys.Send("{ENTER}");
			SendKeys.Send(textBox4.Text);
			SendKeys.Send("{ENTER}");
			
			}

I can't compile it because it says it doesn't recognize 'Clock' in the START and STOP buttons.

Obviousl, when the program is initiated it goes and sets the height etc for the window, then its supposed to set the timer.

I guess it doesn't.

Help?

EDIT:: Also, how would I make a label increase in numbers every time the timer ticks? Since labels run in strings, I don't know how I would do this..

Thanks

You need to declare your Timer outside the scope of the constructor or else it goes out of scope and is no longer accessible, as you are seeing currently.

Try this:

Timer Clock;
        public GUI()
        {
            InitializeComponent();
            //This is the part needed to create a custom shaped Form
            this.FormBorderStyle = FormBorderStyle.None;
            this.Width = this.BackgroundImage.Width;
            this.Height = this.BackgroundImage.Height;
            this.TransparencyKey = Color.FromArgb(0, 255, 0); //Can be your own color 
                   Clock=new Timer();
	           Clock.Interval=5000;
 		   Clock.Tick+=new EventHandler(Timer_Tick);
        }
        
        public void START_Click(object sender, EventArgs e)
        {
					Clock.Start();	
        }
        public void STOP_Click(object sender, EventArgs e)
        {
					Clock.Stop();
        }
			 public void Timer_Tick(object sender,EventArgs eArgs)
  			{
			
                        SendKeys.Send(textBox1.Text);
			SendKeys.Send("{ENTER}");
			SendKeys.Send(textBox2.Text);
			SendKeys.Send("{ENTER}");
			SendKeys.Send(textBox3.Text);
			SendKeys.Send("{ENTER}");
			SendKeys.Send(textBox4.Text);
			SendKeys.Send("{ENTER}");
			
			}

Thanks. Works perfectly.

Do you have any input on the label idea?

Timer Clock;
                   int cnt;
        public GUI()
        {
            InitializeComponent();
            //This is the part needed to create a custom shaped Form
            this.FormBorderStyle = FormBorderStyle.None;
            this.Width = this.BackgroundImage.Width;
            this.Height = this.BackgroundImage.Height;
            this.TransparencyKey = Color.FromArgb(0, 255, 0); //Can be your own color 
                   Clock=new Timer();
	           Clock.Interval=5000;
 		   Clock.Tick+=new EventHandler(Timer_Tick);
            cnt = default(int);
        }
        
        public void START_Click(object sender, EventArgs e)
        {
					Clock.Start();	
        }
        public void STOP_Click(object sender, EventArgs e)
        {
					Clock.Stop();
        }
			 public void Timer_Tick(object sender,EventArgs eArgs)
  			{
			string labelText = string.Format("The timer has elapsed {0:F0} times", cnt++);
                        //set your label1.Text = labelText;
                        SendKeys.Send(textBox1.Text);
			SendKeys.Send("{ENTER}");
			SendKeys.Send(textBox2.Text);
			SendKeys.Send("{ENTER}");
			SendKeys.Send(textBox3.Text);
			SendKeys.Send("{ENTER}");
			SendKeys.Send(textBox4.Text);
			SendKeys.Send("{ENTER}");
			
			}

In GUI Constructor
write this code
clock.Enabled=true;

write this code inside timer click event section
Label1.Text = GetDate();

private string GetDate()
{
string hour, min, second;
hour = DateTime.Now.Hour.ToString();
min = DateTime.Now.Minute.ToString();
second = DateTime.Now.Second.ToString();
return (hour + ":" + min + ":" + second);
}


I'm making a program that was created to send text as you set it at a certain delay with a stop and start button etc.

I finished my GUI first, then went on to creating the controls and functionality portion of the program, and I've come to a halt.

Theres a few problems. Heres the main piece of code that my few problems are located in -

public GUI()
        {
            InitializeComponent();
            //This is the part needed to create a custom shaped Form
            this.FormBorderStyle = FormBorderStyle.None;
            this.Width = this.BackgroundImage.Width;
            this.Height = this.BackgroundImage.Height;
            this.TransparencyKey = Color.FromArgb(0, 255, 0); //Can be your own color 
                   Timer Clock;
                   Clock=new Timer();
	           Clock.Interval=5000;
 		   Clock.Tick+=new EventHandler(Timer_Tick);
        }
        
        public void START_Click(object sender, EventArgs e)
        {
					Clock.Start();	
        }
        public void STOP_Click(object sender, EventArgs e)
        {
					Clock.Stop();
        }
			 public void Timer_Tick(object sender,EventArgs eArgs)
  			{
			
                        SendKeys.Send(textBox1.Text);
			SendKeys.Send("{ENTER}");
			SendKeys.Send(textBox2.Text);
			SendKeys.Send("{ENTER}");
			SendKeys.Send(textBox3.Text);
			SendKeys.Send("{ENTER}");
			SendKeys.Send(textBox4.Text);
			SendKeys.Send("{ENTER}");
			
			}

I can't compile it because it says it doesn't recognize 'Clock' in the START and STOP buttons.

Obviousl, when the program is initiated it goes and sets the height etc for the window, then its supposed to set the timer.

I guess it doesn't.

Help?

EDIT:: Also, how would I make a label increase in numbers every time the timer ticks? Since labels run in strings, I don't know how I would do this..

Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.