0

Problem: I am building a Custom Task Pane in Outlook (VS 2019) using VB. Coming along but I am not able to find how to keep the controls added (textbox, Listbox, ect.) to be shared and accessible from other User Controls, modules, etc.

Current Fix: I can manually add the command "Shared" in the usercontrol.designer.vb part (where it says do not edit). For example to change:

Friend WithEvents lbMatterList as Windows.Forms.ListBox

to:

Friend Shared WithEvents lbMatterList as Windows.Forms.ListBox

This works for the build but if I edit any part of the UserControl in the designer the code reset and I need to manually re-edit every time.

I know VB is not the best language but it is the one I know (this is not my job, I am just building the TaskPane to help my job).

Is there a way to set the control as "Shared" without manually editing or having it reset when the designer is used?

Example Code:

At this stage the attempted action is simple. I am only trying to use a module to update the contents of the List box with values from an Array

TaskManagement.vb (module)Code:

Public Sub PopulateMatterList()
    'MatterNotes = TaskDetailView.
    With TaskManagerCtrl.lbMatterList
        .ClearSelected()
        .Items.Add(MatterListPrimary(0, 1) & " - " & MatterListPrimary(0, 0))
        '.Items.Add()
    End With
End Sub

Error: BC30469 Reference to a non-shared member requires an object reference

TaskManagerCrtl.Designer.vb Code:

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class TaskManagerCtrl
Inherits System.Windows.Forms.UserControl

'UserControl overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
    Try
        If disposing AndAlso components IsNot Nothing Then
            components.Dispose()
        End If
    Finally
        MyBase.Dispose(disposing)
    End Try
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.  
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
    Me.lbMatterList = New System.Windows.Forms.ListBox()
    Me.Button1 = New System.Windows.Forms.Button()
    Me.SuspendLayout()
    '
    'lbMatterList
    '
    Me.lbMatterList.ColumnWidth = 900
    Me.lbMatterList.FormattingEnabled = True
    Me.lbMatterList.ItemHeight = 25
    Me.lbMatterList.Location = New System.Drawing.Point(38, 329)
    Me.lbMatterList.MultiColumn = True
    Me.lbMatterList.Name = "lbMatterList"
    Me.lbMatterList.SelectionMode = System.Windows.Forms.SelectionMode.MultiSimple
    Me.lbMatterList.Size = New System.Drawing.Size(898, 979)
    Me.lbMatterList.TabIndex = 0
    Me.lbMatterList.ValueMember = "Shared"
    '
    'Button1
    '
    Me.Button1.Location = New System.Drawing.Point(358, 98)
    Me.Button1.Name = "Button1"
    Me.Button1.Size = New System.Drawing.Size(170, 86)
    Me.Button1.TabIndex = 1
    Me.Button1.Text = "Button1"
    Me.Button1.UseVisualStyleBackColor = True
    '
    'TaskManagerCtrl
    '
    Me.AutoScaleDimensions = New System.Drawing.SizeF(12.0!, 25.0!)
    Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
    Me.Controls.Add(Me.Button1)
    Me.Controls.Add(Me.lbMatterList)
    Me.Name = "TaskManagerCtrl"
    Me.Size = New System.Drawing.Size(1010, 1374)
    Me.ResumeLayout(False)

End Sub

Friend WithEvents Button1 As Windows.Forms.Button
Friend Shared WithEvents lbMatterList As Windows.Forms.ListBox

End Class

Adding Shared in the last line needs to be manual to avoid the error. I cannot find where to set the control as shared.

help-info.de
  • 6,695
  • 16
  • 39
  • 41
  • There is something not right going on here. The fact that you're having to change access modifiers in the designer code suggests to me there is a much deeper issue in your solution and updating the modifiers is really just masking the real source. Not sure what exactly, but might pay to update your question with some context, example code and so on – Hursey Sep 03 '21 at 00:28
  • I added to code, I assume there is a setting somewhere that I am missing. – Rowan le Clercq Sep 04 '21 at 11:30

1 Answers1

0

Adding the code to ThisAddIn.vb with "Shared" allowed access through ThisAddin. from the module without editing the designer code.

Public WithEvents Active_Explorer As Microsoft.Office.Interop.Outlook.Explorer

'establish Outlook.TaskPanes
Public Shared TaskManagerCtrl As TaskManagerCtrl
Public Shared WithEvents ManagerTaskPane As Microsoft.Office.Tools.CustomTaskPane

'establish Detailed View Outlook.TasPane
Public Shared TaskDetailView As TaskDetailView
Public Shared WithEvents DetailsTaskPane As Microsoft.Office.Tools.CustomTaskPane