×

lineargradientbrush s ie

lineargradientbrush(c# GDI+中LinearGradientBrush到底是如何什么样的笔刷)

admin admin 发表于2022-09-07 01:23:32 浏览164 评论0

抢沙发发表评论

本文目录

c# GDI+中LinearGradientBrush到底是如何什么样的笔刷


LinearGradientMode 枚举
.NET Framework 4
其他版本
此主题尚未评级 - 评价此主题
指定线性渐变的方向。
命名空间: System.Drawing.Drawing2D
程序集: System.Drawing(在 System.Drawing.dll 中)
语法
C#
C++
F#
VB
public enum LinearGradientMode
成员
成员名称
说明
Horizontal 指定从左到右的渐变。
Vertical 指定从上到下的渐变。
ForwardDiagonal 指定从左上到右下的渐变。
BackwardDiagonal 指定从右上到左下的渐变。
版本信息
.NET Framework
受以下版本支持:4、3.5、3.0、2.0、1.1、1.0
.NET Framework Client Profile
受以下版本支持:4、3.5 SP1
平台
Windows 7, Windows Vista SP1 或更高版本, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008(不支持服务器核心), Windows Server 2008 R2(支持 SP1 或更高版本的服务器核心), Windows Server 2003 SP2

C#用Grapic产生验证码图片


public class ValidateCode : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
this.CreateCheckCodeImage(GenerateCheckCode());
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// 《summary》
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// 《/summary》
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private string GenerateCheckCode()
{
int number;
char code;
string checkCode = String.Empty;
System.Random random = new Random();
for(int i=0; i《5; i++)
{
number = random.Next();
if(number % 2 == 0)
code = (char)(’0’ + (char)(number % 10));
else
code = (char)(’A’ + (char)(number % 26));
checkCode += code.ToString();
}
Response.Cookies.Add(new HttpCookie(“CheckCode“, checkCode));
return checkCode;
}
private void CreateCheckCodeImage(string checkCode)
{
if(checkCode == null || checkCode.Trim() == String.Empty)
return;
System.Drawing.Bitmap image = new System.Drawing.Bitmap((int)Math.Ceiling((checkCode.Length * 12.5)), 22);
Graphics g = Graphics.FromImage(image);
try
{
//生成随机生成器
Random random = new Random();
//清空图片背景色
g.Clear(Color.White);
//画图片的背景噪音线
for(int i=0; i《25; i++)
{
int x1 = random.Next(image.Width);
int x2 = random.Next(image.Width);
int y1 = random.Next(image.Height);
int y2 = random.Next(image.Height);
g.DrawLine(new Pen(Color.Silver), x1, y1, x2, y2);
}
Font font = new System.Drawing.Font(“Arial“, 12, (System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic));
System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Blue, Color.DarkRed, 1.2f, true);
g.DrawString(checkCode, font, brush, 2, 2);
//画图片的前景噪音点
for(int i=0; i《100; i++)
{
int x = random.Next(image.Width);
int y = random.Next(image.Height);
image.SetPixel(x, y, Color.FromArgb(random.Next()));
}
//画图片的边框线
g.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width - 1, image.Height - 1);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
Response.ClearContent();
Response.C;
Response.BinaryWrite(ms.ToArray());
}
finally
{
g.Dispose();
image.Dispose();
}
}
}

假如以上验证码生成器页面名为:CheckCode.aspx,那么在登录页面中使用“《IMG》” 这个 HTML 元素来显示生成的验证码图片:《IMG src=“CheckCode.aspx“》
在登录页面的登录按钮的处理事件中使用以下代码判断验证码:
private void btnLogin_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
if(Request.Cookies[“CheckCode“] == null)
{
lblMessage.Text = “您的浏览器设置已被禁用 Cookies,您必须设置浏览器允许使用 Cookies 选项后才能使用本系统。“;
lblMessage.Visible = true;
return;
}
if(String.Compare(Request.Cookies[“CheckCode“].Value, txtCheckCode.Text, true) != 0)
{
lblMessage.Text = “验证码错误,请输入正确的验证码。“;
lblMessage.Visible = true;
return;
}
}
本文来自: 脚本之家(www.jb51.net) 详细出处参考:http://www.jb51.net/article/13634.htm

怎样在pdf文件中添加一个图章呢


首先我们需要了解一下什么是图章,都有什么作用?图章:图章对于校验PDF文档具有重要的意义,实现可以PDF文档审核、审批以及期限等标识。其实给PDF文件添加图章还是非常简单的,创建图章稍微比较复杂。接下来就进入正题了,教大家如何给PDF文件创建以及添加图章,希望能帮助大家。-ie

具体的操作步骤如下:

1、打开PDF编辑器软件,然后再打开我们需要进行编辑的PDF文档。

2、打开文档后,在左边的缩略图中找到需要添加图章的页面,然后选择“注释”菜单栏下的绘图工具中的“图章”。

3、然后选择一个图章,也可以选择”图章调板”新建一个属于自己的图章。

4、在跳转出来的”图章面板”中点击”创建”,然后选择图章的来源。

5、在添加新的图章页面中设置好页面范围、图章标题以及目标图章集等,然后点击确定。然后倒回到”注释”-”图章”中就能找到该图章并添加了。

希望可以帮到你,谢谢。


c#中怎样用shape显示由不同颜色组成的色条


Shape shape = new Rectangle();
shape.Width = 25;
shape.Height = 200;
var linearGradientBrush = new LinearGradientBrush();
linearGradientBrush.StartPoint = new Point(0.5, 0);
linearGradientBrush.EndPoint = new Point(0.5, 1);
var random = new Random();
for (int i = 0; i 《 100; i++)
{
    var color = new Color();
    color.A = byte.MaxValue;
    color.R = (byte)random.Next(0, byte.MaxValue + 1);
    color.G = (byte)random.Next(0, byte.MaxValue + 1);
    color.B = (byte)random.Next(0, byte.MaxValue + 1);
    var gradientStop = new GradientStop();
    gradientStop.Color = color;
    gradientStop.Offset = 0.01 * i;
    linearGradientBrush.GradientStops.Add(gradientStop);
}
shape.Fill = linearGradientBrush;
this.MainGrid.Children.Add(shape);

这样么?-s


题目要求是在c#中的combobox控件的下拉列表中添加图片我有代码,可是有错误,图片添加部分不


class PicComboBox : System.Windows.Forms.ComboBox
{
public PicComboBox()
{
//默认值设置
DrawMode = DrawMode.OwnerDrawFixed;
DropDownStyle = ComboBoxStyle.DropDownList;
ItemHeight = 50;
Width = 200;
}
protected override void OnDrawItem(DrawItemEventArgs e)
{
if (Items.Count == 0 || e.Index == -1) return;
if ((e.State & DrawItemState.Selected) != 0)
{
//选中项背景
LinearGradientBrush brush = new LinearGradientBrush(e.Bounds, Color.FromArgb(255, 251, 237), Color.FromArgb(255, 236, 181), LinearGradientMode.Vertical);
//LinearGradientBrush brush = new LinearGradientBrush(e.Bounds, Color.Red , Color.Blue , LinearGradientMode.Vertical);
Rectangle borderRect = new Rectangle(0, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height);
e.Graphics.FillRectangle(brush, borderRect);
Pen pen = new Pen(Color.FromArgb(229, 195, 101));
e.Graphics.DrawRectangle(pen, borderRect);
}
else
{
SolidBrush brush = new SolidBrush(Color.FromArgb(255, 255, 255));
e.Graphics.FillRectangle(brush, e.Bounds);
}
//绘制图片
PicItem item = (PicItem)Items[e.Index];
Image img = item.Image;
double newwidth = Convert.ToDouble(ItemHeight - 3) * img.Width / img.Height;//保持图片高宽比不变,并先满足高度
Rectangle imgRect = new Rectangle(2, e.Bounds.Y + 2, Convert.ToInt16(newwidth), e.Bounds.Height - 3);
e.Graphics.DrawImage(img, imgRect);
//绘制文本
Rectangle textRect = new Rectangle(imgRect.Right + 2, imgRect.Y, e.Bounds.Width - imgRect.Width, e.Bounds.Height - 3);
String itemText = Items[e.Index].ToString();
StringFormat strFormat = new StringFormat();
strFormat.LineAlignment = StringAlignment.Center;
e.Graphics.DrawString(itemText, Font, new SolidBrush(ForeColor), textRect, strFormat);
base.OnDrawItem(e);
}
/// 《summary》
/// 内部类,用于添加图片文本项
/// 《/summary》
public class PicItem
{
public PicItem(Image img, string text)
{
Text = text;
Image = img;
}
public string Text { get; set; }
public Image Image { get; set; }
public override string ToString()
{
return Text;
}
}
}
这是一个完整的可以添加图片的combox类,用法:
PicComboBox PCB = new PicComboBox();
PCB.Items.Add(new PicComboBox .PicItem(这里是图片,这里是文本)
其中文本可以为空
这是我自己写的、如果觉得外观不好看什么的可以自己修改上面的代码
-ie

c#中LinearGradientBrush 包不包含两个参数的构造函数


LinearGradientBrush() 初始化 LinearGradientBrush 类的新实例。
LinearGradientBrush(GradientStopCollection) 初始化 LinearGradientBrush 类的新实例,该实例具有指定的渐变停止点。
LinearGradientBrush(GradientStopCollection, Double) 初始化 LinearGradientBrush 类的一个新实例,该实例具有指定的 GradientStopCollection 和角度。
LinearGradientBrush(Color, Color, Double) 初始化 LinearGradientBrush 类的一个新实例,该实例具有指定的起始 Color、结束 Color 和角度。
LinearGradientBrush(GradientStopCollection, Point, Point) 初始化 LinearGradientBrush 类的一个新实例,该实例具有指定的渐变停止点、StartPoint 和 EndPoint。
LinearGradientBrush(Color, Color, Point, Point)
-s

c#中,用g.drawline画竖线从而实现从左到右颜色的渐变,应该怎么编程序啊


      //Form1的Paint事件处理 函数
      private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
             //渐变色:起点(0, 0)从红色 ---》终点(250, 250)蓝色
            LinearGradientBrush brush = new LinearGradientBrush(
                new Point(0, 0), new Point(250, 250),
                Color.Red, Color.Blue);
             Pen pen = new Pen(brush);
             //画线
            g.DrawLine(pen, 50, 50, 300, 50);
            
            pen.Dispose();
            brush.Dispose();
        }
-ie

wpf 如何将条纹对进度条进行填充,而不是拉伸


这种情况应该是填充的进度条的是有损图片资源 ,在填充后放大出现拉伸。

建议使用WPF上面的画刷 SolidColorBrush或Color进行对进度条填充,这些资源在WPF框架都是矢量的。无论你放大多少倍都不会失真。

下面是我自己用的一个ProgressBar模板,可以使用下面的模板或自己定义:

        《LinearGradientBrush x:Key=“WindowBackgroundBrush“ EndPoint=“0.5,1“ StartPoint=“0.5,0“》
            《GradientStop Color=“#FF4785B0“ Offset=“0“/》
            《GradientStop Color=“#FF63AADA“ Offset=“1“/》
        《/LinearGradientBrush》
        《Color x:Key=“PrimaryColor“》#FF63AADA《/Color》
        《Color x:Key=“SecondaryColor“》#FFA0FCFF《/Color》
        《SolidColorBrush x:Key=“PrimaryBrush“ Color=“{StaticResource PrimaryColor}“ /》
        《SolidColorBrush x:Key=“SecondaryBrush“ Color=“{DynamicResource SecondaryColor}“ /》
        《SolidColorBrush x:Key=“TextBrush“ Color=“#FF152937“ /》
        《Style x:Key=“{x:Type ProgressBar}“ TargetType=“{x:Type ProgressBar}“》
            《Setter Property=“Foreground“ Value=“{StaticResource TextBrush}“ /》
            《Setter Property=“Background“》
                《Setter.Value》
                    《LinearGradientBrush EndPoint=“0.5,1“ StartPoint=“0.5,0“》
                        《GradientStop Color=“#FFB4B4B4“ /》
                        《GradientStop Color=“#FFFFFFFF“ Offset=“1“ /》
                    《/LinearGradientBrush》
                《/Setter.Value》
            《/Setter》
            《Setter Property=“BorderThickness“ Value=“1“ /》
            《Setter Property=“Maximum“ Value=“100“ /》
            《Setter Property=“IsTabStop“ Value=“False“ /》
            《Setter Property=“BorderBrush“ Value=“{StaticResource PrimaryBrush}“ /》
            《Setter Property=“Template“》
                《Setter.Value》
                    《ControlTemplate TargetType=“{x:Type ProgressBar}“》
                        《Grid x:Name=“Root“ SnapsToDevicePixels=“True“》
                            《Grid.RowDefinitions》
                                《RowDefinition Height=“0.5*“ /》
                                《RowDefinition Height=“0.5*“ /》
                            《/Grid.RowDefinitions》
                            《Border CornerRadius=“4“ x:Name=“White“ BorderBrush=“#FFFFFFFF“ BorderThickness=“1“ Grid.RowSpan=“2“》
                                《Border.Background》
                                    《RadialGradientBrush》
                                        《RadialGradientBrush.RelativeTransform》
                                            《TransformGroup》
                                                《ScaleTransform CenterX=“0.5“ CenterY=“0.5“ ScaleX=“1.35“ ScaleY=“1.35“ /》
                                            《/TransformGroup》
                                        《/RadialGradientBrush.RelativeTransform》
                                        《GradientStop Color=“#FFFFFFFF“ Offset=“0“ /》
                                        《GradientStop Color=“#FFFFFFFF“ Offset=“1“ /》
                                    《/RadialGradientBrush》
                                《/Border.Background》
                            《/Border》
                            《Border x:Name=“PART_Track“ BorderBrush=“{TemplateBinding BorderBrush}“ BorderThickness=“1“ CornerRadius=“4,4,4,4“ Grid.RowSpan=“2“ Opacity=“0.65“ /》
                            《Grid x:Name=“ProgressBarRootGrid“ Grid.RowSpan=“2“》
                                《Rectangle x:Name=“ProgressBarRootGradient“ Canvas.ZIndex=“1“ Stroke=“#FFFFFFFF“ StrokeThickness=“1“ RadiusX=“4“ RadiusY=“4“ Opacity=“0.65“》
                                    《Rectangle.Fill》
                                        《LinearGradientBrush EndPoint=“0.7,1.263“ StartPoint=“0.699999988079071,0“》
                                            《GradientStop Color=“{StaticResource PrimaryColor}“ Offset=“0.312“ /》
                                            《GradientStop Color=“{StaticResource SecondaryColor}“ Offset=“1“ /》
                                        《/LinearGradientBrush》
                                    《/Rectangle.Fill》
                                《/Rectangle》
                                《Grid x:Name=“IndeterminateRoot“ Visibility=“Collapsed“》
                                    《Rectangle Margin=“{TemplateBinding BorderThickness}“ x:Name=“IndeterminateSolidFill“ Opacity=“1“ RenderTransformOrigin=“0.5,0.5“ Fill=“{TemplateBinding Foreground}“ Stroke=“#FF448DCA“ StrokeThickness=“0“ RadiusX=“4“ RadiusY=“4“ /》
                                    《Rectangle Margin=“{TemplateBinding BorderThickness}“ x:Name=“IndeterminateGradientFill“ Opacity=“0.7“ StrokeThickness=“1“ RadiusX=“4“ RadiusY=“4“》
                                        《Rectangle.Fill》
                                            《LinearGradientBrush MappingMode=“Absolute“ SpreadMethod=“Repeat“ EndPoint=“0,1“ StartPoint=“20,1“》
                                                《LinearGradientBrush.Transform》
                                                    《TransformGroup》
                                                        《TranslateTransform X=“0“ /》
                                                        《SkewTransform AngleX=“-30“ /》
                                                    《/TransformGroup》
                                                《/LinearGradientBrush.Transform》
                                                《GradientStop Color=“#FFFFFFFF“ Offset=“0“ /》
                                                《GradientStop Color=“#00FFFFFF“ Offset=“.25“ /》
                                                《GradientStop Color=“#FFFFFFFF“ Offset=“0.85“ /》
                                            《/LinearGradientBrush》
                                        《/Rectangle.Fill》
                                    《/Rectangle》
                                《/Grid》
                                《Grid Margin=“1“ x:Name=“DeterminateRoot“》
                                    《Rectangle HorizontalAlignment=“Left“ Margin=“2“ x:Name=“PART_Indicator“ StrokeThickness=“0.5“ RadiusX=“4“ RadiusY=“4“ Fill=“{StaticResource PrimaryBrush}“ /》
                                《/Grid》
                            《/Grid》
                            《Border BorderBrush=“#ccFFFFFF“ BorderThickness=“1“ CornerRadius=“3.5“ x:Name=“InnerBorder“ Margin=“2“ Grid.RowSpan=“2“ /》
                            《Border CornerRadius=“3.5“ x:Name=“Shadow“ Margin=“2“ Opacity=“0.2“ Grid.RowSpan=“2“》
                                《Border.OpacityMask》
                                    《RadialGradientBrush》
                                        《RadialGradientBrush.RelativeTransform》
                                            《TransformGroup》
                                                《TranslateTransform X=“0“ Y=“-0.5“ /》
                                            《/TransformGroup》
                                        《/RadialGradientBrush.RelativeTransform》
                                        《GradientStop Color=“#00FFFFFF“ Offset=“0.3“ /》
                                        《GradientStop Color=“#FFFFFFFF“ Offset=“1“ /》
                                    《/RadialGradientBrush》
                                《/Border.OpacityMask》
                                《Border.Background》
                                    《RadialGradientBrush》
                                        《RadialGradientBrush.RelativeTransform》
                                            《TransformGroup》
                                                《ScaleTransform CenterX=“0.5“ CenterY=“0.5“ ScaleX=“1.75“ ScaleY=“2.25“ /》
                                                《TranslateTransform Y=“0.65“ /》
                                            《/TransformGroup》
                                        《/RadialGradientBrush.RelativeTransform》
                                        《GradientStop Color=“#00000000“ Offset=“0.55“ /》
                                        《GradientStop Color=“#4C000000“ Offset=“1“ /》
                                    《/RadialGradientBrush》
                                《/Border.Background》
                            《/Border》
                            《Border Margin=“1“ CornerRadius=“4,4,4,10“ x:Name=“Highlight“ Opacity=“0.8“ RenderTransformOrigin=“0.5,1“》
                                《Border.Background》
                                    《RadialGradientBrush》
                                        《RadialGradientBrush.RelativeTransform》
                                            《TransformGroup》
                                                《ScaleTransform CenterX=“0.5“ CenterY=“0.5“ ScaleX=“1.25“ ScaleY=“2“ /》
                                                《TranslateTransform Y=“-0.6“ /》
                                            《/TransformGroup》
                                        《/RadialGradientBrush.RelativeTransform》
                                        《GradientStop Color=“#BFFFFFFF“ Offset=“0“ /》
                                        《GradientStop Color=“#4CFFFFFF“ Offset=“1“ /》
                                    《/RadialGradientBrush》
                                《/Border.Background》
                            《/Border》
                        《/Grid》
                        《ControlTemplate.Triggers》
                            《Trigger Property=“IsIndeterminate“ Value=“True“》
                                《Trigger.EnterActions》
                                    《BeginStoryboard》
                                        《Storyboard RepeatBehavior=“Forever“》
                                            《DoubleAnimationUsingKeyFrames Storyboard.TargetName=“IndeterminateGradientFill“ Storyboard.TargetProperty=“(Shape.Fill).(LinearGradientBrush.Transform).(TransformGroup.Children).X“》
                                                《SplineDoubleKeyFrame KeyTime=“0“ Value=“0“ /》
                                                《SplineDoubleKeyFrame KeyTime=“00:00:.5“ Value=“20“ /》
                                            《/DoubleAnimationUsingKeyFrames》
                                        《/Storyboard》
                                    《/BeginStoryboard》
                                《/Trigger.EnterActions》
                                《Setter Property=“Visibility“ Value=“Visible“ TargetName=“IndeterminateRoot“ /》
                                《Setter Property=“Visibility“ Value=“Collapsed“ TargetName=“DeterminateRoot“ /》
                            《/Trigger》
                        《/ControlTemplate.Triggers》
                    《/ControlTemplate》
                《/Setter.Value》
            《/Setter》
        《/Style》

亲测有效,运行效果:-s

这样,无论将ProgressBar怎样放大,进度条不会产生失真或拉伸的现象。


lineargradientbrush lingrbrush能定义成全局变量吗


void CTextDlg::OnPaint()
{
Graphics graphics(this-》m_hWnd);
LinearGradientBrush linGrBrush(
  Point(0,0),
  Point(200,0),
  Color(255,255,0,0),
  Color(255,0,0,255));
graphics.FillRectangle(&linGrBrush, 0, 0, 200, 200);
}

例2:
Graphics graphics(dc.GetSafeHdc());
graphics.Clear(Color::White);
//定义三种参与渐变的色彩
Color colors =
{
Color::Red, // 红色
Color::Green,//过渡色为绿色
Color::Blue // 蓝色
};
-ie

ASP.NET验证码制作


百度搜索
asp.net 验证码就出来了
image.aspx
加载事件里面:
using System.Xml.Linq;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
/// 《summary》
/// 加载事件
/// 《/summary》
/// 《param name=“sender“》《/param》
/// 《param name=“e“》《/param》
protected void Page_Load(object sender, EventArgs e)
{
string tmp = RndNum(6);
Session[“validation“] = tmp;
HttpCookie a = new HttpCookie(“ImageV “, tmp);
Response.Cookies.Add(a);
this.ValidateCode(tmp);
}
/// 《summary》
/// 生成验证图片
/// 《/summary》
/// 《param name=“VNum“》《/param》
private void ValidateCode(string checkCode)
{
if (checkCode == null || checkCode.Trim() == String.Empty)
return;
System.Drawing.Bitmap image = new System.Drawing.Bitmap((int)Math.Ceiling((checkCode.Length * 12.5)), 22);
Graphics g = Graphics.FromImage(image);
try
{
//生成随机生成器
Random random = new Random();
//清空图片背景色
g.Clear(Color.White);
//画图片的背景噪音线
for (int i = 0; i 《 2; i++)
{
int x1 = random.Next(image.Width);
int x2 = random.Next(image.Width);
int y1 = random.Next(image.Height);
int y2 = random.Next(image.Height);
g.DrawLine(new Pen(Color.Black), x1, y1, x2, y2);
}
Font font = new System.Drawing.Font(“Arial“, 12, (System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic));
System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Blue, Color.DarkRed, 1.2f, true);
g.DrawString(checkCode, font, brush, 2, 2);
//画图片的前景噪音点
for (int i = 0; i 《 100; i++)
{
int x = random.Next(image.Width);
int y = random.Next(image.Height);
image.SetPixel(x, y, Color.FromArgb(random.Next()));
}
//画图片的边框线
g.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width - 1, image.Height - 1);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.ContentType = “image/Gif“;
HttpContext.Current.Response.BinaryWrite(ms.ToArray());
}
finally
{
g.Dispose();
image.Dispose();
}
}
private string RndNum(int VcodeNum)
{
string Vchar= “0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p “+
“,q,r,s,t,u,v,w,x,y,z “;
string VcArray=Vchar.Split(new Char { ’,’});
string VNum= “ “;
int temp=-1;
Random rand=new Random();

for(int i=1;i 《VcodeNum+1;i++)
{
if(temp!=-1)
{
rand=new Random(i*temp*unchecked((int)DateTime.Now.Ticks));
}

int t=rand.Next(35);
if(temp!=-1&&temp==t)
{
return RndNum(VcodeNum);
}
temp=t;
VNum+=VcArray[t];
}
return VNum;
}
页面调用2方法:
string yanzhem =Convert.ToString(Session[“validation“]);
加载事件里面: chkImageButton.ImageUrl = “image.aspx “;
1.
《img src=“image.aspx“ alt=“验证码“ height=“20“ width=“90“ onclick=“this.src=this.src+’?’ /》
2.
《asp:ImageButton runat=“server“ ID=“ImageUrl=“image.aspx“ onclick=“this.src=this.src+’?’ /》
-s