Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Controls / December 2006

Tip: Looking for answers? Try searching our database.

using WebControl as preview window

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Manny Silva - 22 Nov 2006 21:28 GMT
Hi,

  Is there any way to simply generate Html and then display it in the
WebControl that is available in the Windows.Forms namespace in the .Net 2.0
framework?  It seems like it should be a fairly straight-forward operation...
but I can't figure it out for the life of me...  any pointers to concrete
examples would definitely be a great help.

Signature

Thanks in advance for your help,
Manny

Linda Liu [MSFT] - 23 Nov 2006 08:39 GMT
Hi Manny,

I am sorry that I may not understand your question exactly.

Based on my understanding, you want a simple way to generate an HTML page
and then display it in a WebControl control. If I am off base, please feel
free to let me know.

Do you mean you're developing a Windows Forms application? The WebControl
is a web control, which resides in System.Web.UI.WebControls namespace. The
equivalent WinForms control of the WebControl is WebBrowser.

As for a simple way to generate an HTML page, you could directly add an
HTML page to a WinForms application within Visual Studio 2005. To do it, go
to menu  Project | Add New Item. In the Add New Item window, select HTML
Page template and press Add button. Then you could edit the HTML page in
VS2005.

Alternatively, you could also make use of other professional editors to
generate HTML pages, such as Font Page, Dream Weaver and etc.

Hope this helps.
If you have anything unclear, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Linda Liu [MSFT] - 27 Nov 2006 04:03 GMT
Hi Manny,

How about the problem now?

If the problem is not resolved or you have anything unclear, please feel
free to let me know.

Thank you for using our MSND Managed Newsgroup Support Service!

Sincerely,
Linda Liu
Microsoft Online Community Support
Manny Silva - 27 Nov 2006 18:29 GMT
Well, I found a quick and dirty work around for what I was trying to
accomplish.  What I did was I generated the HTML dynamically and then wrote
it out to a file.  I then set the WebBrowser.Url to "file://file-path.html".  
Whenever I make a dynamic change, I re-save the file and then call
WebBrowser.Refresh().  This works ok, but I would far prefer to avoid writing
out to a file just to be able to preview what I am doing dynamically in
memory.  So, if there is a way to do this without having to save the HTML to
a file, I would definitely appreciate any pointers I can get.  If not, I now
have a workable solution.

Signature

Thanks,
Manny

Linda Liu [MSFT] - 29 Nov 2006 07:43 GMT
Hi Manny,

Thank you for your reply. I can understand what you want.

After doing some research, I find a workaround to display a dynamically
generated HTML in a WebBrowser control directly.

The workaround is to get the content from the stream and the then set it to
the DocumentText property of the WebBrowser control.

The following is a sample.

using System.IO;

MemoryStream mstream = new MemoryStream();
StreamWriter streamwriter = new StreamWriter(mstream);
HtmlTextWriter htmlwriter = new HtmlTextWriter(streamwriter);

// get the content from the mstream and then convert it to a string
byte[] byteArray = new byte[mstream.Length];
mstream.Seek(0, SeekOrigin.Begin);
mstream.Read(byteArray, 0, byteArray.Length);
string text = "";
for (int i = 0; i < byteArray.Length; i++)
 {
       text += ((char)byteArray[i]).ToString();
 }
// assign the converted text to the DocumentText property of the webBrowser
 webBrowser1.DocumentText = text;

mstream.Close();
streamwriter.Close();
htmlwriter.Close();

I have performed a test on the above code and confirmed it works.

BTW, as for the way to generate an HTML in memory, I think HtmlTextWriter
is a good option.

Please try my suggestion and let me know the result.

Sincerely,
Linda Liu
Microsoft Online Community Support
Linda Liu [MSFT] - 04 Dec 2006 13:58 GMT
Hi Manny,

How about the problem now?

If the problem is not resolved or you have anything unclear, please feel
free to let me know.

Thank you for using our MSDN Managed Newsgroup Support Service!

Sincerely,
Linda Liu
Microsoft Online Community Support
Manny Silva - 27 Nov 2006 14:45 GMT
Linda,

  Thank you for your reply.  Sorry for the delay.  I didn't have access to
the Internet over the Thanksgiving holiday (and weekend).  Sorry... you are
right.  WebBrowser is what I was referring to.  I would like to generate the
HTML in memory (that I am capable of doing, although any pointers that would
make that task easier are certainly appreciated).  Currently I am using the
System.Web.UI.HtmlTextWriter to generate HTML dynamically.  Now, my main
problem is trying to display the dynamically generated HTML in the WebBrowser
control.  Is that possible?  I wish to use it, basically, like a read-only
rich text edit control simply for the purpose of previewing the dynamically
generated HTML before it is saved to disk.

Does that help clarify what I am asking/trying to do?

Sorry I didn't make myself more clear to begin with... it was a last minute
post at the end of a very frustrating day  :o)

Thanks,
Manny
Signature

Thanks in advance for your help,
Manny

> Hi Manny,
>
[quoted text clipped - 43 lines]
>  
> This posting is provided "AS IS" with no warranties, and confers no rights.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.