我想学习编写控件,哪位能给一个控件的源码,我学习一下?十分感谢!!!![email protected]
[email protected]

解决方案 »

  1.   

    这是一个标题控件调用方法:
    <%@ Register TagPrefix="title" Namespace="HxStudio.CTitle" Assembly="Title" %>
    <title:Title id="Title1" title="欢迎光临" runat="server"></title:Title>源程序
    注:这要新建项目生成DLL后,在你要需要的项目中引用
    Title.vb
    Imports System.Xml
    Imports System.ComponentModel
    Imports System.Web.UI<DefaultProperty("Text"), Designer(GetType(CTitleDesigner)), _
     ToolboxData("<{0}:CTitle runat=server></{0}:CTitle>")> _
    Public Class Title
        Inherits System.Web.UI.WebControls.WebControl    Dim _title As String
        Dim _displayTitle As Boolean = True
        Dim _styles As String
        Dim _displayStyle As Boolean
        Dim _ForTitle As String '//标题前缀
    #Region "属性集"    <Bindable(True), Category("Title"), DefaultValue(""), Description("副标题名称")> _
        Property Title() As String
            Get
                Return _title
            End Get        Set(ByVal Value As String)
                _title = Value
            End Set
        End Property    <Bindable(True), Category("Title"), DefaultValue(""), Description("是否显示副标题")> _
        Property DisplayTitle() As Boolean
            Get
                Return _displayTitle
            End Get        Set(ByVal Value As Boolean)
                _displayTitle = Value
            End Set
        End Property    <Bindable(True), Category("Title"), DefaultValue(""), Description("样式表路径属性")> _
        Property Styles() As String
            Get
                Return _styles
            End Get        Set(ByVal Value As String)
                _styles = Value
            End Set
        End Property    <Bindable(True), Category("Title"), DefaultValue(""), Description("显示显示样式")> _
        Property DisplayStyle() As Boolean
            Get
                Return _displayStyle
            End Get        Set(ByVal Value As Boolean)
                _displayStyle = Value
            End Set
        End Property    <Bindable(True), Browsable(False), Category("Title"), DefaultValue(""), Description("前缀标题")> _
        Property ForTitle() As String
            Get
                Return _ForTitle
            End Get        Set(ByVal Value As String)
                _ForTitle = Value
            End Set
        End Property
    #End Region    Protected Overrides Sub onInit(ByVal e As EventArgs)
            Dim strPath As String = Me.Context.Request.PhysicalApplicationPath().ToString() & "web.config"
            Dim objDom As XmlDocument = New XmlDocument
            objDom.Load(strPath)
            Dim xmlNode As xmlNode = objDom.SelectSingleNode("//appSettings/add[@key='SiteName']")
            _ForTitle = xmlNode.Attributes("value").Value.ToString()
        End Sub    Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter)
            If _displayTitle = True Then
                output.Write("<Title>" & _ForTitle & _title & "</Title>")
                output.Write(vbCrLf & vbTab & vbTab & "<meta name=" & Chr(34) & "Description" & Chr(34) & " content=" & Chr(34) & "最有名的网站" & Chr(34) & " />")
                output.Write(vbCrLf & vbTab & vbTab & "<meta name=" & Chr(34) & "Keywords" & Chr(34) & " content=" & Chr(34) & "电子商务网" & Chr(34) & " />")
                output.Write(vbCrLf & vbTab & vbTab & "<meta name=" & Chr(34) & "Keywords" & Chr(34) & " content=" & Chr(34) & "图书馆" & Chr(34) & " />")
            End If
            If _displayStyle = True Then
                output.Write(vbCrLf & vbTab & vbTab & "<Link  href=" & Chr(34) & "" & _styles & "" & Chr(34) & " type=" & Chr(34) & "text/css" & Chr(34) & " rel=" & Chr(34) & "stylesheet" & Chr(34) & " />")
            End If
        End SubEnd Class
      

  2.   

    www.codeproject.com上面有很多例子的