So in C# to declare and instantiate a UserControl, you would go about it similar to this:
UserControl1 userCont = new UserControl1();
userCont.Show();
And this would show your user control named UserControl1.
This is the way you do it in C#, now how do you do this in VB?
Because I have coded an Excel Add In, and have put a userControl in the ribbon, but it does not want to show, and that project is in VB, not C#.
EDIT:
Some explanation of my project:
I have an Excel 2013 and 2016 VSTO add-in project type.
I have 3 classes, namely:
UserControl1.vb - as my userControl
Ribbon.vb - as my ribbon class
ThisAddIn.vb - as the add in class
My userControl is rather simple, it has 3 buttons, a "Yes" button, a "No" button, and an "Add Tables" button. It has 1 listBox, and 12 checkboxes...
The Ribbon is also quite simple, I have 2 buttons in the Ribbon called "Show" and "Loop"...
The ThisAddIn class contains code that will make this add in work, such as methods and general functionality...
Okay so that's my classes...
The goal of my project is:
When the "Show" button is clicked, a CustomTaskPane will appear in excel on the right, inside this customTaskPane will be my userControl...
(This works)
Big thanks to DrDonut for his answer
When the "Add Tables" button is clicked (in the userControl), I want excel to iterate through all the sheets, and add every listObject's name (tables name) to the listBox.
(The Loop and Add Tables button are the same)
In C# I know you go:
this.ListBox1.Items.Add("Item 1");
And that will add an item to the listbox, the same principle is applied in VB, but with my ListBox sitting in my userControl which inherently sits in the CustomTaskPane, no items can seem to be added...
(Adding items to the list box does not work)
And with regards to the looping of tables, or retrieving their names, this doesn't work either...
(This is what I really want to get going nicely)
Hope this edit will shed some clarity on the situation...
Some gritty information:
OS: Windows 10 Pro (x64)
RAM: 32gb
CPU: i7-6700 #3.40ghz
Microsoft Visual Studio Community 2015
Microsoft Excel 2016 (x64)
In vb.net it's quite similar, for a task pan (the panel at the right side of an office application) it is:
Dim userControl as UserControl
Dim userTaskPane as Microsoft.office.tools.CustomTaskPane
userControl = new UserControl
userTaskPane = Me.CustomTaskPanes.Add(userControl, "Title")
userTaskPane.visible = true
Now it should show the panel.
Edit: Source: https://msdn.microsoft.com/en-us/library/aa942846.aspx
Edit 2: You also need to set the right references. Assuming that you use visual studio, go to the solution explorer -> Your project -> References. In my project these contain the following:
Microsoft.Office.Interop.Excel
Microsoft.Office.Tools
Microsoft.Office.Tools.Common
Microsoft.Office.tools.Common.v4.0.Utilities
Microsoft.Office.Tools.Excel
Microsoft.Office.Tools.v4.0.Framework
Microsoft.VisualStudio.Tools.Applications.Runtime
Office
I don't know if you need all of them, but for sure you will need some of them.
Related
I'm writing a simple VSTO add-in for Office. When the user clicks a button a single form appears, and on the form there are some single-line textboxes, some buttons and some labels. This is all in VB.NET.
Everything works as expected - except I cannot tab between controls on the form. I have set the TabIndex and TabStop properties (actually, left them at defaults, which look OK). I've also tried programmatically setting TabIndex and TabStop in the form's Shown handler - but this made no difference. Changing runtime from .NET 4.5 to 4.6 makes no difference.
The odd thing is that if I use exactly the same form (copy & paste the .vb file) in a Windows Forms App, the tab stops work. It seems there's something about this VSTO project (or perhaps all VSTO projects) that is stopping tabbing working.
I am using Visual Studio 2017 and the host application for the VSTO addin is MS Project 2016.
The difference between a standalone WinForms application and your Office add-in is the host application (can be MDI or SDI application).
Most probably you need to specify the parent window handle to the Show method. The method accepts an instance of the IWin32Window interface which represents the top-level window that will own this form.
I am trying to add an ActionPane to an Excel VSTO Add-in. I need to access the ThisWorkbook.ActionsPane collection to add my action panes.
The Microsoft documentation at:
https://learn.microsoft.com/en-us/visualstudio/vsto/how-to-add-an-actions-pane-to-word-documents-or-excel-workbooks?view=vs-2019
says:
To show the actions pane, add the user control to the Controls
property of the ThisDocument.ActionsPane field (Word) or
ThisWorkbook.ActionsPane field (Excel).
Add the following code to the ThisDocument or ThisWorkbook class as a
class-level declaration (do not add this code to a method).
This implies that I need to add a ThisWorkbook class to the VSTO solution. My questions are:
What base class contains the ActionsPlane collection?
How would I add a class derived from this base class to my VSTO?
Some on-line examples of a ThisWorkbook class contain regions that are designer generated.
My workload includes every VSTO item available. There are no Excel items at all under 'Add New Item' or 'Add New User Control' in Visual Studio 2019. Beyond the Ribbon Bar, there are no designers for VSTO.
The only way that I see to do this is to add a ThisWorkbook class manually.
Am I correct in saying that any designers that may have existed in previous versions of Visual Studio, no longer exist in Visual Studio 2019?
You need to differentiate document-level and application-level add-ins.
An actions pane is a customizable Document Actions task pane that is attached to a specific Microsoft Office Word document or Microsoft Office Excel workbook. The actions pane is hosted inside the Office task pane along with other built-in task panes, such as the XML Source task pane in Excel or the Styles and Formatting task pane in Word. You can use Windows Forms controls or WPF controls to design the actions pane user interface.
Read more about Actions panes in the How to: Add an Actions Pane to Word Documents or Excel Workbooks article if you are developing a document-level add-in.
If you are developing an application-level add-in you may be interested in using Custom task panes. Task panes are user interface panels that are typically docked to one side of a window in a Microsoft Office application. Custom task panes give you a way to create your own task pane and provide users with a familiar interface to access your solution's features. For example, the interface can contain controls that run code to modify documents or display data from a data source. See Walkthrough: Automate an application from a custom task pane to get started quickly.
I created tables and forms in Access 2016. When I Alt-F11 to VBE they do not show up. How do get them to show?
Tables shouldn't be visible in the VBE at all. So that's expected. Only objects that have a VBA module are shown in the VBE.
Forms are only shown in the VBE if they have a module. Add a module to a form by opening it in design view, and either choosing View Code on the Design tab of the ribbon, setting the Has Module property to Yes, or by adding code to one of the events.
I am creating a Word Addin using Visual Studio 2008 with Visual Basic language. I have created a custom ribbon group and a button name "Show_Form". I want that when I click on that button a windows form named "Form" will show.
Sub Button1_Click()
Form.show()
End Sub
It showing a error. Can you please help me.
There is no form called "Form"
You will need to do Form1.Show or Form2.Show etc
However it is good practice to name the forms to what they will be used for otherwise it can become difficult to understand the program code if everything is named so that it doesn't actually identify what it does.
I have a Windows Form with 7 Picture Boxes on it that are called PropButton1 through to PropButton7. I know they aren't buttons but I'm using them as buttons anyway (normal buttons aren't suitable for this purpose).
I want to add a custom "File Path" property to the Picture Boxes. To do this I've created a separate class that inherits the PictureBox class:
Public Class PropButton
Inherits PictureBox
Private SoundFilePath As String
Public Property SoundFile() As String
Get
Return SoundFilePath
End Get
Set(value As String)
SoundFilePath = value
End Set
End Property
End Class
I want to convert the original Picture Boxes from PictureBox to PropButton so I can read and write to things like PropButton1.SoundFilePath and I preferably want to do this without having to delete all of my Picture Boxes and start again. Is there a way to do this?
In Visual Studio look to the right in the Solution Explorer. It has a toolbar button to Show all files. Click it and you will see that you can expand the tree nodes for the forms and they contain three files. One that contains your source code, and another one called a Designer. The Designer file is automatically generated by Visual Studio and in most cases it should not be touched.
When you open the designer file you see all the initializations of the controls on your form and their declarations. Here you can easily change the declarations of your pictureboxes so that they are created as PropButtons instead.
Just be careful what you change here, because it can mess up the Visual Studio designer. But it is good to know what happens behind the scenes.
Look here first:
Change this...
...to this.
Yes, that is possible with the text editor. The Visual Basic IDE hides too much information, first thing you want to do is click the "Show All Files" icon in the Solution Explorer window. That adds a node next to your form in the same window, open it and double-click the Designer.vb file. Note the InitializeComponent() method and the declarations at the bottom of the file, you see the PictureBoxes being declared and initialized.
You can now simply Edit+Replace "System.Windows.Forms.PictureBox" with "PropButton".
Ensure you have a good backup before you do this.