Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Text
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
'www.51aspx.com
<Assembly: WebResource("PicTextBox.Upload.htm", "text/html", PerformSubstitution:=True)> 
<DefaultProperty("TextValue"), ToolboxData("<{0}:PicTextBox runat=server></{0}:PicTextBox>")> _
Public Class PicTextBox
    Inherits CompositeControl
    Public Enum WindowSkin
        Skin_Default = 1
        Skin_iblue = 2
        Skin_iblack = 3
        Skin_blue = 4
        Skin_chrome = 5
        Skin_discuz = 6
        Skin_jtop = 7
        Skin_mac = 8
        Skin_idialog = 9
    End Enum
    Private _Skin As WindowSkin
    Private PicText As TextBox
    Const PicButton As String = "<img src='/App_Themes/ManagerTheme/Images/Pic.gif' alt='选择图片' style='border:0px;' /></div>"
    Private _SelectPath As String = "/"
    Private _FileEx As String = ""
    Property TextValue() As String
        Get
            EnsureChildControls()
            Return PicText.Text
        End Get
        Set(ByVal value As String)
            EnsureChildControls()
            PicText.Text = value
        End Set
    End Property
    Property Skin() As WindowSkin
        Get
            Return _Skin
        End Get
        Set(ByVal value As WindowSkin)
            _Skin = value
        End Set
    End Property
    Property SelectPath() As String
        Get
            Return _SelectPath
        End Get
        Set(ByVal value As String)
            If value.Length > 0 Then
                _SelectPath = value
            End If
        End Set
    End Property

    Public Property FileEx() As String
        Get
            Return _FileEx
        End Get
        Set(ByVal value As String)
            _FileEx = value
        End Set
    End Property

    Protected Overrides Sub RecreateChildControls()
        EnsureChildControls()
    End Sub
    Protected Overrides Sub CreateChildControls()
        Controls.Clear()
        PicText = New TextBox
        PicText.ID = Me.ID + "_PicTextBox"
        Controls.Add(PicText)
    End Sub

    Protected Overrides Sub RenderContents(ByVal writer As HtmlTextWriter)
        'AddAttributesToRender(writer)
        writer.Write("<div style='float:left'>")
        PicText.RenderControl(writer)
        writer.Write("</div>")
        writer.Write("<div style='float:left;padding:5px 0px 0px 0px;' onclick=""javascript:$.dialog({data:'" & FileEx & "##" & SelectPath & "##" & PicText.ClientID & "',content: 'url:" & Page.ClientScript.GetWebResourceUrl(GetType(PicTextBox), "PicTextBox.Upload.htm") & " ',width:900,height:650,max:false,lock:true});"">")
        writer.Write(PicButton)
    End Sub
    Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
        Dim mSkin As String = String.Empty
        Select Case Skin
            Case WindowSkin.Skin_blue
                mSkin = "blue"
            Case WindowSkin.Skin_chrome
                mSkin = "chrome"
            Case WindowSkin.Skin_discuz
                mSkin = "discuz"
            Case WindowSkin.Skin_iblack
                mSkin = "iblack"
            Case WindowSkin.Skin_iblue
                mSkin = "iblue"
            Case WindowSkin.Skin_idialog
                mSkin = "idialog"
            Case WindowSkin.Skin_jtop
                mSkin = "Skin_jtop"
            Case WindowSkin.Skin_mac
                mSkin = "mac"
            Case Else
                mSkin = "default"
        End Select
        If Not Page.ClientScript.IsClientScriptIncludeRegistered("jqueryminScript") Then Page.ClientScript.RegisterClientScriptInclude("jqueryminScript", "/App_Themes/ManagerTheme/js/jquery.min.js")
        If Not Page.ClientScript.IsClientScriptIncludeRegistered("lhgdialogminScript") Then Page.ClientScript.RegisterClientScriptInclude("lhgdialogminScript", "/App_Themes/ManagerTheme/js/lhgdialog.min.js?skin=" & mSkin)
        MyBase.OnPreRender(e)
    End Sub

End Class
