• 主页
  • ASP
  • .NET Framework
  • Web Services
  • VB
  • VC
  • 图表区
  • 分析与设计
  • 组件/控件开发
  • LINQ
hackate 2005年07月08日
关于自定义控件问题!希望控件高手能进来相助,苯苯感激不尽!
最近在学组件开发,买了本<深入剖析组件设计>的书,然后现在边学边做到NumberEditor这个控件这,卡住了。不知道怎么弄,老是不行啊。特郁闷,所以把代码,发过来,大家看看,谢谢,有三个页代码。麻烦耐心看下,谢谢啦!
以下为:HotTrackStyle.vb类代码

Imports System
Imports System.Text
Imports System.ComponentModel
Imports System.Drawing
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls

Namespace hackate
Public Class HotTrackStyle
Implements IStateManager

Private _enabled As Boolean = False
Private _marked As Boolean = False

Private _color As Color = Color.Black
Private _backgroundcolor As color = color.White
Private _bordercolor As Color = Color.Black
Private _borderstyle As BorderStyle = BorderStyle.NotSet
Private _borderwidth As Unit = Unit.Pixel(1)

Private _nonFocusColor As Color
Private _nonFocusBackgroundColor As Color
Private _nonFocusBorderColor As Color
Private _nonFocusBorderStyle As BorderStyle
Private _nonFocusBorderWidth As Unit

Private Const HT_JS_GUID = "{E4D52305-E153-4e6b-8DBE-A17F2FC991F5}"
Private Const HT_JS_Script = "<script language='javascript' SRC='/aspnet_client/hackate.net/hottrack.js'></script>"
Private Const Script_Begin = "<script language='javascript'>"
Private Const Script_End = "</script>"
Private Const HT_JS_Content = "var {0}_obj = new HotTrackObject(document.all['{0}'],""{1}"",""{2}"",""{3}"",""{4}"",""{5}"");"

<DefaultValue(GetType(color), "Black"), NotifyParentProperty(True)> _
Public Property Color() As color
Get
Return _color
End Get
Set(ByVal Value As color)
_color = Value
End Set
End Property

<DefaultValue(GetType(color), "White"), NotifyParentProperty(True)> _
Public Property BackgroundColor() As color
Get
Return _backgroundcolor
End Get
Set(ByVal Value As color)
_backgroundcolor = Value
End Set
End Property

<DefaultValue(GetType(Color), "Black"), NotifyParentProperty(True)> _
Public Property BorderColor() As Color
Get
Return _bordercolor
End Get
Set(ByVal Value As Color)
_bordercolor = Value
End Set
End Property

<DefaultValue(System.Web.UI.WebControls.BorderStyle.NotSet), NotifyParentProperty(True)> _
Public Property BorderStyle() As BorderStyle
Get
Return _borderstyle
End Get
Set(ByVal Value As BorderStyle)
_borderstyle = Value
End Set
End Property

<DefaultValue(GetType(Unit), "1px"), NotifyParentProperty(True)> _
Public Property BorderWidth() As Unit
Get
Return _borderwidth
End Get
Set(ByVal Value As Unit)
_borderwidth = Value
End Set
End Property

<DefaultValue(False), NotifyParentProperty(True)> _
Public Property Enabled() As Boolean
Get
Return _enabled
End Get
Set(ByVal Value As Boolean)
_enabled = Value
End Set
End Property

Public Overridable Sub AddScriptRender(ByVal htpage As Page)
If Not htpage.IsClientScriptBlockRegistered(HT_JS_GUID) Then
htpage.RegisterClientScriptBlock(HT_JS_GUID, HT_JS_Script)
End If
End Sub

Public Overridable Sub AddAttributesToRender(ByVal writer As HtmlTextWriter, ByVal ClientID As String)
If _enabled Then
writer.AddAttribute("onmousemove", ClientID + "_obj.NotActive(true)")
writer.AddAttribute("onmouseout", ClientID + "_obj.NotActive(false)")

writer.AddAttribute("onfocus", ClientID + "_obj.Active(true)")
writer.AddAttribute("onblur", ClientID + "_obj.Active(false)")
End If
End Sub

Public Overridable Sub Render(ByVal writer As HtmlTextWriter, ByVal htcontrol As Control)
writer.WriteLine(Script_Begin)
writer.WriteLine(HT_JS_Content, htcontrol.ClientID, ColorTranslator.ToHtml(_color), ColorTranslator.ToHtml(_backgroundcolor), ColorTranslator.ToHtml(_bordercolor), _borderstyle.ToString, _borderwidth.ToString)
writer.WriteLine(Script_End)
End Sub

#Region "实现ViewState接口"
Public ReadOnly Property IsTrackingViewState() As Boolean Implements System.Web.UI.IStateManager.IsTrackingViewState
Get
Return _marked
End Get
End Property

Public Sub LoadViewState(ByVal state As Object) Implements System.Web.UI.IStateManager.LoadViewState
Dim o As Object() = CType(state, Object())
_enabled = CType(o(0), Boolean)
_color = CType(o(1), Color)
_backgroundcolor = CType(o(2), Color)
_bordercolor = CType(o(3), Color)
_borderstyle = CType(o(4), BorderStyle)
_borderwidth = CType(o(5), Unit)
_nonFocusColor = CType(o(6), Color)
_nonFocusBackgroundColor = CType(o(7), Color)
_nonFocusBorderColor = CType(o(8), Color)
_nonFocusBorderStyle = CType(o(9), BorderStyle)
_nonFocusBorderWidth = CType(o(10), Unit)
End Sub

Public Function SaveViewState() As Object Implements System.Web.UI.IStateManager.SaveViewState
Dim o(11) As Object
o(0) = _enabled
o(1) = _color
o(2) = _backgroundcolor
o(3) = _bordercolor
o(4) = _borderstyle
o(5) = _borderwidth
o(6) = _nonFocusColor
o(7) = _nonFocusBackgroundColor
o(8) = _nonFocusBorderColor
o(9) = _nonFocusBorderStyle
o(10) = _nonFocusBorderWidth
Return o
End Function

Public Sub TrackViewState() Implements System.Web.UI.IStateManager.TrackViewState
_marked = True
End Sub
#End Region

Public Sub New()

End Sub
End Class
End Namespace
...全文
195 点赞 收藏 18
写回复
18 条回复

还没有回复,快来抢沙发~

发动态
发帖子
.NET技术社区
创建于2007-09-28

4.8w+

社区成员

66.8w+

社区内容

.NET技术交流专区
社区公告
暂无公告