How do i make an HTML Editor + a Live HTML/Page Editor.

Do you need something made? then ask in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
6 posts Page 1 of 1
Contributors
User avatar
GaiaonlineHD
Member
Member
Posts: 40
Joined: Mon Jan 23, 2012 8:51 pm

The last topic i did i fixed my self after thinking for like 1 Min :/ but i really need help with this. i did one before and it edited the DocumentTxt but did not save or edit correctly.

Help.
User avatar
smashapps
Coding Guru
Coding Guru
Posts: 961
Joined: Tue Apr 05, 2011 8:41 am

You don't need the webbrowser's document text.

You can use a RichTextBox or any other text control to edit the HTML file, you can use code to have the path and name set so you can save the file without any dialogs, then navigate your webbrowser to the file.

I've just written a small application for you, it saves a file named index.html to the desktop, no dialogs in the way, as soon as you make a change it displays it in the webbrowser.

screenshot:

Image

code:
Code: Select all
Public Class Form1

    'Our declarations, this is going to be the path and file name for our HTML file'
    Dim _path As String
    Dim _name As String

    Private Sub RichTextBox1_TextChanged(sender As System.Object, e As System.EventArgs) Handles RichTextBox1.TextChanged
'try catch in case of any errors'      
Try
'we save the file with the path and name we declared and save it as plain text, then navigate to the file with the webbrowser'
            RichTextBox1.SaveFile(_path & _name, RichTextBoxStreamType.PlainText)
            WebBrowser1.Navigate(_path & _name)
        Catch ex As Exception

        End Try
       
    End Sub

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'set the path and name on our load event'
        _path = My.Computer.FileSystem.SpecialDirectories.Desktop
        _name = "/index.html"
    End Sub


End Class

Need anymore help or have any questions ask me, +rep if I've helped :)
You do not have the required permissions to view the files attached to this post.
My name is Tom | Visit my blog where I post new content every day! Tom's Daily Blog | MineCraft is awesome!
User avatar
GaiaonlineHD
Member
Member
Posts: 40
Joined: Mon Jan 23, 2012 8:51 pm

smashapps wrote:
You don't need the webbrowser's document text.

You can use a RichTextBox or any other text control to edit the HTML file, you can use code to have the path and name set so you can save the file without any dialogs, then navigate your webbrowser to the file.

I've just written a small application for you, it saves a file named index.html to the desktop, no dialogs in the way, as soon as you make a change it displays it in the webbrowser.

screenshot:

Image

code:
Code: Select all
Public Class Form1

    'Our declarations, this is going to be the path and file name for our HTML file'
    Dim _path As String
    Dim _name As String

    Private Sub RichTextBox1_TextChanged(sender As System.Object, e As System.EventArgs) Handles RichTextBox1.TextChanged
'try catch in case of any errors'      
Try
'we save the file with the path and name we declared and save it as plain text, then navigate to the file with the webbrowser'
            RichTextBox1.SaveFile(_path & _name, RichTextBoxStreamType.PlainText)
            WebBrowser1.Navigate(_path & _name)
        Catch ex As Exception

        End Try
       
    End Sub

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'set the path and name on our load event'
        _path = My.Computer.FileSystem.SpecialDirectories.Desktop
        _name = "/index.html"
    End Sub


End Class

Need anymore help or have any questions ask me, +rep if I've helped :)
Thanks for your help but i didnt mean that i dont want to edit a BLANK html i want to have lets say Youtube and i want to be able to open the html of that site and edit it......

Ive looked up tutorials and they all came out like urs :/
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

If you want to alter the page without having to reload the whole document, you will need to make use of the existing HTML elements.
You can access these with GetElementById and GetElementsByTagName.
User avatar
GaiaonlineHD
Member
Member
Posts: 40
Joined: Mon Jan 23, 2012 8:51 pm

mandai wrote:
If you want to alter the page without having to reload the whole document, you will need to make use of the existing HTML elements.
You can access these with GetElementById and GetElementsByTagName.
If i knew how to do that i would have done it wouldnt i?
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

If you are looking to list the elements and alter their attributes/inner HTML then you can use this:
Code: Select all
    Private Sub WebBrowser1_DocumentCompleted(sender As System.Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted

        listElements.Items.Clear()
        For i As Integer = 0 To WebBrowser1.Document.All.Count - 1
            listElements.Items.Add(WebBrowser1.Document.All(i).TagName)
        Next

    End Sub

    Private Sub btnSetAttribute_Click(sender As System.Object, e As System.EventArgs) Handles btnSetAttribute.Click

        If Not WebBrowser1.Document Is Nothing Then

            WebBrowser1.Document.All(listElements.SelectedIndex).SetAttribute(txtAttribute.Text, txtValue.Text)
        End If
    End Sub

    Private Sub btnSetHTML_Click(sender As System.Object, e As System.EventArgs) Handles btnSetHTML.Click

        If Not WebBrowser1.Document Is Nothing Then

            WebBrowser1.Document.All(listElements.SelectedIndex).InnerHtml = txtValue.Text
            WebBrowser1_DocumentCompleted(Nothing, Nothing)
        End If

    End Sub
Where listElements is a ListBox.
6 posts Page 1 of 1
Return to “Tutorial Requests”