我如何创建提醒系统? [英] How Would I Create A Reminder System?

查看:55
本文介绍了我如何创建提醒系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望有一个长文本框,用户可以在其中键入提醒,在长文本框的末尾,在短文本框中,用户输入时间为10:34:15 AM,然后他们点击一个名为的按钮添加提醒并在他们添加后,在短文本框中,提醒在消息框中消失



[来自解决方案的EDIT OP代码]

 使用系统; 
使用 System.Collections.Generic;
使用 System.ComponentModel;
使用 System.Data;
使用 System.Drawing;
使用 System.Linq;
使用 System.Text;
使用 System.Threading.Tasks;
使用 System.Windows.Forms;

命名空间 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( 提醒:\ n + + textBox1.Text + + \\\
Was添加到警报:\ n
+ dateTimePicker1.Text, 提醒已添加,MessageBoxButtons.OK,MessageBoxIcon.Information);
dateTimePicker1.Text = MessageBox.Show(textBox1.Text +);
}
}
}

解决方案

 dateTimePicker1 .Text = MessageBox.Show(textBox1.Text +); 



会导致两个错误



1. textBox1.Text

后面有一个虚假的 + 符号2. MessageBox .Show不返回字符串。即使您向其添加 .ToString(),您也会从dateTimePicker收到错误,指出您尝试插入的文本不是有效的日期时间格式

将行更改为

 MessageBox.Show(textBox1.Text); 

或者最好只删除它 - 它只是重复上一条消息中的一些内容





需要考虑的事项......

加载表单时不要启动计时器,在用户更改时间后启动计时器...并确保它已启用,例如

  private   void  button1_Click( object  sender,EventArgs e)
{
myTimer.Enabled = true ;
myTimer.Start();
}



如果提醒的时间已经过去,你实际上只想要显示消息框,

所以你需要比较当前日期和与datetimepicker中设置的时间相比,例如

  if (DateTime.Now >  =  .dateTimePicker2.Value)
{
MessageBox.Show( .textBox1.Text);
// 下一位会停止再次出现的消息框
myTimer.Enabled = false ;
}



最后,确保你的DateTimePicker设置为正确的格式

 dateTimePicker2。 Format = DateTimePickerFormat.Time; 





如果你仍在努力,那么请阅读这篇CodeProject文章使用计时器创建简单的警报应用程序 [ ^ ]


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]

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 +);
        }
    }
}

解决方案

The line

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.

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.

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

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[^]


这篇关于我如何创建提醒系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆