
Imports ExcelDna.Integration.CustomUI
Imports System.Runtime.InteropServices
Imports System.Drawing
Imports System.Windows.Forms' Define the backing class for the Ribbon
' Would need to be marked with [ComVisible(true)] if in a project that is marked as [assembly:ComVisible(false)] which is the default for VS projects.
<ComVisible(True)> Public Class MyRibbon
Inherits ExcelDna.Integration.CustomUI.ExcelRibbon Private ctp As CustomTaskPane Public Shared Sub ctp_VisibleStateChange(ctp As CustomTaskPane)
MsgBox("Visibility changed to " & ctp.Visible)
End Sub Public Shared Sub ctp_DockPositionStateChange(ctp As CustomTaskPane)
Dim ctrl As MyUserControl
ctrl = CType(ctp.ContentControl, MyUserControl)
ctrl.TheLabel.Text = "Moved to " & ctp.DockPosition.ToString()
End Sub Public Sub OnShowCTP(ByVal control As IRibbonControl)
If ctp Is Nothing Then
ctp = CustomTaskPaneFactory.CreateCustomTaskPane(Type.GetType("MyUserControl"), "My Super Custom Task Pane!")
ctp.Visible = True
ctp.DockPosition = MsoCTPDockPosition.msoCTPDockPositionLeft
AddHandler ctp.DockPositionStateChange, AddressOf ctp_DockPositionStateChange
AddHandler ctp.VisibleStateChange, AddressOf ctp_VisibleStateChange
Else
ctp.Visible = True
End If
End Sub Public Sub OnDeleteCTP(ByVal control As IRibbonControl)
If Not ctp Is Nothing Then
ctp.Delete()
ctp = Nothing
End If
End Sub
End Class' Define the UserControl to display on the CTP ///////////////////////////
' Would need to be marked with [ComVisible(true)] if in a project that is marked as [assembly:ComVisible(false)] which is the default for VS projects.
Public Class MyUserControl
Inherits System.Windows.Forms.UserControl Public TheLabel As System.Windows.Forms.Label
Public Sub New()
TheLabel = New System.Windows.Forms.Label()
TheLabel.Text = "Tinh Dao"
TheLabel.Location = New System.Drawing.Point(20, 20)
TheLabel.Size = New System.Drawing.Size(200, 60)
Controls.Add(TheLabel)
End Sub
End Class<?xml version="1.0" encoding="utf-8"?>
<DnaLibrary Name="CTP Add-In" RuntimeVersion="v4.0" xmlns="http://schemas.excel-dna.net/addin/2018/05/dnalibrary">
<ExternalLibrary Path="CTP.dll" ExplicitExports="false" LoadFromBytes="true" Pack="true" IncludePdb="false" /> <!--
The RuntimeVersion attribute above allows two settings:
* RuntimeVersion="v4.0" - for .NET 4 and 4.5
* RuntimeVersion="v2.0" - for .NET 2.0, 3.0 and 3.5 You can have IntelliSense (autocomplete) and validation for this file.
See https://github.com/Excel-DNA/ExcelDna/tree/master/Distribution/XmlSchemas/ Additional referenced assemblies can be specified by adding 'Reference' tags.
These libraries will not be examined and registered with Excel as add-in libraries,
but will be packed into the -packed.xll file and loaded at runtime as needed.
For example: <Reference Path="Another.Library.dll" Pack="true" /> Excel-DNA also allows the XML for ribbon UI extensions to be specified in the .dna file.
See the main Excel-DNA site at http://excel-dna.net for downloads of the full distribution.
-->
<CustomUI>
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
<ribbon>
<tabs>
<tab id="tab1" label="Custom Task Pane cua Toi">
<group id="SampleGroup" label="CTP Control">
<button id="Button1" label="Show CTP" onAction="OnShowCTP" imageMso="AcceptInvitation" size="large" />
<button id="Button2" label="Delete CTP" onAction="OnDeleteCTP" imageMso="DeclineInvitation" size="large" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>
</CustomUI>
<Reference Path="System.Windows.Forms.dll"/>
<Reference Path="System.Drawing.dll"/>
</DnaLibrary>

--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/exceldna/662dd0dd-4464-4c00-a508-588eeb57571f%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to exce...@googlegroups.com.