(软输入面板)重叠控件

简介

pc_capture1.JPG pc_capture2.JPG pc_capture3.JPG pc_capture4.JPG

这篇文章给出了一个简单但很有效的解释,解决问题时,您的控件是不可见的,当你打开 inputpanel 你可以看到在所有的控件的截图是基于适应 inputpanel 和可用空间。

使用代码

添加到项目中的类。 这是一个 静态 类,所以它可以调用任何形式。 为了让这项工作,你需要添加一个 inputpanel 控制每个窗体。 如果您使用的是tabpages,那么你通过只在当前标签页。 例如:

OverLappingInputPanel.Inputpanel(tabControl1.TabPages
[tabControl1.SelectedIndex].Controls, inputPanel1.Enabled,
inputPanel1.VisibleDesktop.Height);

 

代码
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace MFA_Common
{
public static class OverLappingInputPanel
{
private static int oldrest = 0;
private static int oldheight = 0;
private static int oldtop = 0;
private static Control isFocused = null;

/// <summary>
/// Brings the control that has focus on top of the inputpanel
/// </summary>
/// <param name=""controls""></param>
/// <param name=""SIDCollaps""></param>
public static void Inputpanel(Control.ControlCollection controls,
Boolean SIDExpended,
int Visualdesktopheight)
{
try
{
if (controls != null)
{
if (SIDExpended == true)
{
//Loop through the controls to determinate which has focus
//this can be avoided if the gotfocus event is fired
//for each control that is beneath the inputpanel if expanded

foreach (Control ctrl in controls)
{
if (ctrl.Focused)
{
isFocused
= ctrl;
// if this is not the case calculate the needed space
int rest = Visualdesktopheight - (
ctrl.Top
+ ctrl.Height);
if (rest < 0)
{
//move each control up with the calculated space
foreach (Control ctrl2 in controls)
{
ctrl2.Top
= ctrl2.Top + rest;
}
oldrest
= rest;

}
if (ctrl.Height > Visualdesktopheight)
{
oldtop
= ctrl.Top;
oldheight
= ctrl.Height;
ctrl.Height
= Visualdesktopheight;
ctrl.Top
= 0;
}
}
}

//escape the current function if the selected control is
//not under the inputpanel
return;
}
else
{
//when the inputpanel is hidden, recalculate the top position
//for each control.
//the old value has to be reversed *-1 to inverse the changes
//if the control was bigger than the available screen, then
//give it back its original value
if (oldheight != 0)
{
isFocused.Top
= oldtop;
isFocused.Height
= oldheight;
oldheight
= 0;
}
foreach (Control ctrl2 in controls)
{
ctrl2.Top
= ctrl2.Top + (-1 * oldrest);
}
oldrest
= 0;
}
}
}

catch
{
//the ObjectDisposedException is trapped here. This occurs when the user
//doesn't closes the sip before moving to an other screen
//if an inputpanel is closed on an other form,
//then the object that is stored is dispose
//if this is the case, catch the exception and set the object to null;
oldrest = 0;
controls
= null;
}
}
}
}

 

posted @ 2010-12-01 16:43  Wolves  阅读(340)  评论(0编辑  收藏  举报