Meddelande

Minska
No announcement yet.

ASP.NET (VB) UC för png-halvtransparens.

Minska
X
  • Filter
  • Klockan
  • Show
Clear All
new posts

  • ASP.NET (VB) UC för png-halvtransparens.

    Eftersom att IE inte kan visa halvtransparenta png-bilder så skapade jag en liten work-around.
    Tips på förbättringar/rättelser mottages varmt.
    Kod:
    <%@ Control Language="VB" ClassName="pngControl" %>	 
    
    <%@ Import Namespace="system" %>
    <%@ Import Namespace="system.web.ui" %>
    
    <script runat=server>
        
        Private strimageUrl, strStyle, strCssClass, strAlternateText, strHeight, strWidth, strImageAlign As String
        
        Protected Function GetBrowser() As String
            Dim br As System.Web.HttpBrowserCapabilities = Request.Browser
            Dim sBrowserName As String = UCase(br.Browser)
            Return sBrowserName.ToString()
        End Function
    
        'imageUrl
        Public WriteOnly Property imageUrl() As String
            Set(ByVal value As String)
                strimageUrl = value
            End Set
        End Property
        
        'style
        Public WriteOnly Property style() As String
            Set(ByVal value As String)
                If GetBrowser() = "IE" Then
                    strStyle = value
                Else
                    strStyle = " style=""" & value & """ "
                End If
            End Set
        End Property
        
        'CssClass
        Public WriteOnly Property CssClass() As String
            Set(ByVal value As String)
                strCssClass = " class=""" & value & """"
            End Set
        End Property
        
        'AlternateText
        Public WriteOnly Property AlternateText() As String
            Set(ByVal value As String)
                strAlternateText = value
            End Set
        End Property
        
        'Height
        Public WriteOnly Property Height() As String
            Set(ByVal value As String)
                If GetBrowser() = "IE" Then
                    strHeight = "height:" & value & "px;"
                Else
                    strHeight = " height=""" & value & """"
                End If
            End Set
        End Property
        
        'Width
        Public WriteOnly Property Width() As String
            Set(ByVal value As String)
                If GetBrowser() = "IE" Then
                    strWidth = "width:" & value & "px;"
                Else
                    strWidth = " width=""" & value & """"
                End If
            End Set
        End Property
        
        'ImageAlign
        Public WriteOnly Property ImageAlign() As String
            Set(ByVal value As String)
                If GetBrowser() = "IE" Then
                    strImageAlign = "float:" & value & ";"
                Else
                    strImageAlign = " align=""" & value & """"
                End If
            End Set
        End Property
        
        'OnInit
        Protected Overrides Sub OnInit(ByVal e As EventArgs)
            If Not Me.ID Is Nothing Then ID = "id=""" & Me.ID & """ "
            If GetBrowser() = "IE" Then
                pngImg.Text = "<span " & ID & strCssClass & "title=""" & strAlternateText & _
                """ style=""" & strStyle & strImageAlign & strWidth & strHeight & _
                "display:inline-block;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" & strimageUrl & _
                "', sizingMethod='scale');""></span>"
            Else
                pngImg.Text = "<img " & ID & strCssClass & "src=""" & strimageUrl & _
                """" & strImageAlign & " alt=""" & strAlternateText & """" & strHeight & _
                """" & strWidth & strStyle & " title=""" & strAlternateText & """>"
            End If
        End Sub
        
    </script>
    <asp:Literal runat="server" id="pngImg"></asp:Literal>
    RED. / Jag ser att WF bråkar med koden. Ta bort mellanrummet mellan AlphaImageLoa der
    Last edited by Travoni; 2005-10-17, 19:48.
    Qui rogat, non errat
Working...
X