This article actually was written in last Christmas, now I just re-post in my new home.
Every programmer wants his application GUI to stand out, and so do I. A new idea came into my mind. I would like to add a Christmas hat on the top left corner of my WinForm application. This is not only simple but also not adding too much work load.
.Net application skin could be the first solution for most programmer. But it seems not worth it, because a huge skin library has to be installed just for this simple function. Furthermore, commercial skin library is not free at all.
I have to go back google again. Someone mention that it can override WndProc and in WM_NCPAINT, you have to draw your own title bar, and write function for each button. It seems a lot of work to do.Finally, I invent this peculiar way.
1. Create a transparent Form,
2. Put only a hat inside
3. Let it stay on the top left corner
If you are following the previous two articles, you will see a “Word” document in your frond. However, you may find some glitches in this document and there is a hidden box on top of the document. This is because ASP.Net generates “__VIEWSTATE” hidden view to track each page status.
We don’t want this field to be displayed as this should be a final “Word” document without any attached strings. To get rid of this, we have to override Render method.
MS Word treat this generated “Word” document differently
When clicking download generated document, IE will pop up “File Download” dialog as expected. However when opening the downloaded document, MS Word will be in “Web Layout View” instead of “Print Layout View”.
Let MS Word “thinks” this is true word document and open in “Print Layout View” with zoom “90%”
Replace original Visual Studio automatically generated .aspx header with the following code
OK! Now when MS Word opens this html style Word document, it more likely opens a real Word document.
Another issue comes up that MS Word is so smart, and it automatically breaks the page.
If you want to break the page on a certain position, you can insert the following code into your html style Word document.
Currently I am using ASP.net and working on a web project, which requires dynamically generate Microsoft Word submission document. The generated document must be specific format, and include page number, last print date, company logo, etc.
At first, I was thinking of using COM (Component Object Model). Because MS Word can comfortably work with .Net framework, .Net provide easy runtime callable wrapper. But it requires MS Word to be installed at server side, and it may slow down web server running. I have to give up.
And then I was looking for 3rd party .Net library generate MS Word. It’s not a cheap solution either.
After google, finally I found out that MS Word is compatible with HTML file format. As long as you rename .htm to .doc. MS Word can easily open. What I can do is to create a html template and then filled out the dynamic sections and response back to end user.
Here is the code snap shot:
protected void Page_Load(object sender, EventArgs e)
if (this.Request["projectID"] != null)
//fill dynamic section
//add word document header to response
Response.Charset = "utf-8";
Response.ContentType = "application/ms-word";
//flush out whole page to word document
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
I will keep posting the problem that I met and the solution in the next few posts.
Recently, I bought a SuperPad from eBay for my kid learning, which is running Google Android 2.1.
It’s pretty cool because I can develop my own educational application for my kid. As I haven’t been playing Java for a long time, I have to refresh my memory, and it will slow down the process a little bit.
Download Eclipse IDE, Android simulator, setup development environment… Finally I have my HelloWorld running!!!!!! It’s so excited to see these two words appearing in my new SuperPad screen.