How to generate an Outlook ribbon? - vb.net

I'm trying to create an Outlook ribbon using a VB VSTO program.
I don't receive any error. I don't receive the ribbon.
My code:
Public Class ThisAddIn
Private Sub ThisAddIn_Startup(sender As Object, e As System.EventArgs)
'Handles Me.Startup
End Sub
Public Class ReadPublishing
Private Sub Ribbon1_Load(ByVal sender As System.Object, ByVal e As
RibbonUIEventArgs) Handles MyBase.Load
End Sub
Private Sub btnPDF_Click(sender As Object, e As RibbonControlEventArgs)
Handles btnPDF.Click
Dim desktopFolder, fileName As String
desktopFolder = Environment.GetFolderPath
(Environment.SpecialFolder.Desktop)
fileName = "You press the black one"
' --- insert action
End Sub
End Class
Private Sub ThisAddIn_Shutdown(sender As Object, e As System.EventArgs)
'Handles Me.Shutdown
End Sub
End Class

Related

Is there any way to call the form load on button click in vb.net when using this kind of logic

Public Class form1
Dim var1 as String = ""
Dim var2 as Boolean = True
Public Sub New(ByVal parameter1 as String, ByVal parameter2 As Boolean)
var1 = parameter1
var2 = parameter2
InitializeComponent()
End Sub
Private Sub form1_Load(sender as Object, e As EventArgs) Handles MyBase.Load
If var1 = "This String" Then
End If
End Sub
Private Sub btn_Save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Save.Click
call form1_load()
end sub
I was unable to call the form load with parameters, can somebody please help on this, thanks in advance
form1_Load is just a method that you can call like any other method. The Form_Load method requires a sender and an EventArgs parameter. You can just pass through the ones you get from Button_Click.
Private Sub btn_Save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Save.Click
form1_load(sender, e)
End Sub
But a better solution is to extract the logic into a new method and to call it in both, Form_Load and Button_Click.
Private Sub DoSomething()
If var1 = "This String" Then
End If
End Sub
Private Sub form1_load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles form1.Load
DoSomething()
End Sub
Private Sub btn_Save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Save.Click
DoSomething()
End Sub
Note that calling form1_load does not raise the Load event. It only executes the logic inside this method.

Visual Basic 2012: Passing variable from one form to another

I have two forms, the main (Main.vb) program window and a pop-up that appears when the program is started (getInitialBalance.vb). I need to get a value entered into the PopUp window from the popup window to the Main program. The relevant code is shown below:
getinitialbalance.vb
Public Class GetInitialBalance
Public initialBalance As Integer
Private Sub btnApplyInitialBal_Click(sender As Object, e As EventArgs) Handles btnApplyInitialBal.Click
Dim textinput As Integer = txtInitialBalance.Text
initialBalance = textinput
Me.Close()
End Sub
End Class
Main.vb
Public Class Main
Private Sub Main_Load(sender As Object, e As EventArgs) Handles MyBase.Load
GetInitialBalance.ShowDialog()
End Sub
Dim localInitialBalance As Integer = GetInitialBalance.initialBalance
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
MsgBox(localInitialBalance)
End Sub
End Class
New up the GetInitialBalance form and then when the user clicks OK on the popup dialog, grab the value initialBalance from the reference to GetInitialBalance, like this:
Private Sub Main_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim popup As New GetInitialBalance
If popup.ShowDialog = Windows.Forms.DialogResult.OK Then
localInitialBalance = popup.initialBalance
End If
End Sub
Your entire code should look like this:
Public Class GetInitialBalance
Public initialBalance As Integer
Private Sub btnApplyInitialBal_Click(sender As Object, e As EventArgs) Handles btnApplyInitialBal.Click
initialBalance = Convert.ToInt32(textinput)
Me.DialogResult = Windows.Forms.DialogResult.OK
End Sub
End Class
Public Class Main
Dim localInitialBalance As Integer
Private Sub Main_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim popup As New GetInitialBalance
If popup.ShowDialog = Windows.Forms.DialogResult.OK Then
localInitialBalance = popup.initialBalance
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
MsgBox(localInitialBalance)
End Sub
End Class

Reacting to third-party application form events using vb.net

I would like to know how I should code my VB.net application to react to the form load event in a third-party application (also written in VB.net)
To test, I have created two basic programs, one with two forms (program A) and one (program B) that attempts to the listen to program A's appropriate form load event. I have tried using WithEvents but it does not get fired when Program's A second form loads.
Here is the code for Program A:
Public Class StartPage
Public WithEvents loadtimer As New System.Windows.Forms.Timer
Private Sub StartPage_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
loadtimer.Interval = 1000
loadtimer.Enabled = True
loadtimer.Start()
End Sub
Private Sub loadtimer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles loadtimer.Tick
loadtimer.Stop()
SystemStatus.Show()
End Sub
End Class
Public Class SystemStatus
Inherits StartPage
Private Sub StartPage_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.Label1.Text = "This is the form that I want to listen for the load event"
Me.loadtimer.Enabled = False
End Sub
End Class
Here is the code for Program B:
Imports Program_A
Public Class ListeningForm
Dim WithEvents testlisten As New Program_A.SystemStatus
Private Sub testlisten_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles testlisten.Load
Label1.Text = "SystemStatus form loaded"
End Sub
Private Sub ListeningForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Label1.Text = "Waiting for SystemStatus load event..."
End Sub
End Class
I am quite new when it comes to programming so maybe this is not even possible or I just haven't been understanding what I've been reading. In any case please enlighten me as to what my next course of action should be.
Thanks very much in advance,
theoleric
This will do what your asking.
Imports Program_A
Public Class ListeningForm
Dim WithEvents testlisten As New SystemStatus
Private Sub testlisten_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles testlisten.Load
' now this event will fire
Label1.Text = "SystemStatus form loaded"
End Sub
Private Sub ListeningForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Label1.Text = "Waiting for SystemStatus load event..."
' the load event will not fire until you call this
testlisten.Show()
End Sub
End Class

Event handling in VB.NET

In VB.NET, why isn't the following custom event not firing?
Public Class classes1
Public Event buttonload(ByVal sender As System.Object, ByVal e As System.EventArgs)
Protected Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
attd.Show()
RaiseEvent buttonload(sender, e)
End Sub
End Class
Public Class attd
Dim WithEvents c1 As New classes1
Sub c1_buttonload(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles c1.buttonload
MsgBox("Event received")
End Sub
End Class
You are using your first form, classes1, to show your second form, attd, and then raise your CustomEvent. Then in your second form, attd, you are creating another instance of the first form, classes1, and then trying to attach your handler to that instance's event. They are not the same, so it will not fire.
It is really not clear exactly what you are trying to do. If you are just experimenting around with events you can try something like this.
Form1
Public Class Form1
Dim attd As Form2 = New Form2
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
attd.Show()
End Sub
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
AddHandler attd.buttonload, AddressOf buttonLoadHandler
End Sub
Private Sub buttonLoadHandler(sender As Object, e As EventArgs)
MsgBox("Event received")
End Sub
End Class
Form2
Public Class Form2
Public Event buttonload(ByVal sender As System.Object, ByVal e As System.EventArgs)
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
RaiseEvent buttonload(sender, e)
End Sub
End Class
If you are just wanting to have your second Form respond to the First Forms Button Click try something like this.
Form1
Public Class Form1
Dim attd As Form2 = New Form2
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
attd.Show()
attd.showMessageBox()
End Sub
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
End Sub
End Class
Form2
Public Class Form2
Public Sub showMessageBox()
MsgBox("Hello World")
End Sub
End Class

update form on asynchronous control event

A few weeks ago I wrote a wrapper for the ServiceController control to enhance and streamline the base ServiceController. One of the changes I made was to add a monitoring component using the System.Threading.Timer object. On any change of status, an event is raised to the parent class. The actual monitoring works fine, but when the event is handled in the main form, my program abruptly ends - no exceptions, no warning, it just quits. Here's a skeleton version of the control:
Public Class EnhancedServiceController
Inherits ServiceController
Public Event Stopped(ByVal sender As Object, ByVal e As System.EventArgs)
Public Event Started(ByVal sender As Object, ByVal e As System.EventArgs)
Private _LastStatus As System.ServiceProcess.ServiceControllerStatus
Private serviceCheckTimer as System.Threading.Timer
Private serviceCheckTimerDelegate as System.Threading.TimerCallback
...
Private Sub StartMonitor()
MyBase.Refresh()
_LastStatus = MyBase.Status
serviceCheckTimerDelegate = New System.Threading.TimerCallback(AddressOf CheckStatus)
serviceCheckTimer = New System.Threading.Timer(serviceCheckTimerDelegate, Nothing, 0, 60*1000)
End Sub
Private Sub CheckStatus()
MyBase.Refresh()
Dim s As Integer = MyBase.Status
Select Case s
Case ServiceControllerStatus.Stopped
If Not s = _LastStatus Then
RaiseEvent Stopped(Me, New System.EventArgs)
End If
Case ServiceControllerStatus.Running
If Not s = _LastStatus Then
RaiseEvent Started(Me, New System.EventArgs)
End If
End Select
_LastStatus = s
End Sub
End Class
And the form:
Public Class Form1
Private Sub ServiceStarted(ByVal sender As Object, ByVal e As System.EventArgs) Handles ESC.Started
Me.TextBox1.Text = "STARTED"
End Sub
Private Sub ServiceStopped(ByVal sender As Object, ByVal e As System.EventArgs) Handles ESC.Stopped
Me.TextBox1.Text = "STOPPED"
End Sub
End Class
If I had to guess, I'd say that there's some sort of thread problem, but I'm not sure how to handle that in the form. Any ideas?
IF it is a threading issue then you are probably trying to update the UI from a non-UI thread.
So something like this should solve that...
Private Delegate Sub UpdateTextBoxDelegate(byval tText as String)
Private Sub UpdateTextBox(byval tText As String)
If Me.InvokeRequired Then
Me.Invoke(New UpdateTextBoxDelegate(AddressOf UpdateTextBox), tText)
Exit Sub
End If
TextBox1.Text = tText
End Sub
Private Sub ServiceStarted(ByVal sender As Object, ByVal e As System.EventArgs) Handles ESC.Started
UpdateTextBox ("STARTED")
End Sub
Private Sub ServiceStopped(ByVal sender As Object, ByVal e As System.EventArgs) Handles ESC.Stopped
UpdateTextBox("STOPPED")
End Sub