By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,529 Members | 1,826 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,529 IT Pros & Developers. It's quick & easy.

problem relating AxWebBrowser control in Visual Studio 2003

P: 6
i am using AxWebBrowser in C# project. i add and on click event handler on the document on Document Completed event. code is given below

mshtml.HTMLDocument doc1=(mshtml.HTMLDocument)axWebBrowser1.Document;
mshtml.HTMLDocumentEvents2_Event eve=(mshtml.HTMLDocumentEvents2_Event)doc1;
eve.onclick+=new HTMLDocumentEvents2_onclickEventHandler(eve_onclic k);

its firing ok but the problem is this that if i click a text box, it doesnt get the focus and i cannot type in it.

i will be very thankfull if anyone can help me out here.
Feb 19 '07 #1
Share this Question
Share on Google+
10 Replies


kenobewan
Expert 2.5K+
P: 4,871
What does this onclick event do?
Feb 20 '07 #2

P: 6
it gets the element clicked, then search in the Treeview created from html returned and returns wether its the same one or not.



i removed this handler DocumentComplete event handler and all the things returned to normal. i mean to say that text boxes got their focus.i then put the same code in NavigateComplete2 event and it seized to work again.
Feb 20 '07 #3

kenobewan
Expert 2.5K+
P: 4,871
Please post the code for the event, I assume that you mean ceased.
Feb 21 '07 #4

P: 6
yes i meant cease. and the code u asked for. its given below

Expand|Select|Wrap|Line Numbers
  1. private void axWebBrowser1_DocumentComplete(object sender, System.EventArgs e)
  2.         {
  3.             progressBar1.Increment(progressBar1.Minimum+=15);
  4.             string url=axWebBrowser1.LocationURL;
  5.             prurl=url;
  6.  
  7.             this.comboBox1.Items.Add(axWebBrowser1.LocationURL);
  8.             ImageList ls=new ImageList();
  9.             ls.Images.Add(Image.FromFile("exxp.gif"));
  10.             ls.Images.Add(Image.FromFile("txt.gif"));
  11.             treeView.ImageList=ls;
  12.             if(newproject)
  13.             {
  14.                 newproject=false;
  15.                 TreeNode tnod=new TreeNode("Sequence ");
  16.                 tnod.Nodes.Add(new TreeNode(url,1,1));
  17.                 treeView.Nodes.Add(tnod);
  18.             }
  19.             else
  20.             {
  21.                 treeView.Nodes[0].Nodes.Add(new TreeNode(url,1,1));
  22.             }
  23.  
  24.             mshtml.HTMLDocument doc1=(mshtml.HTMLDocument)axWebBrowser1.Document;
  25.             mshtml.HTMLDocumentEvents2_Event eve=(mshtml.HTMLDocumentEvents2_Event)doc1;
  26.             eve.onclick+=new HTMLDocumentEvents2_onclickEventHandler(eve_onclick);
  27.  
  28.             status="Done";
  29.             sbstatus.Text="Done";
  30.             string code=this.LoadFile();
  31.             if(!code.Equals(""))
  32.             {
  33.                 IHTMLDocument2 doc = (IHTMLDocument2) this.axWebBrowser1.Document;
  34.                 if (doc != null)
  35.                 {
  36.                     IHTMLWindow2 parentWindow = doc.parentWindow;
  37.                     if (parentWindow != null)
  38.                         parentWindow.execScript(code, "javascript");
  39.                 }
  40.             }
  41.             Cursor.Current = Cursors.Default;
  42.             progressBar1.Increment(progressBar1.Minimum+=20);
  43.             string a=this.axWebBrowser1.LocationURL.ToString();        
  44.             this.sbstatus.Text="Loading..."+a;
  45.             this.comboBox1.SelectedItem=a;
  46.             show_html_code(a);
  47.             this.ProcessHTML(htmlCode);                    
  48.             count++;    
  49.  
  50.         }
Feb 21 '07 #5

kenobewan
Expert 2.5K+
P: 4,871
Please post the eve_onclick event code. Thanks.
Feb 22 '07 #6

P: 6
sorry i misunderstood. here is the code for onclick event

Expand|Select|Wrap|Line Numbers
  1. private bool eve_onclick(IHTMLEventObj pEvtObj)
  2.         {
  3.  
  4.             if(RecOn)
  5.             {
  6.  
  7.                 //DataRow dr=dtrob.NewRow();
  8.                 if(rdbdload.Checked)
  9.                 {
  10.                     //dr[0]=act;
  11.                 }
  12.                 else if(rdbfrmsmt.Checked)
  13.                 {
  14.                     //dr[0]=act;
  15.                 }
  16.                 else if(rbnav.Checked)
  17.                 {
  18.                     //dr[0]=act;
  19.                 }
  20.                 else if(rdbtxtext.Checked)
  21.                 {
  22.                     //dr[0]=act;
  23.                 }
  24.                 else
  25.                 {    
  26.                     MessageBox.Show("Please select an action from the given options","Info Message",MessageBoxButtons.RetryCancel,MessageBoxIcon.Information);
  27.                     return false;
  28.                 }
  29.  
  30.                 HtmlParser parser=new HtmlParser();
  31.                 mshtml.IHTMLElement ele=pEvtObj.srcElement;            
  32.                 string strrr=ele.outerHTML;
  33.                 HtmlDocument ddoc=HtmlDocument.Create(strrr,false);
  34.                 TreeNode tnod=tvwDOM.Nodes[0];
  35.                 HtmlNodeCollection hnod=ddoc.Nodes;
  36.                 //If HtmlDocument contains only one parent node for such nodes which can be converted to DOM otherwise all nodes are given 
  37.  
  38.                 builder.Clear();
  39.                 if(hnod.Count>1)
  40.                 {
  41.                     for(int n=0;n<hnod.Count;n++)
  42.                     {
  43.                         HtmlNode nn=hnod[n];
  44.                         builder.Add(nn.ToString());    
  45.                     }
  46.                 }
  47.                 else
  48.                 {                        
  49.                     Builder(ddoc.Nodes[0],true,"nor");
  50.                 }
  51.                 builder.TrimToSize();
  52.                 URList.Add(prurl);
  53.                 tnod=check(tnod,builder,true);/// this function searches a tree and return the node of the tree being searched
  54.                 if(tnod!=null)
  55.                 {    
  56.                     string str=tnod.FullPath;
  57.                     drrob[2]=str;
  58.                     URList.Add(str);
  59.                 }
  60.                 else
  61.                 {
  62.                             /// Node not found    
  63.                             URList.Add(null);
  64.                 }    
  65.                 //System.Xml.XmlTextWriter twriter=new XmlTextWriter(
  66.                 drrob[3]=axWebBrowser1.LocationURL;
  67.                 dtrob.Rows.Add(drrob);
  68.             }    
  69.  
  70.             return true;
  71.         }
Feb 24 '07 #7

kenobewan
Expert 2.5K+
P: 4,871
i removed this handler DocumentComplete event handler and all the things returned to normal. i mean to say that text boxes got their focus.i then put the same code in NavigateComplete2 event and it seized to work again.
I can't see the NavigateComplete2 event in your code, did you take it out to show the rest of the code?
Feb 24 '07 #8

P: 6
iam sending all the events i defined on the axsebbrowser

private void axWebBrowser1_NavigateComplete2(object sender, AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Even t e)
{
status=sbstatus.Text;
string a=this.axWebBrowser1.LocationURL.ToString();
//show_html_code(a);
progressBar1.Increment(progressBar1.Minimum+=15);

}

private void axWebBrowser1_BeforeNavigate2(object sender, AxSHDocVw.DWebBrowserEvents2_BeforeNavigate2Event e)
{
string urlsrt=e.uRL.ToString();
progressBar1.Increment(progressBar1.Minimum+=15);
}


rest u already have.
Feb 25 '07 #9

kenobewan
Expert 2.5K+
P: 4,871
I believe that NavigateComplete2 is not the right event to use here. If navigation to a site is successful, the NavigateComplete2 handler is called, if available. Here is an article that may help:
Component-Based Development with Visual C#
Feb 26 '07 #10

P: 6
actually i am using navigate event to increment the status bar.
All three of the events fire.
the link u sent me is very helpful. i am trying to sort out the problem but still not a solution yet.
Feb 26 '07 #11

Post your reply

Sign in to post your reply or Sign up for a free account.