I have a tabcontrol with several tabpages. I also have hooked into the InputPanel.EnabledChanged event so that the tabcontrol resizes when the inputpanel is enabled. What I would like to do is ensure that the control with the focus is visible when the tabpage is resized. What's the best way to accomplish this. Note that I am using the .NET Compact Framework.
我有一个tabcontrol与几个tabpages。我也已经连接到InputPanel.EnabledChanged事件,以便tabcontrol在启用inputpanel时调整大小。我想要做的是确保在调整标签页大小时可以看到具有焦点的控件。什么是实现这一目标的最佳方式。请注意,我使用的是.NET Compact Framework。
Thanks, MrB
2 个解决方案
#1
You have a couple of things you need to/may want to keep track of here:
• Current scroll position
• Position of the tapped element (I assume a textbox) when they tapped it
Note that the EnabledChanged event for the InputPanel is pretty easy to deal with (I assume you've already done it): check the InputPanel's Enabled state and do a += or -= to the tabcontrol's Height so the InputPanel doesn't cover anything up.
My understanding is that your issue is really to determine where the textbox was, because your worst-case scenario is that it will be moved off-screen when the tabcontrol resizes.
I believe (not 100% certain) that resizing a tabcontrol will keep the top of the tabcontrol contents visible and you'll have to scroll down to see anything that is now "covered" by the InputPanel.
What you'll want to do in the EnabledChanged event is find out the location of the control that was tapped (or the screen coordinate that was tapped - whatever is easiest for you). If it falls within the danger zone of (ClientSize.Height-InputPanel.Bounds.Height,ClientSize.Height), you'll need to adjust your scroll.
This is half-C#-half-pseudocode but you should be able to see where I'm going with it:
int yOffset = top y-coordinate of the tapped control;
if ( yOffset > ClientSize.Height-inputPanel.Bounds.Height )
{
int yShift = amount to shift everything up;
Point scrollPosition = AutoScrollPosition;
scrollPosition.Y = scrollPosition.Y - yShift;
AutoScrollPosition = scrollPosition;
}
What this does, in a nutshell, is checks if your InputPanel is going to cover up the desired control, and if so, scroll up by yShift pixels, where yShift might be the whole height of the inputPanel, or just enough to barely show your control (whatever you want).
• .NET CF seems very forgiving about setting invalid scroll rules. If you can only scroll up 10 pixels and you tell it to scroll up 100, it will stop at 10.
• Screen coordinate (0,0) is the top left of the visible screen - NOT the form being displayed. You can get tripped up if you assume that (0,0) is the top of your form.
您需要/可能想要跟踪这里有几件事情:•当前滚动位置•点击它时,点击元素的位置(我假设一个文本框)请注意,InputPanel的EnabledChanged事件非常容易处理(我假设你已经完成了):检查InputPanel的Enabled状态并对tabcontrol的高度执行+ =或 - =因此InputPanel不会覆盖任何内容。我的理解是你的问题实际上是确定文本框的位置,因为最糟糕的情况是当tabcontrol调整大小时它将被移出屏幕。我相信(不是100%肯定)调整tabcontrol的大小将使tabcontrol内容的顶部可见,你将不得不向下滚动以查看InputPanel现在“覆盖”的任何内容。你想在EnabledChanged事件中做的是找出被点击的控件的位置(或者被点击的屏幕坐标 - 对你来说最简单的)。如果它属于(ClientSize.Height-InputPanel.Bounds.Height,ClientSize.Height)的危险区域,则需要调整滚动。这是半C#-half-pseudocode,但你应该能够看到我要去的地方:int yOffset =点击控件的顶部y坐标; if(yOffset> ClientSize.Height-inputPanel.Bounds.Height){int yShift =将所有内容都移动的数量; Point scrollPosition = AutoScrollPosition; scrollPosition.Y = scrollPosition.Y - yShift; AutoScrollPosition = scrollPosition;简而言之,这样做是检查你的InputPanel是否会覆盖所需的控件,如果是,则向上滚动yShift像素,其中yShift可能是inputPanel的整个高度,或者只是勉强显示你的控制(无论你想要什么)。 •.NET CF似乎对设置无效滚动规则非常宽容。如果你只能向上滚动10个像素并且它告诉它向上滚动100,它将在10处停止。•屏幕坐标(0,0)是可见屏幕的左上角 - 而不是正在显示的表格。如果您认为(0,0)是表单的顶部,则可能会被绊倒。
#2
The only way that comes to my mind is calculate this by currrent controls positions on a screen.
我想到的唯一方法是通过屏幕上的控制位置来计算。
#1
You have a couple of things you need to/may want to keep track of here:
• Current scroll position
• Position of the tapped element (I assume a textbox) when they tapped it
Note that the EnabledChanged event for the InputPanel is pretty easy to deal with (I assume you've already done it): check the InputPanel's Enabled state and do a += or -= to the tabcontrol's Height so the InputPanel doesn't cover anything up.
My understanding is that your issue is really to determine where the textbox was, because your worst-case scenario is that it will be moved off-screen when the tabcontrol resizes.
I believe (not 100% certain) that resizing a tabcontrol will keep the top of the tabcontrol contents visible and you'll have to scroll down to see anything that is now "covered" by the InputPanel.
What you'll want to do in the EnabledChanged event is find out the location of the control that was tapped (or the screen coordinate that was tapped - whatever is easiest for you). If it falls within the danger zone of (ClientSize.Height-InputPanel.Bounds.Height,ClientSize.Height), you'll need to adjust your scroll.
This is half-C#-half-pseudocode but you should be able to see where I'm going with it:
int yOffset = top y-coordinate of the tapped control;
if ( yOffset > ClientSize.Height-inputPanel.Bounds.Height )
{
int yShift = amount to shift everything up;
Point scrollPosition = AutoScrollPosition;
scrollPosition.Y = scrollPosition.Y - yShift;
AutoScrollPosition = scrollPosition;
}
What this does, in a nutshell, is checks if your InputPanel is going to cover up the desired control, and if so, scroll up by yShift pixels, where yShift might be the whole height of the inputPanel, or just enough to barely show your control (whatever you want).
• .NET CF seems very forgiving about setting invalid scroll rules. If you can only scroll up 10 pixels and you tell it to scroll up 100, it will stop at 10.
• Screen coordinate (0,0) is the top left of the visible screen - NOT the form being displayed. You can get tripped up if you assume that (0,0) is the top of your form.
您需要/可能想要跟踪这里有几件事情:•当前滚动位置•点击它时,点击元素的位置(我假设一个文本框)请注意,InputPanel的EnabledChanged事件非常容易处理(我假设你已经完成了):检查InputPanel的Enabled状态并对tabcontrol的高度执行+ =或 - =因此InputPanel不会覆盖任何内容。我的理解是你的问题实际上是确定文本框的位置,因为最糟糕的情况是当tabcontrol调整大小时它将被移出屏幕。我相信(不是100%肯定)调整tabcontrol的大小将使tabcontrol内容的顶部可见,你将不得不向下滚动以查看InputPanel现在“覆盖”的任何内容。你想在EnabledChanged事件中做的是找出被点击的控件的位置(或者被点击的屏幕坐标 - 对你来说最简单的)。如果它属于(ClientSize.Height-InputPanel.Bounds.Height,ClientSize.Height)的危险区域,则需要调整滚动。这是半C#-half-pseudocode,但你应该能够看到我要去的地方:int yOffset =点击控件的顶部y坐标; if(yOffset> ClientSize.Height-inputPanel.Bounds.Height){int yShift =将所有内容都移动的数量; Point scrollPosition = AutoScrollPosition; scrollPosition.Y = scrollPosition.Y - yShift; AutoScrollPosition = scrollPosition;简而言之,这样做是检查你的InputPanel是否会覆盖所需的控件,如果是,则向上滚动yShift像素,其中yShift可能是inputPanel的整个高度,或者只是勉强显示你的控制(无论你想要什么)。 •.NET CF似乎对设置无效滚动规则非常宽容。如果你只能向上滚动10个像素并且它告诉它向上滚动100,它将在10处停止。•屏幕坐标(0,0)是可见屏幕的左上角 - 而不是正在显示的表格。如果您认为(0,0)是表单的顶部,则可能会被绊倒。
#2
The only way that comes to my mind is calculate this by currrent controls positions on a screen.
我想到的唯一方法是通过屏幕上的控制位置来计算。