These two days I want to make a small PPC Program To find that it is difficult to do a lot of things ....
Taking the content in the scrolling form as an example, it is easy to use winform. You have to implement it yourself here.
Finally, I found an example in Microsoft's example. However, if an input panel control exists on the form, if the Input Panel is displayed, it will cover part of the form, which is troublesome. I have never been able to find a good solution. After some hard work, I finally figured out this problem. Now I will write out the solution and let's see if there are any optimizations.
First, all controls to be displayed in the form should be placed in a panel, and then a vscrollbar should be placed on the form. Of course, if you also need a horizontal scroll bar, you should also put one, as shown in:
The panel width is set to 224, and the height is determined based on the content. The width and height of the scroll bar are 16 and 320.
Private Void Form1_load ( Object Sender, system. eventargs E)
{
This. Vscrollbar1.maximum=This. Panel1.height-This. Height;
}
That is to say, if the height of the Panel is 400, the maximum value that the scroll bar needs to represent is only the height of the Panel minus the height of the form.
Next, add the following Code :
Private Int Prevalue;
Private Void Vscrollbar1_valuechanged ( Object Sender, system. eventargs E)
{
// Only when the input panel is open,
// It is not the top control in the panel (I have used hard encoding here. In fact, you can also implement it through program traversal, but it does not seem necessary to pay for it)
// And only when the user is scrolling down the form.
If ( This . Inputpanel1.enabled && ( ! Sender. Equals ( This . Textbox1 )) && This . Vscrollbar1.value > = This . Prevalue)
// The top of the Panel is actually set to the value of the scroll bar, plus the copying of the height of the Input Panel, that is, moving the panel up is equivalent to rolling.
This . Panel1.top =- ( This . Vscrollbar1.value + This . Inputpanel1.bounds. Height );
Else
// Otherwise, you only need to move the value of the scroll bar up the panel.
This . Panel1.top =- This . Vscrollbar1.value;
// Record Current Value
This . Prevalue = This . Vscrollbar1.value;
}
Private Void Inputpanelappsenabledchanged ( Object Sender, system. eventargs E)
{
If ( This . Inputpanel1.enabled)
This . Vscrollbar1.height = This . Inputpanel1.visibledesktop. height;
Else
This . Vscrollbar1.height = This . Clientsize. height;
}
Private Void Showinputpanel ( Object Sender, system. eventargs E)
{
This. Inputpanel1.enabled=True;
Setscrollbar (sender );
}
Private Void Hideinputpanel ( Object Sender, system. eventargs E)
{
// If the last time on the input method panel is hidden, you don't need to change it this time. Return it directly.
If ( ! This . Inputpanel1.enabled)
Return ;
This . Inputpanel1.enabled = False ;
Setscrollbar (sender );
}
Private Void Setscrollbar ( Object Sender)
{
Control C = (Control) sender;
// Calculate the value set for the scroll bar based on the current control, and then trigger the valuechanged event of the scroll bar again to adjust the scroll bar.
This . Vscrollbar1.value = This . Vscrollbar1.maximum * C. Top / This . Panel1.height;
This . Vscrollbar1_valuechanged (sender, Null );
}
Finally, the control that needs to display the input method panel is processed as follows, so that it can display the input method panel and adjust the position of the control in the form when getting the focus:
This. Textbox1.gotfocus+ = NewSystem. eventhandler (This. Showinputpanel );
All controls whose input method panel needs to be hidden are processed as follows to hide the input method panel and adjust the control position when the control is focused:
This. Radiobutton1.gotfocus+ = NewSystem. eventhandler (This. Hideinputpanel );
OK. After the above processing, the position of the control in your form first scrolls with the position of the scroll bar.
Second, when the input method panel is displayed or hidden, the position is adjusted accordingly.