本文介绍了如何在文本框中插入当前日期/时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我想在文本框中添加当前时间/日期。 使用下面的代码,我们可以在文本框的末尾添加时间/日期。I want to add the current time/date in textbox.Using the code below we can add the time/date at the end of the textbox.txtWritingBox.AppendText(time.ToString("G")); 但是我想在文本框的任何地方插入time.date 你能解决这个问题吗?But I want to insert time.date anywhere in the textboxCan you solve this推荐答案一个文本属性TextBox允许您访问整个文本,获取和设置机器人 - 所以您需要做的就是决定放置它的位置,并插入日期字符串。 例如:The Text property of a TextBox gives you access to the whole text, bot for get and set - so all you need to do is decide where you want to put it, and "insert" the date string.For example:myTextBox.Text = time.ToString("G") + myTextBox.Text;将它插入前面。 或:Will insert it at the front.Or:myTextBox.Text = myTextBox.Text.Replace("%%", time.ToString("G"));将替换:Would replace:It is %% at the momentWithIt is 20/02/2014 13:02:10 at the moment您可以使用文本框的SelectionStart属性。 例如:You can use the SelectionStart property of the textbox.For example:txtWritingBox.Text = txtWritingBox.Text.Insert(txtWritingBox.SelectionStart, time.ToString("G"));string inginsertText = "Blah Blah Blah Text";int selectionIndex = textBox1.SelectionStart;textBox1.Text = textBox1.Text.Insert(selectionIndex, insertText);textBox1.SelectionStart = selectionIndex + insertText.Length; -KR-KR 这篇关于如何在文本框中插入当前日期/时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!