Click here to Skip to main content
15,891,184 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to create collection class in C# Pin
DaveyM6924-Jun-10 0:08
professionalDaveyM6924-Jun-10 0:08 
AnswerMessage Closed Pin
24-Jun-10 0:20
stancrm24-Jun-10 0:20 
GeneralRe: How to create collection class in C# Pin
DaveyM6925-Jun-10 2:06
professionalDaveyM6925-Jun-10 2:06 
Questionhow to:C# Datagridview must show only fixed number of rows Pin
Cobusvdvyver23-Jun-10 23:43
Cobusvdvyver23-Jun-10 23:43 
AnswerRe: how to:C# Datagridview must show only fixed number of rows PinPopular
Cobusvdvyver24-Jun-10 0:44
Cobusvdvyver24-Jun-10 0:44 
GeneralRe: how to:C# Datagridview must show only fixed number of rows Pin
Mycroft Holmes24-Jun-10 1:14
professionalMycroft Holmes24-Jun-10 1:14 
QuestionDetect scroll to end of document in a webbrowser control Pin
Chris Quinn23-Jun-10 22:39
Chris Quinn23-Jun-10 22:39 
AnswerRe: Detect scroll to end of document in a webbrowser control Pin
Pete O'Hanlon24-Jun-10 1:04
mvePete O'Hanlon24-Jun-10 1:04 
This is relatively painless to do, but requires a little bit of work. What you need to do is place your text inside a div control which will serve as the scroll container - note, make sure that your web browser doesn't have nav bars enabled - this can be a bit confusing. Now, set your div to look like this
<div id="containerDiv" wrap="soft" style="border-style:window-inset; overflow-x:visible; overflow-y:scroll; height="100%"><!-- add your contents here --></div>
You need to reference the MsHtml com library and hook that up so that you can get access to the div element. Now, I added a simple UserControl which inherits from the webbrowser, and uses a timer to check the whether or not the scroll height indicates that the end of the page has been reached. Here's the user control:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using mshtml;

namespace LicenseScreen
{
  public partial class LicenseControl : WebBrowser
  {
    private bool _endReached;
    private HTMLDivElement _div;
    private Timer _timer;
    public EventHandler LicenseScrolledToEnd;

    public LicenseControl()
    {
      InitializeComponent();
      ScrollBarsEnabled = false;
      this.Navigate("about:blank");
    }

    public void LoadContent(string content, string containerDiv)
    {
      Document.Write(content);
      _div = this.Document.All[containerDiv].DomElement as HTMLDivElement;
      EndReached = _div.scrollHeight <= this.Height;

      _timer = new Timer();
      _timer.Interval = 200;
      _timer.Tick += new EventHandler(_timer_Tick);
      _timer.Start();
    }

    void _timer_Tick(object sender, EventArgs e)
    {
      if (_endReached)
        _timer.Stop();
      TestLocation();
    }

    private void TestLocation()
    {
      EndReached = _div.scrollHeight == (_div.scrollTop + _div.clientHeight) || 
        _div.scrollHeight <= this.Height;
    }

    public bool EndReached
    {
      set 
      {
        _endReached = value;
        if (value)
        {
          EventHandler handler = LicenseScrolledToEnd;
          if (handler != null)
            handler(this, EventArgs.Empty);
        }
      }
    }

  }
}
And here's an example of the code that calls into it:
public partial class LicenseForm : Form
{
  public LicenseForm()
  {
    InitializeComponent();
  }

  private string BuildPage()
  {
    StringBuilder sb = new StringBuilder();
    sb.Append("<html><head><title>My License</title></head>");
    sb.Append("<body>");
    sb.Append("<div id='containerDiv' wrap='soft' ");
    sb.Append(" style=\"border-style:window-inset; overflow-x:visible; overflow-y:scroll; height='100%'\">");
    for (int i = 0; i < 300; i++)
    {
      sb.AppendFormat("<p>This line represents line {0} in my license</p>", i);
    }
    sb.Append("</div></body></html>");
    return sb.ToString();
  }
  private void LicenseForm_Load(object sender, EventArgs e)
  {
    licenseControl.LicenseScrolledToEnd += new EventHandler(licenseControl_PropertyChanged);
    licenseControl.LoadContent(BuildPage(), "containerDiv");
  }

  void licenseControl_PropertyChanged(object sender, EventArgs e)
  {
    btnAccept.Enabled = btnCancel.Enabled = true;
  }
}

"WPF has many lovers. It's a veritable porn star!" - Josh Smith

As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.


My blog | My articles | MoXAML PowerToys | Onyx



GeneralRe: Detect scroll to end of document in a webbrowser control Pin
Chris Quinn28-Jun-10 1:14
Chris Quinn28-Jun-10 1:14 
GeneralRe: Detect scroll to end of document in a webbrowser control Pin
Chris Quinn28-Jun-10 4:30
Chris Quinn28-Jun-10 4:30 
GeneralRe: Detect scroll to end of document in a webbrowser control Pin
Chris Quinn28-Jun-10 23:23
Chris Quinn28-Jun-10 23:23 
Questiondo anyone have codes for sql 2005 for saving picture? Pin
ronakT23-Jun-10 21:59
ronakT23-Jun-10 21:59 
AnswerRe: do anyone have codes for sql 2005 for saving picture? Pin
Pete O'Hanlon23-Jun-10 22:12
mvePete O'Hanlon23-Jun-10 22:12 
GeneralRe: do anyone have codes for sql 2005 for saving picture? Pin
Luc Pattyn24-Jun-10 3:35
sitebuilderLuc Pattyn24-Jun-10 3:35 
GeneralRe: do anyone have codes for sql 2005 for saving picture? Pin
Pete O'Hanlon24-Jun-10 3:49
mvePete O'Hanlon24-Jun-10 3:49 
GeneralRe: do anyone have codes for sql 2005 for saving picture? Pin
Luc Pattyn24-Jun-10 3:57
sitebuilderLuc Pattyn24-Jun-10 3:57 
AnswerRe: do anyone have codes for sql 2005 for saving picture? [modified] Pin
Luc Pattyn24-Jun-10 4:05
sitebuilderLuc Pattyn24-Jun-10 4:05 
GeneralRe: do anyone have codes for sql 2005 for saving picture? Pin
Pete O'Hanlon24-Jun-10 4:21
mvePete O'Hanlon24-Jun-10 4:21 
AnswerRe: do anyone have codes for sql 2005 for saving picture? Pin
yu-jian27-Jun-10 9:18
yu-jian27-Jun-10 9:18 
QuestionHow to make a part of the text as superscript in button text Pin
NarVish23-Jun-10 21:40
NarVish23-Jun-10 21:40 
AnswerRe: How to make a part of the text as superscript in button text Pin
Pete O'Hanlon23-Jun-10 22:07
mvePete O'Hanlon23-Jun-10 22:07 
Questionhow to allign the image at the left corner..... Pin
Nivas8223-Jun-10 20:42
Nivas8223-Jun-10 20:42 
GeneralRe: how to allign the image at the left corner..... Pin
Nivas8223-Jun-10 21:16
Nivas8223-Jun-10 21:16 
QuestionHow to display excel sheet inside a windows form Pin
vineesh v23-Jun-10 20:28
vineesh v23-Jun-10 20:28 
QuestionLatency Meter Pin
satsumatable23-Jun-10 19:20
satsumatable23-Jun-10 19:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.