HtmlView.cs :  » Game » SokoSolve-Sokoban » SokoSolve » UI » Controls » Web » 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 » Game » SokoSolve Sokoban 
SokoSolve Sokoban » SokoSolve » UI » Controls » Web » HtmlView.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.IO;
using System.Text;
using System.Windows.Forms;
using SokoSolve.UI.Controls.Secondary;
using SokoSolve.UI.Controls.Web;

namespace SokoSolve.UI.Controls.Web{
    /// <summary>
    /// A wrapper of the .NET browser control.
    /// It has features for embedding in a winform application.
    /// </summary>
    public partial class HtmlView : UserControl
    {
        public HtmlView()
        {
            InitializeComponent();

            ShowStatus = false;
            ShowCommands = false;
        }

        public void SetHTML(string html)
        {
            webBrowser.DocumentText = html;
        }

        public void Navigate(string Url)
        {
            webBrowser.Navigate(Url);
        }

        /// <summary>
        /// Allow URI's with the schema/prefix "app://" to be trapped and handled
        /// </summary>
        public event EventHandler<UIBrowserEvent> OnCommand; 

        public bool ShowCommands
        {
            get
            {
                return toolStripCommands.Visible;
            }
            set
            {
                toolStripCommands.Visible = value;
            }
        }

        public bool ShowStatus
        {
            get
            {
                return statusStrip.Visible;
            }
            set
            {
                statusStrip.Visible = value;
            }
        }

        public bool ShowCommandBack
        {
            get { return tsbBack.Visible;  }
            set { tsbBack.Visible = value;  }
        }

        public bool ShowCommandForward
        {
            get { return tsbForward.Visible; }
            set { tsbForward.Visible = value; }
        }

        public bool ShowCommandHome
        {
            get { return tsbHome.Visible; }
            set { tsbHome.Visible = value; }
        }


        public bool ShowCommandDone
        {
            get { return tsbDone.Visible; }
            set { tsbDone.Visible = value; }
        }

        public bool ShowCommandPrint
        {
            get { return tsbPrint.Visible; }
            set { tsbPrint.Visible = value; }
        }

        public bool ShowCommandSave
        {
            get { return tsbSave.Visible; }
            set { tsbSave.Visible = value; }
        }


        private void tsbBack_Click(object sender, EventArgs e)
        {
            if (OnCommand != null)
            {
                UIBrowserEvent args = new UIBrowserEvent(this, new Uri("app://Controller/Back"));
                OnCommand(sender, args);
                if (!args.Completed)
                {
                    webBrowser.GoBack();
                }
            }
            else
            {
                webBrowser.GoBack();
            }
        }

        private void tsbForward_Click(object sender, EventArgs e)
        {
            if (OnCommand != null)
            {
                UIBrowserEvent args = new UIBrowserEvent(this, new Uri("app://Controller/Forward"));
                OnCommand(sender, args);
                if (!args.Completed)
                {
                    webBrowser.GoForward();
                }
            }
            else
            {
                webBrowser.GoForward();
            }
        }

        private void tsbHome_Click(object sender, EventArgs e)
        {
            if (OnCommand != null)
            {
                UIBrowserEvent args = new UIBrowserEvent(this, new Uri("app://Controller/Home"));
                OnCommand(sender, args);
                if (!args.Completed)
                {
                    webBrowser.GoHome();
                }
            }
            else
            {
                webBrowser.GoHome();
            }
        }

        private void tsbPrint_Click(object sender, EventArgs e)
        {
            webBrowser.Print();
        }

        private void tsbDone_Click(object sender, EventArgs e)
        {
            if (OnCommand != null) OnCommand(sender, new UIBrowserEvent(this, new Uri("app://Controller/Done")));
        }

        private void webBrowser_Navigating(object sender, WebBrowserNavigatingEventArgs e)
        {
            try
            {
                if (e.Url.Scheme == "app")
                {
                    e.Cancel = true;
                    if (OnCommand != null)
                    {
                        OnCommand(this, new UIBrowserEvent(this, e.Url));
                    }
                }
            }
            catch(Exception ex)
            {
                e.Cancel = true;
                FormError error = new FormError();
                error.Exception = ex;
                error.ShowDialog();
            }
            
        }

        private void webBrowser_Navigated(object sender, WebBrowserNavigatedEventArgs e)
        {
            tsLabelStatus.Text = e.Url.ToString();
        }

        private void tsbSave_Click(object sender, EventArgs e)
        {
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                SaveToFile(saveFileDialog.FileName);
            }
        }

        /// <summary>
        /// Inner web browser component
        /// </summary>
        [Browsable(false)]
        public WebBrowser WebBrowser
        {
            get { return webBrowser; }
            set { webBrowser = value; }
        }

        public void SaveToFile(string location)
        {
            File.WriteAllText(location, webBrowser.DocumentText); 
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.