Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Visual Studio Custom Add-Ins

Status
Not open for further replies.

MrTrue

Technical User
Jul 28, 2008
46
0
0
US
I apologize if this isn't the correct forum, but I'm not exactly sure where this should be posted... I just got Visual Studio 2010 and I'm working on a Custom Outlook Add-In. I'm using the example at to tie a new Ribbon to a Custom Pane (User Control). In the example it has you add a textbox to the pane. It's realatively simple to have the pane populate the Textbox1 with a value using the on_load event of the pane, but if I want to change the textbox value by clicking a button on the Ribbon, how do I access the textbox object to do so (from a ribbon control)? I've tried several different paths (such as Globals.ThisAddIn.TaskPane1.textbox1.text) and intellisense doesn't seem to want to give me the "textbox1.text" property... Most everything I've done to this point has been in VBA, and I know this is going to be a change for me... Any help is greatly appreciated!
 
Your textbox will exist as part of the UserControl, which will exist as part of the Ribbon.

You will need something like

Pseudo C#
TextBox tb = (TextBox)theRibbon.Controls("myUserControl").Controls("textBox1");



You've got questions and source code. We want both!
 
I used the C# to Vb conversion and came up with...

Dim tb As TextBox = Ribbon1.Controls("TaskPaneControl").Controls("textBox1")

tb.text = "My new text value."

However, "Controls" and "Control" does not appear to be available it wants me to create a method stub or shared property. Is there something I need to import aside from the system.windows.forms?

I'm sure there is some simple explanation to what I'm doing wrong, but I've been spinning my wheels for hours...
 
I finally got it.

On thisaddin class i made customtaskpane1 public, then used...

Code:
Dim myPane As TaskPaneControl = Globals.ThisAddIn.taskPaneControl1
Dim tb As TextBox = myPane.TextBox1
tb.Text = "Finally got it."
 
In case there are any other people just getting started with something like this, I also figured out that rather than making the whole taskpanecontrol public, I should just be exposing the component I need by using get/set. In thisAddin class I added the following:

Code:
 Public Property myTB() As Windows.Forms.TextBox
        Get
            Return taskPaneControl1.TextBox1
        End Get

        Set(ByVal value As Windows.Forms.TextBox)

        End Set
 End Property

Then I can access the component I need from the ribbon buttons using:

Code:
            'USE THIS IN YOUR BUTTON EVENT TO SET THE VALUE OF TB
            Dim tb As TextBox = Globals.ThisAddIn.myTB
            tb.Text = "Finally got it."

            'OR

            'USE THIS IN THE EVENT TO RETURN THE CURRENT 
            'VALUE OF THE TB
            MsgBox(Globals.ThisAddIn.myTB.Text)

I know it's pretty basic, but I guess we have to understand the basics first, and if you're like me and all you've done in the past is VBA, switching to VB.NET is not the most intuitive of transitions... %-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top