本文整理汇总了VB.NET中System.Drawing.Design.ToolboxItemCreatorCallback代理的典型用法代码示例。如果您正苦于以下问题:VB.NET ToolboxItemCreatorCallback代理的具体用法?VB.NET ToolboxItemCreatorCallback怎么用?VB.NET ToolboxItemCreatorCallback使用的例子?那么恭喜您, 这里精选的代理代码示例或许可以为您提供帮助。
在下文中一共展示了ToolboxItemCreatorCallback代理的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1: TextDataTextBoxComponent
' 导入命名空间
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Drawing
Imports System.Drawing.Design
Imports System.Security.Permissions
Imports System.Windows.Forms
' Component that adds a "Text" data format ToolboxItemCreatorCallback
' to the Toolbox. This component uses a custom ToolboxItem that
' creates a TextBox containing the text data.
<PermissionSetAttribute(SecurityAction.Demand, Name:="FullTrust")> _
Public Class TextDataTextBoxComponent
Inherits System.ComponentModel.Component
Private creatorAdded As Boolean = False
Private ts As IToolboxService
Public Sub New()
End Sub
' ISite override to register TextBox creator
Public Overrides Property Site() As System.ComponentModel.ISite
Get
Return MyBase.Site
End Get
Set(ByVal Value As System.ComponentModel.ISite)
If (Value IsNot Nothing) Then
MyBase.Site = Value
If Not creatorAdded Then
AddTextTextBoxCreator()
End If
Else
If creatorAdded Then
RemoveTextTextBoxCreator()
End If
MyBase.Site = Value
End If
End Set
End Property
' Adds a "Text" data format creator to the toolbox that creates
' a textbox from a text fragment pasted to the toolbox.
Private Sub AddTextTextBoxCreator()
ts = CType(GetService(GetType(IToolboxService)), IToolboxService)
If (ts IsNot Nothing) Then
Dim textCreator As _
New ToolboxItemCreatorCallback(AddressOf Me.CreateTextBoxForText)
Try
ts.AddCreator( _
textCreator, _
"Text", _
CType(GetService(GetType(IDesignerHost)), IDesignerHost))
creatorAdded = True
Catch ex As Exception
MessageBox.Show(ex.ToString(), "Exception Information")
End Try
End If
End Sub
' Removes any "Text" data format creator from the toolbox.
Private Sub RemoveTextTextBoxCreator()
If (ts IsNot Nothing) Then
ts.RemoveCreator( _
"Text", _
CType(GetService(GetType(IDesignerHost)), IDesignerHost))
creatorAdded = False
End If
End Sub
' ToolboxItemCreatorCallback delegate format method to create
' the toolbox item.
Private Function CreateTextBoxForText( _
ByVal serializedObject As Object, _
ByVal format As String) As ToolboxItem
Dim o As New DataObject(CType(serializedObject, IDataObject))
Dim formats As String() = o.GetFormats()
If o.GetDataPresent("System.String", True) Then
Return New TextToolboxItem(CStr(o.GetData("System.String", True)))
End If
Return Nothing
End Function
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If creatorAdded Then
RemoveTextTextBoxCreator()
End If
End Sub
End Class
' Custom toolbox item creates a TextBox and sets its Text property
' to the constructor-specified text.
<PermissionSetAttribute(SecurityAction.Demand, Name:="FullTrust")> _
Public Class TextToolboxItem
Inherits System.Drawing.Design.ToolboxItem
Private [text] As String
Delegate Sub SetTextMethodHandler( _
ByVal c As Control, _
ByVal [text] As String)
Public Sub New(ByVal [text] As String)
Me.text = [text]
End Sub
' ToolboxItem.CreateComponentsCore override to create the TextBox
' and link a method to set its Text property.
<PermissionSetAttribute(SecurityAction.Demand, Name:="FullTrust")> _
Protected Overrides Function CreateComponentsCore(ByVal host As IDesignerHost) As IComponent()
Dim textbox As TextBox = CType(host.CreateComponent(GetType(TextBox)), TextBox)
' Because the designer resets the text of the textbox, use
' a SetTextMethodHandler to set the text to the value of
' the text data.
Dim c As Control = host.RootComponent
c.BeginInvoke( _
New SetTextMethodHandler(AddressOf OnSetText), _
New Object() {textbox, [text]})
Return New System.ComponentModel.IComponent() {textbox}
End Function
' Method to set the text property of a TextBox after it is initialized.
Private Sub OnSetText(ByVal c As Control, ByVal [text] As String)
c.Text = [text]
End Sub
End Class
开发者ID:VB.NET开发者,项目名称:System.Drawing.Design,代码行数:138,代码来源:ToolboxItemCreatorCallback
注:本文中的System.Drawing.Design.ToolboxItemCreatorCallback代理示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论