• 0

[C#] WebBrowser control


Question

Hey guys, I've found tutorials on the WebBrowser control on changing font size and stuff (on the subject of making a basic wysiwyg). But I need slightly more then that and I can't find anything anywhere so far on how to make a table button to dynamically create tables and control the rows and columns. This would be very helpful. Any ideas?

Link to comment
https://www.neowin.net/forum/topic/641108-c-webbrowser-control/
Share on other sites

3 answers to this question

Recommended Posts

  • 0
  sathenzar said:
Hey guys, I've found tutorials on the WebBrowser control on changing font size and stuff (on the subject of making a basic wysiwyg). But I need slightly more then that and I can't find anything anywhere so far on how to make a table button to dynamically create tables and control the rows and columns. This would be very helpful. Any ideas?

Look at the documentation for the HtmlDocument class. They give an example of how to manipulate the doc programmatically.

http://msdn.microsoft.com/en-us/library/sy...mldocument.aspx

  • 0

ok, so I have everything working, however this control is by far the most annoying control to work with. I just want to dynamically add php code before the HTML part, so I simply do a string mTxt = "<?php ?>" + WebBrowser.DocumentText; and it all the sudden calls the documentcompleted event twice and on top of that get this, the first time it gets called, it inserts all the code needed, the second time it erases all the php code from the page. WHY??!?!! It's driving me crazy:

		void gl_wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
		{
			//if (exeI != 2)
		   // {
				initEnv();
				exeI++;
		   //}
		}

		public void initEnv()
		{
			//if (exeI == 0)
		   // {
				exeI = 1;
				this.doc = (mshtml.IHTMLDocument2)gl_wb.Document.DomDocument;
				divCol = gl_wb.Document.GetElementsByTagName("div");
				tdCol = gl_wb.Document.GetElementsByTagName("td");
				tblCol = gl_wb.Document.GetElementsByTagName("table");
				doc.designMode = "On";
				for (int i = 0; i &lt; tdCol.Count; i++)
				{
					tdCol[i].Style = "border: 1px dotted #2a2a2a;";
				}

				for (int i = 0; i &lt; tblCol.Count; i++)
				{
					tblCol[i].Style = "border: 1px dotted #2a2a2a;";
					tblCol[i].Click += new HtmlElementEventHandler(tblClick);
				}

				AddCons();
			//}
		}

My main file I call this code:

 using (StreamReader sr = new StreamReader(@".\tmp\" + page.PageGuid + ".html"))
				{
					wb.DocumentText = sr.ReadToEnd();
					sr.Close();
					sr.Dispose();
				}
				webL.initEnv();

One strange thing I noticed if I don't include the webL.initEnv() in the main file it doesn't work at all.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.