DM5.0 in C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel;
using mshtml;

namespace DM4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
Excel.Application app = new Excel.Application();
Excel.Workbook book = app.Workbooks.Open(“c:/dm/dm.xlsx”);
Excel.Worksheet sheet1 = book.Sheets[1];
Excel.Worksheet sheet2 = book.Sheets[2];
Excel.Worksheet sheet3 = book.Sheets[3];
int rows = 1;
int cpages = 1;
//MessageBox.Show(sheet1.Cells[1, 1].value);
while (true)
{
while (cpages <= Convert.ToInt32(sheet2.Cells[rows, 6].value)) { //link_new + "#ipg" + cpages.ToString webBrowser1.Navigate(sheet2.Cells[rows, 5].value + "#ipg"+cpages.ToString ()); do { Delay1(1); } while (webBrowser1.ReadyState != WebBrowserReadyState.Complete); while (true) { string whole_html = ""; System.Windows.Forms.HtmlElementCollection get_html = webBrowser1.Document.GetElementsByTagName("html"); foreach (HtmlElement get_html_ in get_html) { whole_html = get_html_.GetAttribute("innerHtml"); } if (whole_html.IndexOf("id=cp_image") != 0) { break; } if (whole_html.IndexOf("class=\"tsmy mato5\"") != 0) { break; } Delay1(1); } //create folder start string f1 = sheet2.Cells[rows, 1].value; string f2 = sheet2.Cells[rows, 2].value; string f3 = sheet2.Cells[rows, 3].value; string f4 = sheet2.Cells[rows, 4].value; string folder_total = "c:\\comics\\" + f1 + "\\" + f2 + "\\" + f3 + "\\" + f4 + "\\"; System.IO.Directory.CreateDirectory(folder_total); //create folder end System.Windows.Forms.HtmlElement get_img = webBrowser1.Document.GetElementById("cp_image"); webBrowser1.Navigate(get_img.GetAttribute("src")); do { Delay1(1); } while (webBrowser1.ReadyState != WebBrowserReadyState.Complete); //download starts try { IHTMLDocument2 doc = (IHTMLDocument2)webBrowser1.Document.DomDocument; IHTMLControlRange imgRange = (IHTMLControlRange)((HTMLBody)doc.body).createControlRange(); foreach (IHTMLImgElement img in doc.images) { imgRange.add((IHTMLControlElement)img); imgRange.execCommand("Copy", false, null); using (Bitmap bmp = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap)) { bmp.Save(@folder_total + cpages.ToString() + ".jpg"); } } } catch { } cpages++; } rows++; // Dim whole_html As String = "" //Dim get_name1 As System.Windows.Forms.HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("html") //For Each get_name1_ As HtmlElement In get_name1 // whole_html = get_name1_.GetAttribute("innerHtml") //Next } } public void Delay1(int DelayInSeconds) { TimeSpan ts; DateTime targetTime = DateTime.Now.AddSeconds(DelayInSeconds); do { ts=targetTime .Subtract (DateTime .Now ); Application .DoEvents (); System .Threading .Thread.Sleep (50); } while (ts.TotalSeconds >0);
}
}
}

Check File Size in VB.net

Dim infoReader2 As System.IO.FileInfo
Dim file_size2 As Integer = 0
infoReader2 = My.Computer.FileSystem.GetFileInfo(“c:\test.jpg”)
file_size2 = infoReader2.Length
‘MsgBox(file_size2)

Start Process (Start Programm)

Process.Start(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + “\Visual Studio 2013\Projects\DM3.0\DM3.0\publish\DM3.0.application”)

Multi-threading Code in VB.net

Imports System.Threading

mythread1 = New Thread(AddressOf Mysql)
mythread1.Start()
mythread1.IsBackground = True
mythread2 = New Thread(AddressOf Reset)
mythread2.Start()
mythread2.IsBackground = True

Public Sub Mysql()
While True
End While
End Sub
Public Sub Reset()
While True
Application.ExitThread()
Application.Exit()
End While
End Sub

Get Handle and Set to Front Window

Private Declare Auto Function FindWindowEx Lib “user32” (ByVal parentHandle As Integer, ByVal childAfter As Integer, ByVal lclassName As String, ByVal windowTitle As String) As Integer
Private Declare Function SetForegroundWindow Lib “user32” (ByVal hwnd As IntPtr) As Long

SetForegroundWindow(Me.Handle())

Change Default Webbrowser to IE 11

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
CreateBrowserKey()
WebBrowser1.ScriptErrorsSuppressed = True

End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs) Handles Me.FormClosing
RemoveBrowerKey()
End Sub
Private Const BrowserKeyPath As String = “\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION”
Private Sub CreateBrowserKey(Optional ByVal IgnoreIDocDirective As Boolean = False)
Dim basekey As String = Microsoft.Win32.Registry.CurrentUser.ToString
Dim value As Int32
Dim thisAppsName As String = My.Application.Info.AssemblyName & “.exe”
‘ Value reference: http://msdn.microsoft.com/en-us/library/ee330730%28v=VS.85%29.aspx
‘ IDOC Reference: http://msdn.microsoft.com/en-us/library/ms535242%28v=vs.85%29.aspx
Select Case (New Windows.Forms.WebBrowser).Version.Major
Case 8
If IgnoreIDocDirective Then
value = 8888
Else
value = 8000
End If
Case 9
If IgnoreIDocDirective Then
value = 9999
Else
value = 9000
End If
Case 10
If IgnoreIDocDirective Then
value = 10001
Else
value = 10000
End If
Case 11
If IgnoreIDocDirective Then
value = 11001
Else
value = 11000
End If
Case Else
Exit Sub
End Select
Microsoft.Win32.Registry.SetValue(Microsoft.Win32.Registry.CurrentUser.ToString & BrowserKeyPath, _
Process.GetCurrentProcess.ProcessName & “.exe”, _
value, _
Microsoft.Win32.RegistryValueKind.DWord)
End Sub
Private Sub RemoveBrowerKey()
Dim key As Microsoft.Win32.RegistryKey
key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(BrowserKeyPath.Substring(1), True)
key.DeleteValue(Process.GetCurrentProcess.ProcessName & “.exe”, False)
End Sub

Website Page Loading Delay

Do While WebBrowser1.ReadyState <> 4
Delay1(0.5)
Loop

Close All Excel Processes

Try
For Each prog As Process In Process.GetProcesses
If prog.ProcessName = “EXCEL” Then
prog.Kill()
End If
Next
Catch ex As Exception
End Try

DOWNLOAD A FILE in VB.net

Imports System.Net
Dim remoteUri As String = “http://bigfox.com.au/”
Dim fileName As String = “abc.txt”
Dim myStringWebResource As String = Nothing
‘ Create a new WebClient instance.
Dim myWebClient As New WebClient()
myStringWebResource = remoteUri + fileName
myWebClient.DownloadFile(myStringWebResource, “c:\163\” + fileName)

SendKeys (KEYBOARD EMU)

SendKeys.Send(“{TAB}”)

SendKeys.Send(“^{a}”)
SendKeys.Send(“^{v}”)

Create Folder VB.net

System.IO.Directory.CreateDirectory(“e:\Music\” + range3.Value + “\” + range2.Value.ToString + “\”)

AD New Window Prevent

Private Sub WebBrowser1_NewWindow(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles WebBrowser1.NewWindow
e.Cancel = True
End Sub