日期:2014-05-19  浏览次数:20835 次

toolbarbutton焦点问题
toolbarbutton如何获取焦点,好像没有.focus().

------解决方案--------------------
http://topic.csdn.net/t/20060627/15/4846201.html
示例:

private void Form_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if(ProcessToolbarButton(e,this.toolBar1) != null)
this.toolBar1_ButtonClick(this.toolBar1,ProcessToolbarButton(e,this.toolBar1));
}

private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
switch(e.Button.Text)
{
case "新增 ":
MessageBox.Show( "新增 ");
break;
case "保存 ":
MessageBox.Show( "保存 ");
break;
}
}

public static ToolBarButtonClickEventArgs ProcessToolbarButton(KeyEventArgs key,ToolBar toolbar)
{
ToolBarButtonClickEventArgs click;
foreach(ToolBarButton button in toolbar.Buttons)
{
if(TransTemp(key.KeyData.ToString()) == button.Text )
{
click = new ToolBarButtonClickEventArgs(button);
return click;
}
}
return null;
}

public static string TransTemp(string KeyText)
{
switch(KeyText)
{
case "F1 ":
return "新增 ";

case "F2 ":
return "保存 ";

default:
return " ";
}
}