Click here to Skip to main content
15,886,664 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to have a long textbox where the user types the reminder, and at the end of the long textbox, in a short textbox, the user types a time like 10:34:15 AM and then they click a button named "ADD REMINDER" and after they add it, at the time in the short textbox, the reminder goes off in a message box

[EDIT OP code from solution]
C#
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 Calander
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            timer1.Start();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            label1.Text = System.DateTime.Now.ToLongTimeString();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("The Reminder:\n" +"~" + textBox1.Text +"~" + "\nWas Added To Alert At:\n" + dateTimePicker1.Text, "Reminder Was Added", MessageBoxButtons.OK, MessageBoxIcon.Information);
            dateTimePicker1.Text = MessageBox.Show(textBox1.Text +);
        }
    }
}
Posted
Updated 12-Apr-14 7:27am
v2
Comments
PIEBALDconsult 12-Apr-14 12:22pm    
Use a DateTimePicker for date/time values; not a TextBox.
Are you expecting the user to keep the application running constantly?
Member 10640251 12-Apr-14 12:26pm    
No
CHill60 12-Apr-14 12:42pm    
What have you tried so far?
Member 10640251 12-Apr-14 12:46pm    
Well I added the DateTimePicker, and I tried getting its time, and then sending messagebox with textbox's text
Member 10640251 12-Apr-14 12:51pm    
Nothing worked

1 solution

The line
C#
dateTimePicker1.Text = MessageBox.Show(textBox1.Text +);

is going to cause you two errors

1. There is a spurious + sign after textBox1.Text
2. MessageBox.Show does not return a string. Even if you add .ToString() to it you will then get an error from the dateTimePicker saying that the text you are trying to insert into it is not a valid datetime format
Change the line to
MessageBox.Show(textBox1.Text);
or preferably just remove it altogether - it's only repeating some of the stuff from the previous message

[EDIT - some further assistance for the OP]
Things to consider ...
Don't start your timer when you load the form, start it after the time has been changed by the user... and make sure it is enabled e.g.
C#
private void button1_Click(object sender, EventArgs e)
{
    myTimer.Enabled = true;
    myTimer.Start();
}

You actually only want the message box to appear if the time for the reminder has passed,
so you will need to compare the current date & time against that set in the datetimepicker e.g.
C#
if (DateTime.Now >= this.dateTimePicker2.Value)
    {
		MessageBox.Show(this.textBox1.Text);
		// This next bit stops the message box reappearing again
		myTimer.Enabled = false;
	}

Finally, make sure your DateTimePicker is set to the correct format
C#
dateTimePicker2.Format = DateTimePickerFormat.Time;


If you are still struggling then have a read of this CodeProject article Use a timer to create a simple alarm application[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900