HTML.cs :  » GUI » wx-NET » wx » SampleHTML » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » GUI » wx NET 
wx NET » wx » SampleHTML » HTML.cs
//-----------------------------------------------------------------------------
// wx.NET/Samples - HTML.cs
//
// A NET version of the wxWidgets "HTML" sample.
//
// Written by Bryan Bulten (bryan@bulten.ca)
// Copyright (C) 2003 Bryan Bulten
// Licensed under the wxWidgets license, see LICENSE.txt for details.
//
// $Id: HTML.cs,v 1.7 2007/12/08 23:10:18 harald_meyer Exp $
//-----------------------------------------------------------------------------

using System;
using System.Drawing;
using wx;

/** This demonstrates the built in HTML browser.
 */
namespace wx.SampleHTML{
    public class MyFrame : Frame
    {
        enum Cmd { Open, OpenURL, About, Quit, Dialog, Back, Forward }


        HtmlWindow m_html;

        //---------------------------------------------------------------------

        public MyFrame(string title, Point pos, Size size)
            : base(title, pos, size)
        {
            // Set the window icon

            Icon = new wx.Icon("../Samples/HTML/mondrian.png");

            // Set up a menu

            Menu fileMenu = new Menu();
            fileMenu.Append((int)Cmd.Open, "Open...\tCtrl+O",
                            "Open a page");
            fileMenu.Append((int)Cmd.OpenURL, "Open URL...\tCtrl+U",
                            "Open a URL");
            fileMenu.AppendSeparator();
            fileMenu.Append((int)Cmd.Quit, "E&xit\tAlt-X", 
                            "Quit this program");

            Menu goMenu = new Menu();
            goMenu.Append((int)Cmd.Back, "&Back\tCtrl+B", 
                          "Browse back one page");
            goMenu.Append((int)Cmd.Forward, "&Forward\tCtrl+F", 
                          "Browse forward one page");

            Menu helpMenu = new Menu();
            helpMenu.Append((int)Cmd.About, "&About...\tF1", 
                            "Show about dialog");

            MenuBar menuBar = new MenuBar();
            menuBar.Append(fileMenu, "&File");
            menuBar.Append(goMenu,   "&Browse");
            menuBar.Append(helpMenu, "&Help");

            MenuBar = menuBar;

            // Set up a status bar

            CreateStatusBar(2);
            StatusText = "Welcome to wxWidgets!";

            // Create the HTML window

            m_html = new HtmlWindow(this);
            m_html.SetRelatedFrame(this, "HTML : %s");
            m_html.RelatedStatusBar = 1;
            m_html.LoadPage("../Samples/HTML/Data/test.htm");

            // Set up the event table

            EVT_MENU((int)Cmd.Open,    new EventListener(OnOpen));
            EVT_MENU((int)Cmd.OpenURL, new EventListener(OnOpenURL));
            EVT_MENU((int)Cmd.Quit,    new EventListener(OnQuit));
            EVT_MENU((int)Cmd.Back,    new EventListener(OnBack));
            EVT_MENU((int)Cmd.Forward, new EventListener(OnForward));
            EVT_MENU((int)Cmd.About,   new EventListener(OnAbout));
        }

        //---------------------------------------------------------------------

        public void OnOpen(object sender, Event e)
        {
            string page = new FileSelector("Open HTML document", "", "", "", 
                                           "HTML Files (*.htm)|*.htm|" + 
                                           "All Files (*.*)|*.*");
            if (page != "") {
                m_html.LoadPage(page);
            }
        }

        public void OnOpenURL(object sender, Event e)
        {
            TextEntryDialog dlg = 
                new TextEntryDialog(this, "Enter URL to open", "Open URL", 
                                    "http://wxnet.sourceforge.net/news.html", 
                                    Dialog.wxOK | Dialog.wxCANCEL);
            if (dlg.ShowModal() == Dialog.wxID_OK) {
                m_html.LoadPage(dlg.Value);
            }
        }

        public void OnQuit(object sender, Event e)
        {
            Close();
        }

        //---------------------------------------------------------------------

        public void OnAbout(object sender, Event e)
        {
            HtmlAboutDialog dlg = new HtmlAboutDialog(this);
            dlg.ShowModal();
        }

        //---------------------------------------------------------------------

        public void OnBack(object sender, Event e)
        {
            if (!m_html.HistoryBack()) {
                MessageDialog dlg = 
                    new MessageDialog(this, "Can't go back any further", 
                                      "HTML", Dialog.wxOK | Dialog.wxCENTRE);
                dlg.ShowModal();
            }
        }

        public void OnForward(object sender, Event e)
        {
            if (!m_html.HistoryForward()) {
                MessageDialog dlg = 
                    new MessageDialog(this, "There is no forward", 
                                      "HTML", Dialog.wxOK | Dialog.wxCENTRE);
                dlg.ShowModal();
            }
        }

        //---------------------------------------------------------------------
    }

    public class HtmlAboutDialog : Dialog
    {
        //---------------------------------------------------------------------

        public HtmlAboutDialog (Window parent)
            : base(parent, -1, "About HTML")
        {
            Sizer = new BoxSizer(Orientation.wxVERTICAL);

            // Create the about html window

            HtmlWindow html = new HtmlWindow(this, -1, wxDefaultPosition,
                                             new Size(380, 160), 
                                             HtmlWindow.wxHW_SCROLLBAR_NEVER);
            html.Borders = 0;
            html.LoadPage("../Samples/HTML/Data/about.htm");

            html.Size = new Size(html.InternalRepresentation.Width,
                                 html.InternalRepresentation.Height);

            Sizer.Add(html, 1, Direction.wxALL, 5);

            // Create the OK button

            Sizer.Add(new Button(this, -1, "OK"), 0, 
                      Alignment.wxALIGN_CENTER | Direction.wxALL, 5);
            Sizer.Fit(this);

            EVT_BUTTON(-1, new EventListener(OnOK));
        }

        //---------------------------------------------------------------------

        public void OnOK(object sender, Event e)
        {
            EndModal(wxID_OK);
        }

        //---------------------------------------------------------------------
    }

    public class MyApp : App
    {
        //---------------------------------------------------------------------

        public override bool OnInit()
        {
            MyFrame frame = new MyFrame("HTML Sample", new Point(50,50), 
                                        new Size(450,340));
            frame.Show(true);

            return true;
        }

        //---------------------------------------------------------------------

        [STAThread]
        static void Main()
        {
            MyApp app = new MyApp();
            app.Run();
        }

        //---------------------------------------------------------------------
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.