|
16 | 16 | using System.Windows.Forms; |
17 | 17 | using HtmlRenderer.Entities; |
18 | 18 | using HtmlRenderer.Parse; |
| 19 | +using HtmlRenderer.Utils; |
19 | 20 |
|
20 | 21 | namespace HtmlRenderer |
21 | 22 | { |
@@ -256,6 +257,26 @@ public string GetHtml() |
256 | 257 | return _htmlContainer != null ? _htmlContainer.GetHtml() : null; |
257 | 258 | } |
258 | 259 |
|
| 260 | + /// <summary> |
| 261 | + /// Adjust the scrollbar of the panel on html element by the given id.<br/> |
| 262 | + /// The top of the html element rectangle will be at the top of the panel, if there |
| 263 | + /// is not enough height to scroll to the top the scroll will be at maximum.<br/> |
| 264 | + /// </summary> |
| 265 | + /// <param name="elementId">the id of the element to scroll to</param> |
| 266 | + public void ScrollToElement(string elementId) |
| 267 | + { |
| 268 | + ArgChecker.AssertArgNotNullOrEmpty(elementId, "elementId"); |
| 269 | + |
| 270 | + if( _htmlContainer != null ) |
| 271 | + { |
| 272 | + var rect = _htmlContainer.GetElementRectangle(elementId); |
| 273 | + if (rect.HasValue) |
| 274 | + { |
| 275 | + UpdateScroll(Point.Round(rect.Value.Location)); |
| 276 | + _htmlContainer.HandleMouseMove(this, new MouseEventArgs(MouseButtons, 0, MousePosition.X, MousePosition.Y, 0)); |
| 277 | + } |
| 278 | + } |
| 279 | + } |
259 | 280 |
|
260 | 281 | #region Private methods |
261 | 282 |
|
@@ -481,7 +502,16 @@ private void OnRefresh(object sender, HtmlRefreshEventArgs e) |
481 | 502 | /// </summary> |
482 | 503 | private void OnScrollChange(object sender, HtmlScrollEventArgs e) |
483 | 504 | { |
484 | | - AutoScrollPosition = e.Location; |
| 505 | + UpdateScroll(e.Location); |
| 506 | + } |
| 507 | + |
| 508 | + /// <summary> |
| 509 | + /// Adjust the scrolling of the panel to the requested location. |
| 510 | + /// </summary> |
| 511 | + /// <param name="location">the location to adjust the scroll to</param> |
| 512 | + private void UpdateScroll(Point location) |
| 513 | + { |
| 514 | + AutoScrollPosition = location; |
485 | 515 | _htmlContainer.ScrollOffset = AutoScrollPosition; |
486 | 516 | } |
487 | 517 |
|
|
0 commit comments