I have created Notepad application using C#.
In that cannot go to the specific line number using Go To facility which is already available in Microsoft''s Notepad.
If somebody know that how to focus the cursor on specified line then please let me know.. and if you want to see the code then give me your mail ID, I''ll mail to you..
waiting for reply.
Thanks
解决方案No, you did not create Notepad application. Such application already existed (and it''s extremely bad one, by the way). :-)
Also, there is no such thing as "focus" inside a control. This would mean "keyboard focus", and only one control in the whole system can get focus. Inside a control, this is selection. For text controls, this is selection and insertion point at the same time.
The answer depends on your UI library which you failed to specify, which is not nice of you, for who would like to provide redundant information?
For System.Windows.Controls.TextBox, you can use the property CaretIndex, please see:
http://msdn.microsoft.com/en-us/library/system.windows.controls.textbox.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.controls.textbox.caretindex.aspx[^].
For System.Windows.Forms.TextBox, this is two properties: SelectionStart and SelectionLength:
http://msdn.microsoft.com/en-us/library/system.windows.forms.textbox.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.textboxbase.selectionstart.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.textboxbase.selectionlength.aspx[^].
To find what character is on what line and visa versa, use the methods GetFirstCharIndexFromLine, GetFirstCharIndexOfCurrentLine and GetLineFromCharIndex.
—SA
Load for application in Notepad file
namespace MyNotepad
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void newToolStripMenuItem_Click(object sender, EventArgs e)
{
richTextBox1.Clear();
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog op = new OpenFileDialog();
if (op.ShowDialog() == DialogResult.OK)
{
richTextBox1.LoadFile(op.FileName, RichTextBoxStreamType .PlainText );
this.Text = op.FileName;
}
}
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog op = new SaveFileDialog ();
if (op.ShowDialog() == DialogResult.OK)
{
richTextBox1.SaveFile (op.FileName, RichTextBoxStreamType.PlainText);
this.Text = op.FileName;
}
}
private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog op = new SaveFileDialog();
if (op.ShowDialog() == DialogResult.OK)
{
richTextBox1.SaveFile(op.FileName, RichTextBoxStreamType.PlainText);
this.Text = op.FileName;
}
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
//richTextBox1
Application.Exit();
}
private void undoToolStripMenuItem_Click(object sender, EventArgs e)
{
richTextBox1.Undo();
}
private void cutToolStripMenuItem_Click(object sender, EventArgs e)
{
richTextBox1.Cut();
}
private void copyToolStripMenuItem_Click(object sender, EventArgs e)
{
richTextBox1.Copy();
}
private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
{
richTextBox1.Paste();
}
private void selectAllToolStripMenuItem_Click(object sender, EventArgs e)
{
richTextBox1.SelectAll();
}
private void dateTimeToolStripMenuItem_Click(object sender, EventArgs e)
{
richTextBox1.Text = System.DateTime.Now .ToString ();
}
private void colorToolStripMenuItem_Click(object sender, EventArgs e)
{
ColorDialog op = new ColorDialog ();
if (op.ShowDialog() == DialogResult.OK)
{
richTextBox1.ForeColor = op.Color;
}
}
private void fontToolStripMenuItem_Click(object sender, EventArgs e)
{
FontDialog op = new FontDialog();
if (op.ShowDialog() == DialogResult.OK)
{
richTextBox1.Font = op.Font ;
}
}
private void findToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void replaceToolStripMenuItem_Click(object sender, EventArgs e)
{
}
}
}