Incluír WebKit en el proyecto

WEBKIT:

1. Descargar el componente http://webkitdotnet.sourceforge.net/downloads.php

2. Copia todos los ficheros de WebKit.NET-0.4-bin-cairo\bin excepto el .exe dentro del "..\bin\debug\" del proyecto

3. Agregar la referencia a “WebkitBrowser.dll”

4. Agregar la anterior dll en el cuadro de Herramientas ... "Elegir Elementos/ Componentes de .Net Framework / Examinar..."

5. Arrastra el componente al diseño del furmulario

Private Sub form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
WebKitBrowser1.Navigate("http://www.google.es")
End Sub



ClientScriptManager PARA AGREGAR CONTENIDO Y SCRIPTS A LA PÁGINA


'crear contenido web desde servidor
Dim texto as string = "
" & vbNewLine & _

               "Hola Mundo
" & vbNewLine & _     

               "
"Dim cs As ClientScriptManager = Page.ClientScript


If Not cs.IsStartupScriptRegistered(Me.[GetType](), "HolaMundo") Then
                cs.RegisterStartupScript(Me.[GetType](), "HolaMundo", texto)
End If


'crear y ejecutar script
Dim texto as string= "alert('Hello World');";
Dim cs As ClientScriptManager = Page.ClientScript


cs.RegisterStartupScript( Me.[GetType](),"HolaMundo2",texto,true);

LEER Y RECORRER LOS FICHEROS DE UN DIRECTORIO


Dim Files As String(), File As String


Files = IO.Directory.GetFiles(System.AppDomain.CurrentDomain.BaseDirectory & "/DATA", "*.xml")
     
For Each File In Files
     cmbConnect.Items.Add(IO.Path.GetFileNameWithoutExtension(File))
     My.Application.DoEvents()
Next

CONTROLAR EL CURSOR Y EVENTOS DEL RATÓN


'RATÓN ->
    DllImport ( "User32.dll" )> _
    Public Shared Function SetCursorPos ( ByVal X Como Entero , ByVal Y Como Entero ) Como Largo
    Fin Función
    DllImport ( "User32.dll" )> _
    Public Shared Function GetCursorPos ( ByRef lpPoint Como Point ) Como Largo
    Fin Función
    DllImport ( "User32.dll" )> _
    Public Shared Sub mouse_event( ByVal dwFlags As Integer , ByVal dx As Integer , ByVal dy As Integer , ByVal cButtons As Integer , ByVal dwExtraInfo As IntPtr )
    End Sub

    Dim URLini Como Cadena

    Public Const MOUSEEVENTF_LEFTDOWN = & H2 'botón izquierdo
    Public Const MOUSEEVENTF_LEFTUP = & H4 'botón izquierdo hasta
    Public Const MOUSEEVENTF_MIDDLEDOWN = & H20 'botón del medio hacia abajo
    Public Const MOUSEEVENTF_MIDDLEUP = & H40 'botón central hasta
    Public Const MOUSEEVENTF_RIGHTDOWN = & H8 'botón de la derecha abajo
    Public Const MOUSEEVENTF_RIGHTUP = & H10 'botón hasta

    '<- font="" rat="">

Private Sub ...
'Cursor 1 Posicionamos el
SetCursorPos (Me.Width - 210, 165)
'2 Pulsamos boton Derecho del Ratón
mouse_event (MOUSEEVENTF_LEFTDOWN, Me.Width - 215, 165, 0, 0)
mouse_event (MOUSEEVENTF_LEFTUP, Me.Width - 215, 165, 0, 0)
End Sub

DESACTIVAR TECLAS Y RATÓN AL USUARIO

 Private Declare Function BlockInput Lib "user32" (ByVal fBlock As Long) As Long


 Private Sub  .....
        BlockInput(True) 'bloqueamos las interacciones del usuario 
         '<--- llamadas a las rutinas que deseamos ejecutar con las interacciones del usuario bloqueadas--->
        BlockInput(False)' desbloqueamos las interacciones del usuario
  End Sub 

WEBBROWSER (EJEMPLOS DE USO)

Dim txtUser_Element As HtmlElemen
Dim txtPass_Element As HtmlElement
Dim btEntrar_Element As HtmlElement

'Capturar elemento por el ID
txtUser_Element = WebBrowserEx1.Document.GetElementById("txtUsuario")
txtPass_Element = WebBrowserEx1.Document.GetElementById("txtPassword")
btEntrar_Element = WebBrowserEx1.Document.GetElementById("btnEntrar")
'Por posición del tipo elemento-> .Document.GetElementsByTagName("INPUT").Item(8)

'Informar txt a traves del atributo value
txtUser_Element.SetAttribute("value", tdbConfig.SegurosVF.userShop)
txtPass_Element.SetAttribute("value", tdbConfig.SegurosVF.passShop)

'llamada al evento click
btEntrar_Element.RaiseEvent("onclick")

'-------------------------------------

'Capturar contenido txt a través del atributo value

Dim txtCod_Element As HtmlElement
txtCodSAP_Element = WebBrowserEx1.Document.GetElementById("txtCod")
msgbox(txtCod_Element.GetAttribute("value"))

'--------------------------------------

'Pulsar botón mediante InvokeMember
Dim btBuscar_Element As HtmlElement

btBuscar_Element = WebBrowserEx1.Document.GetElementById("btnBuscar")
btBuscar_Element.InvokeMember("click")

'--------------------------------------

'Capturar contenido del desplegable combo del indice seleccionado
Dim cmbFact_Element As HtmlElement, i as integer
cmbFact_Element = WebBrowserEx1.Document.GetElementById("cmbFact")
i = cmbFact_Element.GetAttribute("selectedindex")
msgbox(cmbFact_Element.Children(i).InnerText)

'Seleccionar indice del desplegable combo
Dim cmbProducto_Element As HtmlElement
cmbProducto_Element = WebBrowserEx1.Document.GetElementById("cmbProducto")
cmbProducto_Element.SetAttribute("selectedindex", 3)
cmbProducto_Element.RaiseEvent("onchange")

'---------------------------------------
'ZOOM

Private Enum Exec
     OLECMDID_OPTICAL_ZOOM = 63
End Enum
Private Enum ExecOpt
     OLECMDEXECOPT_DODEFAULT = 0
     OLECMDEXECOPT_PROMPTUSER = 1
     OLECMDEXECOPT_DONTPROMPTUSER = 2
     OLECMDEXECOPT_SHOWHELP = 3
End Enum


Dim Res As Object = Nothing
Dim MyWeb As Object
MyWeb = Me.WebBrowserEx1.ActiveXInstance
MyWeb.ExecWB(Exec.OLECMDID_OPTICAL_ZOOM, _
 ExecOpt.OLECMDEXECOPT_DONTPROMPTUSER, 50, IntPtr.Zero)

'Cambiar tamaño de la fuente
-----------------------------------
WebBrowserEx1.Document.Body.Style = "font-size:11px;"

OBTENER IP DE LA CONEXIÓN DEL CLIENTE


Dim ClientIP, Forwaded, RealIP


RealIP = ""


ClientIP = Request.ServerVariables("REMOTE_ADDR")
If ClientIP <> "" Then
            RealIP = ClientIP
Else
    'El usuario está accediendo a través de un Proxy.
    Forwaded = Request.ServerVariables("HTTP_X-Forwarded-For")
    If Forwaded <> "" Then RealIP = Forwaded
End If

LABEL FONDO TRANSPARENTE SOBRE OBJETO CON IMAGEN


label1.Parent = Picturebox1
label1.BackColor = Color.Transparent
label1.Location = New Point(0, 0)'Punto del objeto (en este caso picturebox1)donde se sitúa la etiqueta 

NOMBRE CORTO DE RUTA (C#)


 //Short Path Name -->
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern uint GetShortPathName(
[MarshalAs(UnmanagedType.LPTStr)]
string lpszLongPath,
[MarshalAs(UnmanagedType.LPTStr)]
StringBuilder lpszShortPath,
uint cchBuffer);


[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
       static extern uint GetShortPathName(string lpszLongPath, char[] lpszShortPath, int cchBuffer);
// <-- Short Path Name



 public string ToShortPathName(string longName)
{
    uint bufferSize = 256;
    StringBuilder shortNameBuffer = new StringBuilder((int)bufferSize);
    uint result = GetShortPathName(longName, shortNameBuffer, bufferSize);
    return shortNameBuffer.ToString();
}


public string ShortPath(string longpath)
{
    char[] buffer = new char[256];
    GetShortPathName(longpath, buffer, buffer.Length);
    return new string(buffer);
}

UNIR PDFs usando iTextSharp

'unir documentos usando iTextDoNEt --> http://sourceforge.net/projects/itextdotnet/
'función llamada

  public void combinarPDFs(string basePath, string filePDF1, string filePDF2, string newFilePDF)
{
    PdfMerge newPDF = new PdfMerge();


    newPDF.AddDocument(Path.Combine(basePath, filePDF1));
    newPDF.AddDocument(Path.Combine(basePath, filePDF2));
    newPDF.Merge(basePath + newFilePDF);
}
'Clase
using System;
using System.Collections.Generic;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
public class PdfMerge
{
    private BaseFont baseFont;
    private bool enablePagination = false;
    private readonly List documents;
    private int totalPages;
    public BaseFont BaseFont
    {
        get { return baseFont; }
        set { baseFont = value; }
    }
    public bool EnablePagination
    {
        get { return enablePagination; }
        set
        {
            enablePagination = value;
            if (value && baseFont == null)
                baseFont = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        }
    }
    public List Documents
    {
        get { return documents; }
    }
    public void AddDocument(string filename)
    {
        documents.Add(new PdfReader(filename));
    }
    public void AddDocument(Stream pdfStream)
    {
        documents.Add(new PdfReader(pdfStream));
    }
    public void AddDocument(byte[] pdfContents)
    {
        documents.Add(new PdfReader(pdfContents));
    }
    public void AddDocument(PdfReader pdfDocument)
    {
        documents.Add(pdfDocument);
    }
    public void Merge(string outputFilename)
    {
        Merge(new FileStream(outputFilename, FileMode.Create));
    }
    public void Merge(Stream outputStream)
    {
        if (outputStream == null || !outputStream.CanWrite)
            throw new Exception("OutputStream es nulo o no se puede escribir en éste.");

        Document newDocument = null;
        try
        {
            newDocument = new Document();
            PdfWriter pdfWriter = PdfWriter.GetInstance(newDocument, outputStream);
            newDocument.Open();
            PdfContentByte pdfContentByte = pdfWriter.DirectContent;
            if (EnablePagination)
                documents.ForEach(delegate(PdfReader doc)
                                  {
                                      totalPages += doc.NumberOfPages;
                                  });
            int currentPage = 1;
            foreach (PdfReader pdfReader in documents)
            {
                for (int page = 1; page <= pdfReader.NumberOfPages; page++)
                {
                    newDocument.NewPage();
                    PdfImportedPage importedPage = pdfWriter.GetImportedPage(pdfReader, page);
                    pdfContentByte.AddTemplate(importedPage, 0, 0);
                    if (EnablePagination)
                    {
                        pdfContentByte.BeginText();
                        pdfContentByte.SetFontAndSize(baseFont, 9);
                        pdfContentByte.ShowTextAligned(PdfContentByte.ALIGN_CENTER,string.Format("{0} de {1}", currentPage++, totalPages), 520, 5, 0);
                        pdfContentByte.EndText();
                    }
                }
            }
        }
        finally
        {
            outputStream.Flush();
            if (newDocument != null)
                newDocument.Close();
            outputStream.Close();
        }
    }
    public PdfMerge()
    {
        documents = new List();
    }
}