2009年5月23日星期六

AJAX Control Toolkit for ASP.NET 3.5 Service Pack 1 2009 年 5 月版已經發行

此次發行的 AJAX Control Toolkit 新增了 3 個擴充項與控制項:

  • ColorPicker
    在彈出式的對話方塊中,選取顏色。
  • ComboBox
    這個應該不用多解釋吧。
  • HTMLEditor
    提供兩種模式來編輯 HTML 內容,在設計模式中,就如同 Microsoft Word 這類的編輯器一樣,以所見即所得的方式進行編輯;在原始碼模式中,則直接編輯 HTML 語法。

下載點(請依需要,擇一下載):


章立民研究室

2009年5月20日星期三

Silverlight 2.0 教學影片

Silverlight 2.0 教學影片已經上傳至 MSDN,網址如下:

http://msdn.microsoft.com/zh-tw/dd756042.aspx

章立民研究室

2009年5月15日星期五

簡體書訊 - Silverlight 2.0 开发技术精粹.C#版

“Silverlight 2.0 开发技术精粹.C#版-(含1DVD价格)”已經出版,請參閱以下連結:

北京新华文化购书指南!

章立民研究室

2009年5月10日星期日

如何將多個圖檔組合成單一圖片

如何將多個圖檔組合成單一圖片呢?直接看程式碼吧。下面這一個方法能夠將外觀為數目字的四個圖片檔(.gif) 組合成單一圖片並以圖片資料流傳回,以便在登入畫面中做為圖文驗證的雜訊四碼數字,以防止大量張貼:

// GenerateImage 以圖檔產生驗證字圖形
//函數功能:    GenerateImage 以圖檔產生驗證文字圖形
//傳入參數:   
//            img_width        圖形寬度
//            img_height        圖形高度
//            confirm_str        驗證字串
//傳回數值:
//            MemoryStream    圖形資料
//備註說明:    本範例僅有 0 ~ 9 的數字圖檔,故驗證字串僅可輸入 0 ~ 9 的數字
public MemoryStream GenerateImage(int img_width, int img_height, string confirm_str)
{
    int wlen = 0, cnt = 0, tmpwidth, tmpheight;
    string tmpfile = "";

    // 取得網站存放圖檔的位置
    string gpath = HttpContext.Current.Request.MapPath("~/images/confirm/");

    // 取得字串長度
    wlen = confirm_str.Length;

    // 建立圖片元件
    Bitmap img_work = new System.Drawing.Bitmap(img_width, img_height);

    // 建立繪圖元件
    Graphics gh_work = Graphics.FromImage(img_work);

    // 擷取字串內容對應的圖檔,並填入 img_work 圖片物件
    for (cnt = 0; cnt < wlen; cnt++)
    {
        // 取得對應圖檔的名稱
        tmpfile = gpath + confirm_str.Substring(cnt, 1) + ".gif";

        // 根據檔案建立圖片物件。
        using (System.Drawing.Image img_tmp = System.Drawing.Image.FromFile(tmpfile, true))
        {
            tmpwidth = img_tmp.Width;
            tmpheight = img_tmp.Height;

            // 將圖形填入繪圖元件
            gh_work.DrawImage(img_tmp, new Rectangle(cnt * tmpwidth, 0, tmpwidth, tmpheight), 0, 0, tmpwidth, tmpheight, GraphicsUnit.Pixel);
        }
    }

    // 建立繪圖輸出資料流
    MemoryStream ms_work = new MemoryStream();

    //將圖片儲存到輸出資料流
    img_work.Save(ms_work, System.Drawing.Imaging.ImageFormat.Png);

    gh_work.Dispose();
    img_work.Dispose();

    return ms_work;
}

章立民研究室

本文節錄自 “ASP.NET 3.5 圖表與實務案例模組大全”一書

甚麼是 IIS 伺服器變數

IIS 伺服器變數能夠提供關於伺服器、用戶端之連結、以及連結上之作用請求的相關資訊。比方說,您可以使用 IIS 伺服器變數 REMOTE_ADDR (寫法:Request.ServerVariables["REMOTE_ADDR"] ) 去取得提出請求之來訪者的 IP。IIS 伺服器變數與環境變數並不相同,欲瞭解有哪些 IIS 變數可以使用以及它們的功用,請參閱 MSDN 說明 http://msdn.microsoft.com/en-us/library/ms524602.aspx

章立民研究室

2009年5月9日星期六

如何於泛型處理常式 .ashx 中存取工作階段變數(Session Variable)

要能夠在泛型處理常式中存取工作階段變數(Session Variable),其類別必須實作 System.Web.SessionState 命名空間中的 IRequiresSessionState 介面。如下所示者即是一例:

<%@ WebHandler Language="C#" Class="confirm" %>
//----------------------------------------------------------------------------
//程式功能    圖文驗證模組範例 - 產生圖型
//
//備註說明    需先產生 Session["confirm"]
//                    範例圖檔僅有 0 ~ 9 的圖型
//----------------------------------------------------------------------------
using System;
using System.Web;
using System.IO;
using System.Web.SessionState;

public class confirm : IHttpHandler, IRequiresSessionState
{
    public void ProcessRequest(HttpContext context)
    {
        MemoryStream gdata = new MemoryStream();
        BuildImage bd_img = new BuildImage();
        string mdata = "";

        mdata = context.Session["confirm"].ToString();

        // 取得驗證圖型的資料(設定驗證圖型尺寸及驗證字串)
        gdata = bd_img.GenerateImage(200, 54, mdata);

        // 設定輸出格式
        context.Response.ContentType = "image/png";

        // 送出資料內容
        context.Response.BinaryWrite(gdata.ToArray());
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}

最後提醒大家,於泛型處理常式 .ashx 中,請務必在 SessionRequest Response 之前均要加上 context. 才能使用。

章立民研究室

本文節錄自 “ASP.NET 3.5 圖表與實務案例模組大全”一書