Krunal Soni
Krunal Soni

Reputation: 151

Identify web browser's vertical scroll is reached on last position in c#

I have load HTML content in WebBrowser control of Winforms. And I want to append another HTML content when vertical scroll is reached on last position. So I am stuck on it how can I achieve it.

Here is my sample code:

WebBrowser web = new WebBrowser();
web.Document.Write("Some html content");
web.Document.Window.AttachEventHandler("onscroll", OnScrollEventHandler); // Create scroll event for browser control

private void OnScrollEventHandler(object sender, EventArgs e)
{
    // Identify vertical scroll reached on last position and append another HTML
}

Thanks in advance.

Upvotes: 3

Views: 336

Answers (2)

Tiber Septim
Tiber Septim

Reputation: 335

You can try this approach: Make two-way communication between your Winforms app (C#) and browser-side javascript, then you'll be able to call C# code from javascript, like this: window.external.GetAdditionalContent() when the scrollbar reaches the bottom.

GetAdditionalContent = your COM-visible method.

How to: Implement Two-Way Communication Between DHTML Code and Client Application Code: https://msdn.microsoft.com/en-us/library/a0746166.aspx

Check if a user has scrolled to the bottom: Check if a user has scrolled to the bottom

Upvotes: 1

Anup Patil
Anup Patil

Reputation: 209

This will work

 class KeyHandle
 {
    private static Int32 WM_KEYDOWN = 0x100;
    private static Int32 WM_KEYUP = 0x101;

    [return: MarshalAs(UnmanagedType.Bool)]
    [DllImport("user32.dll", SetLastError = true)]
    static extern bool PostMessage(IntPtr hWnd, int Msg, 
   System.Windows.Forms.Keys wParam, int lParam);

 public static void SendKey(IntPtr hWnd, System.Windows.Forms.Keys key)
  {
      PostMessage(hWnd, WM_KEYDOWN, key, 0);
   }
 }

Call method:

     KeyHandle.SendKey(this.webBrowser.Handle, Keys.PageDown);

Upvotes: 2

Related Questions