Communicate between two Visual Basic Applications

How to communicate between 2 different visual basic applications.

Simple technique by using SendMessage()

	'Main app that tries to communicate with other
	Public Class Form1
		'Project App1

		Private Const APP2_MSG1 As Integer = 6541

		Declare Auto Function SendMessage Lib "user32.dll" _
		(ByVal hWnd As IntPtr, ByVal Msg As Integer, _
		 ByVal wParam As Integer, ByVal lParam As Integer) As Integer

		Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
		Handles Button1.Click
			Dim p() As Process = Process.GetProcessesByName("App2")
			If p.Count > 0 Then
				Dim hWnd As IntPtr = p(0).MainWindowHandle
				SendMessage(hWnd, APP2_MSG1, 0, 0)
				Debug.WriteLine("Msg sent")
			End If
		End Sub
	End Class

Read more to get code of Listening application

Continue reading

Get Screen information related to Form location

	If Screen.FromPoint(Me.Location).Primary Then
		'is primary
	End If

Get device name on which form is currently on :


Get Screen resolution of display, your form is currently on :

	Dim rect As Rectangle = Screen.FromPoint(Me.Location).Bounds

prevent opening popup in internet explorer

A common problem while using webBrowser control is open pop up windows in instance of Internet Explorer and not in your application.
There’s a simple way to prevent this.

Logic is to capture the event when New Window is opened | Grab Link | Open it programatically in our application | cancel opening IE.

and code would be :

Continue reading

Add BindingNavigator for DataGridView

To add a BindingNavigator for a DataGridView, even when there’s no DataSource like DataSet or DataTable in use, you can have DataGridView’s rows collection as DataSource for BindingSource.
And set that BindingSource to BindingSource property of BindingNavigator.

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles MyBase.Load

        BindingSource2.DataSource = DataGridView1.Rows
        BindingNavigator1.BindingSource = BindingSource2

        'instead of adding event handler for MoveFirst,MoveLast,MoveNext,MovePrevious
        'chose this one. it will fire anyway
        AddHandler BindingNavigatorPositionItem.TextChanged, AddressOf bindingnavigator_PostionChanged

    End Sub

Continue reading

Using Explorer Form in

Adding directory structure to explorer form to use it like Windows Explorer:

Right click your project in Solution Explorer and click Add > Add New Item | Select Explorer Form from the list and Click ok, [keep default name if you dont know changing it in further code]

When new Form is added to your project, double click it and replace whole code with the following. Result of which will be like this-

Continue reading

Set EXE parent to Form

Original Post by Martin Xie

     Public Shared Function SetParent(ByVal instr As IntPtr, ByVal outstr As IntPtr) As IntPtr

    End Function

    Private Sub startProcess()
        Dim p As Process
        p = Process.Start("notepad.exe")
        SetParent(p.MainWindowHandle, Me.Handle)
    End Sub