c#简单记事本应用程序的快捷方式_使用C#帮助记事本应用程序

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)

{

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值