) but how to change background of html element when the element has focus or lost focus?

Help me, please

Question : How to change background html element when focus and lost focus?

Hi Everybody,

In Window Form (C#) I am developing a HTML list control. The Html List control like a List control of Windows but Item of it is a html. I inherit from Webbrowser control to do this. The Html list is a webbrowser, a Item is a Html element ( like
...
. ..

Answer : How to change background html element when focus and lost focus?

I am using CSS to define the background & text color of the rows:

td.Selected
{
      background-color: Blue;
      color: White;
}

td.NotSelected
{
      background-color: White;
      color: Black;
}

Then, in your WebBrowser control, add a private variable:  private HtmlElement lastElement = null;
And in your constructor, add:  this.Document.Click += new HtmlElementEventHandler(Document_Click);
And finally, your click event handler:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
void Document_Click(object sender, HtmlElementEventArgs e)
{
     if (this.Document != null && this.Document.ActiveElement != null)
     {
          //if a row is already selected, change it back to unselected
          if (lastElement != null)
          {
             mshtml.IHTMLElement lastElementDom = (IHTMLElement)lastElement.DomElement;
             lastElementDom.className = "NotSelected";
          }
                    
          //Now change the selected row to be highlighted
          mshtml.IHTMLElement element = (IHTMLElement) rosterBrowser.Document.ActiveElement.DomElement;
          element.className = "Selected";
 
          //cache this element so we can unselect it later
          lastElement = rosterBrowser.Document.ActiveElement;
    }
          
}
Random Solutions  
 
programming4us programming4us