C# winForm程序 如何定义快捷健?

如按Ctrl+shift+S时调用指定方法…
2024-11-23 20:44:09
推荐回答(1个)
回答1:

if ((Keys.Shift & e.Modifiers) > 0 && (Keys.Control & e.Modifiers) > 0) //Control+Shift Key pressed
{
switch (e.KeyCode)
{
case Keys.H: //for topic shortkey verification and content replacement

//get selected text
//if no current text selection, create one by the position of current cursor
if (txtOutgoingBody.SelectedText == "")
{

//get current cursor postion
Int32 cursorpos = txtOutgoingBody.SelectionStart;
Int32 select_start;
Int32 select_end;
char[] chars = new char[] { ' ', '\n', '\r', '\t' };

if (cursorpos >= 0 && cursorpos <= txtOutgoingBody.TextLength)
{
if (cursorpos == 0)
select_start = 0;
else
{
//get select_start
select_start = txtOutgoingBody.Text.LastIndexOfAny(chars, cursorpos - 1);
if (select_start == -1)
select_start = 0;
else
select_start = select_start + 1;
}

//select_end
select_end = txtOutgoingBody.Text.IndexOfAny(chars, cursorpos);
if (select_end == -1)
select_end = txtOutgoingBody.TextLength - 1;
else
select_end = select_end - 1;

//select
txtOutgoingBody.Select(select_start, select_end - select_start + 1);

}

}

你看代码吧,然后记得给分!