您的位置:首页 > 其它

.Net compact framework 界面自适应输入法

2010-06-18 09:54 274 查看
.NET Compact Framework提供了一个很不错的组件,名字叫InputPanel。好,现在大家在已经打开的VS平台中新建一个Windows Mobile的项目,并且从“工具箱”中找到那个"InputPanel"组件,把其拖放到窗体编辑中。

接下来我们在窗体中添加一个Panel控件“pnlTextchat”,并把其的Dock属性设置为Fill状态,然后添加一个文本框控件,假设ID是“txtRecord". 那么我们切换到文本框控件的事件列表中来,然后按着我们里面事件,添加这两个事件:GotFocus和LostFocus。

然后添加InputPanel控件的EnabledChanged事件

/// <summary>
/// 启用或禁用输入法软面板(SIP)时
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void inputPanel_EnabledChanged(object sender, EventArgs e)
{
if(pnlTextchat != null)
{
if (inputPanel.Enabled)
{
pnlTextchat.Height -= inputPanel.Bounds.Height;
}
else
{
pnlTextchat.Height += inputPanel.Bounds.Height;
}
}
}
/// <summary>
/// 启用或禁用输入法软面板(SIP)时
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void inputPanel_EnabledChanged(object sender, EventArgs e)
{
if(pnlTextchat != null)
{
if (inputPanel.Enabled)
{
pnlTextchat.Height -= inputPanel.Bounds.Height;
}
else
{
pnlTextchat.Height += inputPanel.Bounds.Height;
}
}
}


代码写到这里基本差不多了,但是还有重要的一点:

用完inputPanel后,一定要释放资源,好像inputPanel不会自动释放,

/// <summary>
/// 界面关闭时调用inputPanel的Dispose()释放其资源,否则会出现ObjectDisposedException.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void TextChatForm_Closing(object sender, CancelEventArgs e)
{
inputPanel.Dispose();
}
/// <summary>
/// 界面关闭时调用inputPanel的Dispose()释放其资源,否则会出现ObjectDisposedException.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void TextChatForm_Closing(object sender, CancelEventArgs e)
{
inputPanel.Dispose();
}


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/yanzhibo/archive/2010/03/22/5403921.aspx
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: