Greetings. I'm very much a newbie at C#. I've taken a couple of online classes, but I still have very much to learn. I'm developing a small word processor application (just to see if i can do it, and for my own use when it's finished) and I need to know how to insert the DateTime object into a rich text box wherever the cursor happens to be at the time, just like it works in Wordpad. This kind of code is beyond my current understanding. I have most of the functionality of what a typical user would expect from a word processor working reasonably well, but I would love to have this function as part of my program. Thanks for whatever help you can provide and for your time.
Bob C.
Loading
Aleksandar IlioskiPosted Mar 10, 2010, 8:42 PM
followint line of code hapens when you press button1.. you can modity it for your own uses..
private void button1_Click(object sender, EventArgs e)
{
}
Aleksandar IlioskiPosted Mar 11, 2010, 5:42 PM
about cursor class and computing the X & Y axis positions, like I said, c# is great language.. and you can make great things with simple steps..
Bob CongdonPosted Mar 10, 2010, 9:31 PM
DateTime myTime = new DateTime();
myTime = DateTime.Now;
string wDateTime = " ";
wDateTime = myTime.ToString("g");
And then using what you gave me, I finished it with:
int CaretPosition = rtbMain.SelectionStart;
string TextBefore = rtbMain.Text.Substring(0, CaretPosition);
string textAfter = rtbMain.Text.Substring(CaretPosition);
rtbMain.Text = TextBefore + wDateTime + textAfter;
I never realized it would be that simple. I had nightmarish visions of having to go into the cursor class and computing the X & Y axis positions. I'm sure glad I didn't have to do that. Once again, thank you. I appreciate your help!
Bob C.