国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

使用 Visual C# .NET 向 Excel 工作簿傳輸數(shù)據(jù)

2024-07-10 12:55:47
字體:
供稿:網(wǎng)友

/* copyright all(c) 2005 zhongfeng, http://blog.csdn.net/sw515 */
 public class validatecode : system.web.ui.page
 {
  private void page_load(object sender, system.eventargs e)
  {
   this.createcheckcodeimage(generatecheckcode());
  }

  #region web 窗體設(shè)計器生成的代碼
  override protected void oninit(eventargs e)
  {
   //
   // codegen: 該調(diào)用是 asp.net web 窗體設(shè)計器所必需的。
   //
   initializecomponent();
   base.oninit(e);
  }
  
  /// <summary>
  /// 設(shè)計器支持所需的方法 - 不要使用代碼編輯器修改
  /// 此方法的內(nèi)容。
  /// </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.contenttype = "image/gif";
    response.binarywrite(ms.toarray());
   }
   finally
   {
    g.dispose();
    image.dispose();
   }
  }
 }




發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 博客| 淮安市| 岑巩县| 宁明县| 新野县| 娱乐| 丹巴县| 安乡县| 宁南县| 清水河县| 许昌市| 察隅县| 自贡市| 曲阳县| 咸阳市| 香格里拉县| 新闻| 化德县| 韩城市| 潞西市| 饶河县| 岳池县| 康定县| 岳阳市| 自治县| 历史| 清河县| 玉林市| 广南县| 安岳县| 青州市| 沂南县| 通化县| 巧家县| 南阳市| 凤冈县| 凤冈县| 喀喇沁旗| 苏尼特右旗| 东乡县| 杭锦后旗|