Test Foro de elhacker.net SMF 2.1

Programación => Programación General => .NET (C#, VB.NET, ASP) => Mensaje iniciado por: snakeboy8 en 29 Enero 2015, 01:21 AM

Título: como agregar texto en el body de un webbrowser
Publicado por: snakeboy8 en 29 Enero 2015, 01:21 AM
hola estoy tratando de agregar texto en un webbrowser con esto
Código (vbnet) [Seleccionar]
WebBrowser1.Document.GetElementById("B").InnerText = "halo"

y este es el html

Código (html4strict) [Seleccionar]
<body id="B" style="padding: 0px; margin: 2px; color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 15px; background: rgb(255, 255, 255);>halo</body>

en el codigo html donde dice halo asi es como tendria que quedar pero no me funciona por que no agrega el texto alguien sabe como solucionar esto? :huh:
Título: Re: como agregar texto en el body de un webbrowser
Publicado por: Eleкtro en 29 Enero 2015, 02:20 AM
¿Te has dado cuenta que en el html que has mostrado NO has encerrado el style de CSS con comillas dobles?, no se si ha sido un error de edición por tu parte al publicar el código, o si ese es el mismo html original de la página, entonces esa podría ser la causa del problema, ya que con este error de sintaxis yo tampoco consigo reconocer correctamente el elemento:
Citar...255);>halo...

Ejemplo funcional:

Código (vbnet) [Seleccionar]
   Private Sub HtmlTest()

       Dim htmlText As String =
<a><![CDATA[
   <body id="B"
         style="padding: 0px;
                margin: 2px;
                color: rgb(0, 0, 0);
                font-family: Verdana, Arial, Helvetica, sans-serif;
                font-size: 15px;
                background: rgb(255, 255, 255);">

       This is a test inner text

   </body>
]]></a>.Value

       Dim htmlElement As HtmlElement

       Dim wb As New WebBrowser With
           {
               .Dock = DockStyle.Fill,
               .DocumentText = String.Empty
           }

       Me.Controls.Add(wb)

       wb.Document.Write(htmlText)
       htmlElement = wb.Document.GetElementById("B")

       Select Case htmlElement Is Nothing

           Case False
               htmlElement.InnerText = "halooooo???"
               Debug.WriteLine(htmlElement.OuterHtml)

           Case Else
               Throw New NullReferenceException("Element not found")

       End Select

   End Sub


Saludos
Título: Re: como agregar texto en el body de un webbrowser
Publicado por: snakeboy8 en 29 Enero 2015, 06:35 AM
me funciono muy bien el codigo amigo gracias   :)