Skip to main content
A newer version of this page is available. .
Tab

ASPxCaptcha.ChallengeImageCustomRender Event

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

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v22.1.dll

NuGet Package: DevExpress.Web

Declaration

public event ChallengeImageCustomRenderEventHandler ChallengeImageCustomRender

Event Data

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

Property Description
Code Gets the code generated within the challenge image of the ASPxCaptcha control.
Image Provides 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

This example demonstrates how the ChallengeImageCustomRender event of the ASPxCaptcha control can be used to implement a custom challenge image.

View Example

<dx:ASPxCaptcha ID="ASPxCaptcha1" runat="server" 
    OnChallengeImageCustomRender="ASPxCaptcha1_ChallengeImageCustomRender">
</dx:ASPxCaptcha>
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DevExpress.Web.ASPxEditors.Captcha;
using System.Drawing;

public partial class _Default : System.Web.UI.Page {
    protected void Page_Load(object sender, EventArgs e) {

    }
    protected void ASPxCaptcha1_ChallengeImageCustomRender(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();
        }
    }
}
See Also