如何撤消此步骤 [英] How to undo this step

查看:75
本文介绍了如何撤消此步骤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上,当我选中此按钮时,它会在富文本框的顶部插入日期和时间,这是好的,但是现在我希望当我再次单击此按钮并取消选中它时,它应该删除日期和时间它在我检查时插入了



到目前为止发生的事情是当我检查按钮它在顶部插入日期和时间时当我取消选中它没有任何反应但是当我检查时再次它再次在顶部插入日期和时间

我也尝试使用已检查状态更改的事件,但它清除了整个富文本框。



这就是我为此所做的事情



我尝试过的事情:



Actually when I check this button it inserts Date and time at the top of rich text box which is fine till here but now I want that when I click again on this button and I uncheck it, it should remove the date and time it inserted when I checked it

what happens till now is when I check the button it inserts date and time at top and when I uncheck it nothing happens but when I check it again it again inserts date and time at top
I've also tried using the checked state changed event but it clears the whole rich text box.

here is what I've done for this

What I have tried:

private RichTextBox Getnew()
{
    RichTextBox box = null;
    TabPage z = tabControl1.SelectedTab;
    if (z != null | z == null)
    {
        box = z.Controls[0] as RichTextBox;
    }
    return box;
}

private void dateTimeToolStripMenuItem_Click(object sender, EventArgs e)
{
    if (dateTimeToolStripMenuItem.Checked == true)
    {
        Getnew().Text = Getnew().Text.Insert(0, DateTime.Now.ToLongDateString() + DateTime.Now.ToLongTimeString()+"\n");
    }
}

private void dateTimeToolStripMenuItem_CheckStateChanged(object sender, EventArgs e)
{
    // Sorry I've Removed this.
}

推荐答案

0 )正如理查德所指出的,你的部分问题是你需要一个其他条件才能删除日期时间。



1)问题的另一部分是你无法知道要删除的内容,因为您没有将日期时间(已插入)存储在变量中。如果您不知道要删除什么,怎么可能删除它?
0) As pointed out by Richard, part of your problem is that you need an else condition to remove the datetime.

1) The other part of your problem is that you have no way of knowing what to remove because you're not storing the datetime (that was inserted) in a variable. How can you possibly remove it if you don't know what to remove?


这篇关于如何撤消此步骤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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