Create Web-like Forms as Windows App

I have used VS 2005 to create a family-based web site ... about 100 pages/forms consisting of mostly text with some graphics thrown in for interest. I have no intention of putting this out on a publicly-accessible server but instead had anticipated burning everything onto CD's and then distributing that to family members so that they could view the site on their own machines (XP Pro SP2) using IE. In inquiring on this forum how to do that I am told that that is not feasible and that instead I should have created a windows app and simply deployed that app to the family (via CD). That's fine except for one thing ... I don't know how to create a web-like app as a windows app. For example, as I create the app I want to be able to easily highlight a particular word in the middle of a paragraph by setting its font/size/color ... I want to set indentations here and there ... I want to insert graphics in the middle of some text and specify that text can flow to the left (or right) of the image ... I want to insert links that, when clicked, cause certain pages (forms) to be loaded ... all of these are normal things easily done in the creation of web forms but I don't know what tools/features are available for me to create this sort of app as a windows app.

For example, suppose I have two paragraphs of text and I want the second one indented a certain amount ... I suppose I could have two text boxes (one for each paragraph) and position and size these the way I want them but if I later decide to add, say, a lot of stuff to the first paragraph then I have to resize its text box and reposition the other one. There MUST be a way to edit paragraphs of text (of various indentations) that are strung together and insert/position images on a windows form. I guess what I'm looking for is a feature that lets me create/format windows forms the way I can web forms in Design mode..

Can someone help me to understand how to do this ... or point me to a source that discusses it

Thanks very much.



Answer this question

Create Web-like Forms as Windows App

  • Corres

    Matt:

    Oh, I am learning so much ... I hope you will hang in with me as I develop this "windows app that looks like a web app". I am beginning to make some progress ... believe it or not! Based on your last note I have setup the main form with a panel that contains a textbox that has the date put in it at form load event time, a panel with the graphic in it and a long skinny panel down the left with a listbox in it that contains a bunch of LinkLabels. A click on one of these LinkLabels invokes the LinkLabelClicked event which will load the associated HTML page into a webbrowser control that occupies the lion's share of the form. Whew! Now, two questions:

    When I click on a linklabel to display an HTML page I want see I get an error (Host name could not be parsed). The URL I am using is http://~/mypage1.htm ... mypage1.htm is in the project folder. I thought that a URL that starts with ~ says "start at the folder that contains this project and load the specified file. If I use a fully-qualified URL (eg. http://www.microsoft.com") it works OK. Can you help me understand this

    Second question ... the list of linklabels in the skinny left panel is considerably longer than length of the listbox that they are contained in. How do I setup a vertical scroll bar to allow users to see links that are below the window form

    Thanks again for helping me.


  • Nisa

    Good question ... the site uses a master page that has a few dropdown lists in it and users can click a particular item in a list to go off to a particular page. To do this I use the Selected Index Changed event to determine which item was selected (clicked) and then I use the Response.Redirect method to load the appropriate page. This is the only code-behind the project uses. I don't see a way to make the drop down list items hyperlinks directly ... that is why I use the Selected Index Changed event handler.


  • psp77

    \ are used for URLs (web pages on a web server)
    / are used for file systems (e.g., a Windows file system on the local computer)

    since this is a web application, you should be using \. However, since this app will only be running on a local machine (not a web server) they should be /


  • jwin

    It is pretty simple to do that via JavaScript; in fact, the following site will do the code for you:

    http://javascript.internet.com/generators/drop-down-menu.html

    ASP.NET is great, but I think this is one of those occasions when there are better solutions.

    Matt

  • OldCDude

    Ye, got yer slashes back'ard me boy!

    Backslash is used by file systems: C:\my folder\my file.ext

    Forwardslash are used in URLs: www.mysite.com/default.asp

    The web browser knows how to parse and translate either pathing convention.



  • R.Tutus

    If you've done a lot of the work already to create the website, and you now just want to package it up for CD use, one thing you could consider doing is creating a Windows app which uses a webbrowser as the control. I haven't totally thought this through, plus you'd need to get past any issues to do with requiring ASPX server functionality, and of course the target machine would need the framework... but if you could do all that, it might solve some these formatting problems you're getting.

    Having said all that, it might be possible to use a web spider... I once used something called Black Widow which basically trawled the site, and saved every page to an HTML document.



  • bfarr23

    Do you actually need to use web forms (.aspx), i.e. is there code behind the forms

    If you are just showing text and pictures then you could just use html pages instead of web forms. Then you could just use your original plan.


  • AlexanderJ

    Hmmmm ... the value of Environment.CurrentDirectory includes the \bin\debug at the end. I have found that by setting a string variable to the value of Environment.CurrentDirectory but without the trailing "\bin\debug" and then appending "/mypage.htm" that it works ... which makes sense because mypage.htm is not in the directory that ends with "\bin\debug". So, it appears that I am off and running and will setup my 100 or so htm pages and see how things go. If questions arise I will be back. Thanks.

    While I have your attention I would like to ask a niggling question that I have had for some time ... what is the difference betwee the forward slash (/) and the backward slash (\) in directory/file addresses. For example, in the case here I have found that adding both "/mypage.htm" or "\mypage.htm" work. Are they interchangeable or are there circumstances where they behave differently

    This is a low priority question ... you have already been too generous with your time.


  • Rabbitrun

    Here's why you're page can't be displayed:

    The tilde character only works as a dynamic path indicator in ASP.Net. When the ASP engine is reading that path, it knows to begin searching in the website's physical root for folders named in the path. That happens on the server side. The client side does not have this functionality; it needs to know precicely what URL you want to visit.

    Now, that being said about how the tilde works, it has nothing to do with your problem. All of your content is now local to the pc running the application. It is not located on the web. When you start a URL with "http" you are telling the browser that this resource is to be accessed via the hypertext transport protocol, and your browser knows that this means initiating a tcp connection on port 80 to the specified resource. In this case the domain "~" can't be found. Since your files are located on the local machine you can just give the browser the path to the file. If the files are in a folder that's in the same folder as the application, you should be able to to call the Navigate() method with just Navigate("docfolder/filename.htm").

    On your second question - I'm confused by the LinkLabels/ListBox thing... I'm not sure how you're using these controls. If you add LinkLables to a ListBox.Items collection they render as their typename - so I don't think that's what you're doing. When I suggested using the ListBox, I was really thinking more of binding one to an ArrayList of DictionaryEntries that contain the File Name and Path of each HTML file. Then you just have a little line of code that navigates to the SelectedValue property of the ListBox when the SelectedIndex changes. Could you explain how you handled this, or provide a code snipit showing it

    As far as the scrolling goes - if you have more controls in a panel that you can see, you can set the AutoScroll property for the panel to True and it will then have scrollbars that let you get to the rest of the controls. Most controls that can be containers have an AutoScroll property.



  • learnerplates

    Hi,

    Environment.CurrentDirectory returns the directory that the programme is in, you do not need to set it to anything.

    Try putting a breakpoint on the webbroswer.url = new uri (Environment.CurrentDirectory & "mypage.htm") line, and see what Environment.CurrentDirectory is. It might not be quite the location you need and you might need to add a bit more file path to it. For example:

    webbroswer.url = new uri (Environment.CurrentDirectory & "\bin\debug\" & mypage.htm")

    Matt

  • ronlahav

    Oh boy, you guys are really helping me understand this stuff. rkimble's explanation of the tilde and the significance of "http" in a URL helped me get things straight. I'm sure all of this is documented many times over in the on-line help files and tutorials included with VS 2005 ... but finding those thiings is a trick. I have forums such as this absolutely essential to my (slowly) grasping these concepts. Thanks for your help ... and patience.

    Now, Matt suggested I use Environment.CurrentDirectory as I target the htm file I want to display in the WebBrowser ... but I don't know what he means by "use". I can set the value of Environment.CurrentDirectory to a string such as "C://Documents & Settings/<username>/My Doucments/MyVS2005Project/" and then use WebBrowser.url Environment.CurrentDirectory & "mypage.htm" ... as in:

    webbroswer.url = new uri (Environment.CurrentDirectory & "mypage.htm")

    but this results in "This program cannot display the webpage". Obviously I am not using Environment.CurrentDirectory properly.

    If I take rkimble's suggestion of just using WebBrowser.Navigate ("mypage.htm") I get the same thing as above. Interestingly if I use a somehitng like http://www.microsoft.com as the argument both procedures above work fine. I guess I need more help understanding how to access an htm file that is resident on my own machine.

    The linklabel/listbox thing is probably a nmsuse of the linklabel control on my part ... when a label is clicked I just display the associated htm page in the WebBrowser control ... or should I say I "try" to display the htm page.

    Thanks for hanging in there with me ... sooner or later I will begin to understand what's going on.


  • IlCapo

    Hi,

    In winforms you can set the listbox to "ScrollAlwaysVisible=true"; this can be done in the code or via the designer.

    In both winforms and webforms a vertical scroll bar should appear on a listbox when the number of items is greater than the height of the box.

    To link to a file in your project, you don't need to use http://. I don't think you can use ~;
    instead, use Environment.CurrentDirectory.

    Does that help

    Matt


  • airwalker2000

    Matt ... I really appreciate your helping me understand this stuff ... I am sort of newbie and am having fun trying to get my arms around this system. I have a couple of very basic questions ... which will demonstrate my "newbie-ness"! When I created my original family web site I used a master page that contains a 2 x 2 table ... with the date and a graphic in the top row and a list of links in the first cell of the second row and a contents placeholder in the second cell of the second row. I take it that support for this requires ASP.Net because I do not see a way to use the master page concept with html files. Is there some sneaky way to do this That is I would like all of my pages to show the date and the graphic in the top row and the list of links to other pages in the site on the left ... is there a way to make this happen

    Thanks for your patience with someone who obviously needs a lot of help!


  • murph___

    Think of the MasterPage as the form itself. Use panels on the form to create your table layout. Your navigation can be controled using something as simple as a listbox. When the user clicks an item you load the appropriate HTML page into a webbrowser control that is also on the form. Your header section can contain a textbox or label that you set the date in with a picture box next to it for the graphic.

    There are lots of approachs that would work since your base content is HTML. Once you recreate the MasterPage functionality in the form you should be good to go.



  • Create Web-like Forms as Windows App