ChallengeImageCustomRenderEventArgs.Code Property
Gets the code generated within the challenge image of the ASPxCaptcha control.
Namespace: DevExpress.Web.Captcha
Assembly: DevExpress.Web.v19.1.dll
Declaration
public string Code { get; }
Public ReadOnly Property Code As String
Property Value
Type |
Description |
String |
A string value that represents the code.
|
Example
This example demonstrates how the ChallengeImageCustomRender event of the ASPxCaptcha control can be used to implement a custom challenge image.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="DevExpress.Web.ASPxEditors.v10.1" Namespace="DevExpress.Web.ASPxEditors"
TagPrefix="dx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<dx:ASPxCaptcha ID="ASPxCaptcha1" runat="server" OnChallengeImageCustomRender="ASPxCaptcha1_ChallengeImageCustomRender">
</dx:ASPxCaptcha>
</div>
</form>
</body>
</html>
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();
}
}
}
Imports Microsoft.VisualBasic
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports DevExpress.Web.ASPxEditors.Captcha
Imports System.Drawing
Partial Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Protected Sub ASPxCaptcha1_ChallengeImageCustomRender(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
End Class
<%@ Page Language="vb" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<%@ Register Assembly="DevExpress.Web.ASPxEditors.v10.1" Namespace="DevExpress.Web.ASPxEditors"
TagPrefix="dx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<dx:ASPxCaptcha ID="ASPxCaptcha1" runat="server" OnChallengeImageCustomRender="ASPxCaptcha1_ChallengeImageCustomRender">
</dx:ASPxCaptcha>
</div>
</form>
</body>
</html>
See Also