• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

VB.NET IDictionaryService接口代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了VB.NET中System.ComponentModel.Design.IDictionaryService接口的典型用法代码示例。如果您正苦于以下问题:VB.NET IDictionaryService接口的具体用法?VB.NET IDictionaryService怎么用?VB.NET IDictionaryService使用的例子?那么恭喜您, 这里精选的接口代码示例或许可以为您提供帮助。



在下文中一共展示了IDictionaryService接口的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。

示例1: New

' 导入命名空间
Imports System.Collections
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Drawing
Imports System.Data
Imports System.Windows.Forms

Namespace IDictionaryServiceControl

    ' This example control works with the IDictionaryServiceDesigner to demonstrate
    ' using the IDictionaryService for storing data provided by a designer, and
    ' accessing it from a control. The IDictionaryService provides a Site-specific 
    ' key-based dictionary. An IDictionaryServiceDesigner sets an ArrayList of strings 
    ' to the dictionary with a "DesignerData" key, and its contents are accessed and
    ' displayed once the Update box is clicked at design time.
    <DesignerAttribute(GetType(IDictionaryServiceDesigner), GetType(IDesigner))> _
     Public Class IDictionaryServiceControl
        Inherits System.Windows.Forms.UserControl
        Public al As ArrayList

        Public Sub New()
            ' Initializes the example control.
            al = New ArrayList()
            Me.Size = New Size(344, 88)
            Me.BackColor = Color.White
        End Sub 

        ' Draws the instructions and user interface, and any strings contained
        ' in a local ArrayList.
        Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
            If Me.DesignMode Then
                e.Graphics.DrawString("IDictionaryServiceDesigner Control", New Font(FontFamily.GenericMonospace, 9), New SolidBrush(Color.Blue), 5, 4)
                e.Graphics.DrawString("Click the Update box to update display strings", New Font(FontFamily.GenericMonospace, 8), New SolidBrush(Color.DarkGreen), 5, 17)
                e.Graphics.DrawString("from the IDictionaryService.", New Font(FontFamily.GenericMonospace, 8), New SolidBrush(Color.DarkGreen), 5, 29)

                e.Graphics.FillRectangle(New SolidBrush(Color.Beige), 270, 7, 60, 10)
                e.Graphics.DrawRectangle(New Pen(New SolidBrush(Color.Black), 1), 270, 7, 60, 10)
                e.Graphics.DrawString("Update", New Font(FontFamily.GenericMonospace, 7), New SolidBrush(Color.Black), 282, 7)

                Dim i As Integer
                For i = 0 To al.Count - 1
                    e.Graphics.DrawString(CStr(al(i)), New Font(FontFamily.GenericMonospace, 8), New SolidBrush(Color.Black), 5, 44 + i * 12)
                Next i
            End If
        End Sub

        ' On mouse down, this method attempts to access the IDictionaryService and 
        ' obtain an ArrayList with a key of "DesignerData" in the dictionary.
        ' If successful, this ArrayList is set to the local ArrayList.
        Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
            ' Attempts to obtain the IDictionaryService using the Control.GetService method.
            Dim ds As IDictionaryService = CType(GetService(GetType(IDictionaryService)), IDictionaryService)
            ' If the service was obtained...
            If (ds IsNot Nothing) Then
                ' Attempts to retrieve a list with a key of "DesignerData".
                Dim list As ArrayList = CType(ds.GetValue("DesignerData"), ArrayList)
                ' If the list exists, sets the list obtained by the 
                ' IDictionaryService to the local list.
                If (list IsNot Nothing) Then
                    Me.al = list
                End If
                Me.Refresh()
            End If
        End Sub 
    End Class 

    ' This designer uses the IDictionaryService to store an ArrayList of 
    ' information strings that the associated control can access and 
    ' display. The IDictionaryService creates a new dictionary for each Site.
    Public Class IDictionaryServiceDesigner
        Inherits System.Windows.Forms.Design.ControlDesigner

        Public Sub New()
        End Sub 

        ' On designer initialization, this method attempts to obtain 
        ' the IDictionaryService, and populates an ArrayList
        ' associated with a "DesignerData" key in the dictionary with 
        ' designer- and control-related information strings.
        Public Overrides Sub Initialize(ByVal component As System.ComponentModel.IComponent)
            MyBase.Initialize(component)
            Dim ds As IDictionaryService = CType(component.Site.GetService(GetType(IDictionaryService)), IDictionaryService)
            If (ds IsNot Nothing) Then
                ' If the dictionary service does not contain a 
                ' DesignerData key, adds an ArrayList for that key.
                If ds.GetValue("DesignerData") Is Nothing Then
                    ds.SetValue("DesignerData", New ArrayList())
                    ds.SetValue("DesignerData", New ArrayList())
                End If

                ' Obtains the ArrayList with the "DesignerData" key 
                ' from the dictionary service.
                Dim al As ArrayList = CType(ds.GetValue("DesignerData"), ArrayList)
                If (al IsNot Nothing) Then
                    al.Clear()
                    ' Populates the array list with designer and 
                    ' control information strings.
                    al.Add(("Designer type: " + Me.GetType().Name))
                    al.Add(("Control type:  " + Me.Control.GetType().Name))
                    al.Add(("Control name:  " + Me.Control.Name))
                End If
            End If
        End Sub 

        ' Translates the point to client coordinates and passes the 
        ' messages to the control while over the click box.
        Protected Overrides Function GetHitTest(ByVal point As System.Drawing.Point) As Boolean
            Dim translated As Point = Me.Control.PointToClient(point)
            If translated.X > 269 And translated.X < 331 And translated.Y > 7 And translated.Y < 18 Then
                Return True
            Else
                Return MyBase.GetHitTest(point)
            End If
        End Function 
    End Class 

End Namespace
开发者ID:VB.NET开发者,项目名称:System.ComponentModel.Design,代码行数:118,代码来源:IDictionaryService



注:本文中的System.ComponentModel.Design.IDictionaryService接口示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
VB.NET ICustomMarshaler接口代码示例发布时间:2022-05-26
下一篇:
VB.NET TextPattern.TabsAttribute字段代码示例发布时间:2022-05-26
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap