Back to Devexpress

ASPxCaptcha.ChallengeImageCustomRender Event

aspnet-devexpress-dot-web-dot-aspxcaptcha-b91bd9be.md

latest4.1 KB
Original Source

ASPxCaptcha.ChallengeImageCustomRender Event

Enables you to implement custom logic for rendering the ASPxCaptcha’s challenge image.

Namespace : DevExpress.Web

Assembly : DevExpress.Web.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
public event ChallengeImageCustomRenderEventHandler ChallengeImageCustomRender
vb
Public Event ChallengeImageCustomRender As ChallengeImageCustomRenderEventHandler

Event Data

The ChallengeImageCustomRender event's data class is ChallengeImageCustomRenderEventArgs. The following properties provide information specific to this event:

PropertyDescription
CodeGets the code generated within the challenge image of the ASPxCaptcha control.
ImageProvides access to a Bitmap object representing the ASPxCaptcha’s challenge image.

Remarks

The ChallengeImageCustomRender event occurs before each render of the challenge image.

The parameters of the event argument allow you to obtain the generated code (ChallengeImageCustomRenderEventArgs.Code) and draw a custom image (ChallengeImageCustomRenderEventArgs.Image).

Example

The example below demonstrates how to handle the ChallengeImageCustomRender event to implement a custom challenge image.

aspx
<dx:ASPxCaptcha ID="ASPxCaptcha1" runat="server" 
                OnChallengeImageCustomRender="OnChallengeImageCustomRender" />
csharp
protected void OnChallengeImageCustomRender(object sender, ChallengeImageCustomRenderEventArgs e) {
    using (Graphics graphics = Graphics.FromImage(e.Image)) {
        System.Drawing.Image backgroundImage = System.Drawing.Image.FromFile(Server.MapPath("~/pp.jpg"));
        graphics.DrawImage(backgroundImage, 0, 0, e.Image.Width, e.Image.Height);
        Font font = new Font("Times New Roman", 40.0f, FontStyle.Bold, GraphicsUnit.Pixel);
        graphics.DrawString(e.Code, font, Brushes.Red, new PointF(0.0f, 0.0f));
        graphics.Flush();
    }
}
vb
Protected Sub OnChallengeImageCustomRender(ByVal sender As Object, ByVal e As ChallengeImageCustomRenderEventArgs)
    Using graphics As Graphics = Graphics.FromImage(e.Image)
        Dim backgroundImage As System.Drawing.Image = System.Drawing.Image.FromFile(Server.MapPath("~/pp.jpg"))
        graphics.DrawImage(backgroundImage, 0, 0, e.Image.Width, e.Image.Height)
        Dim font As New Font("Times New Roman", 40.0f, FontStyle.Bold, GraphicsUnit.Pixel)
        graphics.DrawString(e.Code, font, Brushes.Red, New PointF(0.0f, 0.0f))
        graphics.Flush()
    End Using
End Sub

See Also

Captcha Control

ASPxCaptcha Class

ASPxCaptcha Members

DevExpress.Web Namespace