| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 
 |  
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Text
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.IO
 
Imports System.Drawing
Imports Microsoft.VisualBasic
Imports System.Drawing.Drawing2D
 
<DefaultProperty("MyCode"), ToolboxData("<{0}:CaptchaControl runat=server></{0}:CaptchaControl>")> _
Public Class CaptchaControl
    Inherits WebControl
 
    Dim _MyCode As String = Nothing
 
    <Bindable(True), Category("Appearance"), DefaultValue(""), Localizable(True)> Property MyCode() As String
        Get
            If _MyCode = Nothing Then _MyCode = "Captach@"
            Return _MyCode
        End Get
 
        Set(ByVal Value As String)
            _MyCode = Value
        End Set
    End Property
 
    Protected Overrides Sub RenderContents(ByVal output As HtmlTextWriter)
 
        Dim MyImg As New Web.UI.HtmlControls.HtmlImage
        MyImg.Attributes.Add("TITLE", _MyCode)
        'MyImg.Attributes.Add("SRC", BuildMyImg)
        MyImg.RenderControl(output)
 
    End Sub
 
    Protected Function BuildMyImg() As System.IO.MemoryStream
 
        Dim memSt As New System.IO.MemoryStream
 
        Dim b As New Bitmap(150, 30, Imaging.PixelFormat.Format32bppArgb)
        Dim gr As Graphics = Graphics.FromImage(b)
        Dim str As String = MyCode
 
        Dim sizeff As SizeF = gr.MeasureString(str, New Font("Arial", 25, FontStyle.Strikeout, GraphicsUnit.Pixel), 300)
        Dim hatchBrush As HatchBrush = New HatchBrush(HatchStyle.Wave, Color.DarkBlue, Color.Gray)
        gr.FillRectangle(hatchBrush, New Rectangle(0, 0, 150, 30))
        gr.DrawString(str, New Font("Arial", 15, FontStyle.Strikeout, GraphicsUnit.Point), Brushes.White, 5, 5)
        b.Save(memSt, Drawing.Imaging.ImageFormat.Jpeg)
        b.Dispose()
 
        Return memSt
 
    End Function
End Class | 
Partager