Category / Section
How to reset the scroll position programmatically in WinForms HTMLUIControl?
2 mins read
Reset the scroll position
The scroll position can be moved programmatically to show the selected item with the help of the ScrollToElement method of the HTMLUI control. The ScrollToElement method helps the user to scroll to a position such that the specified element is visible in the HTMLUI control.
The following HTML document contains a div element and the code snippet below shows how the HTMLUI control is scrolled to make the div element visible.
Essential Studio is available with full source code. It incorporates a unique debugging support system that allows switching between 'Debug' and 'Release' versions of our library with a single click from inside the Visual Studio.NET IDE.
C#
private System.Windows.Forms.Button button1; DIVElementImpl div; private void htmluiControl1_LoadFinished(object sender, System.EventArgs e) { Hashtable html = this.htmluiControl1.Document.GetElementsByUserIdHash(); this.div = html["div1"] as DIVElementImpl; } private void button1_Click(object sender, System.EventArgs e) { this.htmluiControl1.ScrollToElement(this.div); }
VB
Private button1 As System.Windows.Forms.Button Private div As DIVElementImpl Private Sub htmluiControl1_LoadFinished(ByVal sender As Object, ByVal e As System.EventArgs) Dim html As Hashtable = Me.htmluiControl1.Document.GetElementsByUserIdHash() Me.div = CType(IIf(TypeOf html("div1") Is DIVElementImpl, html("div1"), Nothing), DIVElementImpl) End Sub Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Me.htmluiControl1.ScrollToElement(Me.div) End Sub