用程式碼產生圖片是很常用的需求,

這裡教你怎麼把版權宣告文字PRINT在圖片上,

再用IMG CONTROL把它抓出來, 然後不留垃圾在Server.

"Defautlt.aspx

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!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>
         <!– 用IMAGECONTROL把它抓出來 –>
         <asp:Image ID="Image1″ runat="server" ImageUrl="~/getImage.aspx" />
    </div>
    </form>
</body>
</html>

" getImage.aspx

Imports System.Drawing
Imports System.Drawing.Imaging

Partial Class getImage
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim s As String = "NewtonStudio"
       ‘若不要固定圖片路徑, 可以用querystring來抓.
       ’Dim bmpFile As String = Server.MapPath(Request.QueryString("id").ToString())
        Dim bmpFile As String = Server.MapPath("ADONETx.jpg")
        Dim img As System.Drawing.Image = System.Drawing.Image.FromFile(bmpFile)
        Dim g As Graphics = Graphics.FromImage(img)
        Dim f As New Font("Courier New", 10)
        Dim b As New SolidBrush(Color.Black)
        g.DrawString(s, f, b, 0, 0)
        img.Save(Response.OutputStream, ImageFormat.Jpeg)

        img.Dispose()
    End Sub
End Class

 

 

用.NET FRAMEWORK 2.0可以針對不同的語系去展示網頁.
而culture都是預設的zh-TW, en-US, 如果要自訂Culture呢? 方法如下, 使用Console 端做例子

Imports System.Globalization
Imports System.Threading

Module Module1

    Sub Main()

        CultureAndRegionInfoBuilder.Unregister("zh-TW-adams")

        Dim DemoBuilder As New CultureAndRegionInfoBuilder("zh-TW-adams", CultureAndRegionModifiers.None)

        Dim TWCulture As New CultureInfo("zh-TW")
        Dim TWRegion As New RegionInfo("zh-TW")
        DemoBuilder.LoadDataFromCultureInfo(TWCulture)
        DemoBuilder.LoadDataFromRegionInfo(TWRegion)

        Dim NumberInfo As New NumberFormatInfo()
        NumberInfo.CurrencySymbol = "##"
        NumberInfo.CurrencyDecimalDigits = "4″
        DemoBuilder.NumberFormat = NumberInfo

        Dim DateInfo As New DateTimeFormatInfo
        DateInfo.DateSeparator = "."
        DemoBuilder.GregorianDateTimeFormat = DateInfo

        DemoBuilder.Register()
        Thread.CurrentThread.CurrentCulture = New CultureInfo("zh-TW-adams")
        Thread.CurrentThread.CurrentCulture.NumberFormat = NumberInfo
        Thread.CurrentThread.CurrentCulture.DateTimeFormat = DateInfo
        Console.WriteLine("Culture: " & Thread.CurrentThread.CurrentCulture.Name)
        Console.WriteLine("DateTime: " & DateTime.Now.ToString)
        Console.WriteLine("Currency: " & 1000.ToString("c"))
        Console.Read()
    End Sub

End Module

不知道有沒有人像我一樣常常會去比較每個語言的差異性以及實用性,
有人跟我說Visual Basic很容易學, 比較快得到成就, 但他的發展空間有限.
也有人跟我說Visual C#很難學, 比較難得到成就, 但他可以做比較大的發展.
也有講師級的人說其實兩者可以做到的事情是一樣的.
最主要是看你比較喜歡甚麼..

既然Visual Studio 內兩種語言的CLASS是可以互相使用的,
那使用哪種語言就顯得沒那麼重要的了吧? 就完全看你個人的習慣囉…
但根據我的觀察, 似乎只要會其中一種, 另一種就比較容易上手吧~

這個網址列出了一些VB及C#語法的比較:

http://www.harding.edu/fmccown/vbnet_csharp_comparison.html

沒有說誰比誰好,
能夠幫你達成目的,解決方案的就是好物就對啦~

為了讓資料存取的速度加快, 我們可以設定CACHE把資料站存在伺服器的記憶體.\
如下:

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        Label1.Text = Now
    End Sub

    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        If Not IsNothing(Cache("data")) Then
            Label2.Text = Cache("data").ToString()
        Else
            Label2.Text = "不存在…"
        End If
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Cache.Insert("data", TextBox1.Text & " – " & Now, Nothing, Now.AddSeconds(10), System.Web.Caching.Cache.NoSlidingExpiration)
       
    End Sub

    Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Cache.Insert("data", TextBox1.Text & " – " & Now, Nothing, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(10))
    End Sub

    Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Cache.Insert("data", TextBox1.Text & " – " & Now, New CacheDependency(Server.MapPath("~/Mod05/Books.xml")))
    End Sub

    Protected Sub Button5_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Cache.Insert("data", TextBox1.Text & " – " & Now, Nothing, Now.AddSeconds(10), System.Web.Caching.Cache.NoSlidingExpiration, CacheItemPriority.Default, New CacheItemRemovedCallback(AddressOf RemovedCallback))
    End Sub
   
    ‘當cache 被移除的時候, 寫一個TXT檔在C:\
    Public Sub RemovedCallback(ByVal k As String, ByVal v As Object, ByVal r As CacheItemRemovedReason)
        Dim sw As New IO.StreamWriter("c:\2544\log.txt", True)
        sw.WriteLine("快取物件 " & k & " 已經移除, 原因是 : " & r.ToString)
        sw.Close()
    End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1″ runat="server">
    <div>
        Now =
        <asp:Label ID="Label1″ runat="server" Text="Label"></asp:Label><br />
        <br />
        Data :
        <asp:TextBox ID="TextBox1″ runat="server"></asp:TextBox>
        <asp:Button ID="Button1″ runat="server" Text="絕對過期" OnClick="Button1_Click" />
        <asp:Button ID="Button3″ runat="server" OnClick="Button3_Click" Text="相對過期" />
        <asp:Button ID="Button4″ runat="server" OnClick="Button4_Click" Text="相依檔案" />
        <asp:Button ID="Button5″ runat="server" OnClick="Button5_Click" Text="快取釋放回呼" /><br />
        <br />
        <br />
        <br />
        <br />
        <asp:Button ID="Button2″ runat="server" OnClick="Button2_Click" Text="取得快取資料" />
        <asp:Label ID="Label2″ runat="server" Text="Label"></asp:Label></div>
    </form>
</body>
</html>

快取 CACHE 功能:

使用WEBSERVER將網頁的內容一直存取在SERVER的記憶體內,
當有瀏覽者瀏覽該網頁時, 記憶體就會直接抓出來, 是效率提高.
CACHE也可以設定時數, 也就是規定幾分鐘之內才更新.
(而不會讓網頁一直停留在同一個狀態, 讓瀏覽者以為網站都不會更新)

詳細設定可參考以下網址:

http://www.ilovejackdaniels.com/php/caching-output-in-php/

 

UserControl是 .NET FRAMEWORK 2.0 非常好用的功能,
一旦物件建立之後, 包裝起來. 就可以重複使用.

testQuery.aspx

<%@ Page Language="VB" %>

<%@ Register Src="ucQueryCustomers.ascx" TagName="ucQueryCustomers" TagPrefix="uc1″ %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        UcQueryCustomers1.Visible = True
    End Sub

    ’3, 使用事件
    Protected Sub UcQueryCustomers1_Selected(ByVal sender As Object, ByVal e As System.EventArgs)
        TextBox1.Text = UcQueryCustomers1.CustomerID
        UcQueryCustomers1.Visible = False
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1″ runat="server">
    <div>
        訂單<br />
        <br />
        Customer ID :
        <asp:TextBox ID="TextBox1″ runat="server"></asp:TextBox>
        <asp:Button ID="Button1″ runat="server" OnClick="Button1_Click" Text="…" /><br />
        <br />
        <uc1:ucQueryCustomers ID="UcQueryCustomers1″ runat="server" Visible="false" OnSelected="UcQueryCustomers1_Selected" />
   
    </div>
    </form>
</body>
</html>

———

(User Control: UcQueryCustomers1.ascx)

———

<%@ Control Language="VB" ClassName="ucQueryCustomers" %>

<script runat="server">

    Public ReadOnly Property CustomerID() As String
        Get
            Return GridView1.SelectedValue
        End Get
    End Property
   
    ’1, 對外宣告事件
    Public Event Selected As EventHandler
   
    ’2, 在正確時間點觸發事件給外界
    Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        RaiseEvent Selected(sender, e)
    End Sub
</script>

<div>
    查詢 :
    <asp:TextBox ID="TextBox1″ runat="server"></asp:TextBox>
    <asp:Button ID="Button1″ runat="server" Text="查詢" /><br />
    <asp:GridView ID="GridView1″ runat="server" AllowPaging="True" AutoGenerateColumns="False"
        CellPadding="4″ DataKeyNames="CustomerID" DataSourceID="SqlDataSource1″ EmptyDataText="There are no data records to display."
        ForeColor="#333333″ GridLines="None" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
        <FooterStyle BackColor="#1C5E55″ Font-Bold="True" ForeColor="White" />
        <Columns>
            <asp:CommandField ShowSelectButton="True" />
            <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" ReadOnly="True" SortExpression="CustomerID" />
            <asp:BoundField DataField="ContactTitle" HeaderText="ContactTitle" SortExpression="ContactTitle" />
            <asp:BoundField DataField="CompanyName" HeaderText="CompanyName" SortExpression="CompanyName" />
            <asp:BoundField DataField="ContactName" HeaderText="ContactName" SortExpression="ContactName" />
        </Columns>
        <RowStyle BackColor="#E3EAEB" />
        <EditRowStyle BackColor="#7C6F57″ />
        <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333″ />
        <PagerStyle BackColor="#666666″ ForeColor="White" HorizontalAlign="Center" />
        <HeaderStyle BackColor="#1C5E55″ Font-Bold="True" ForeColor="White" />
        <AlternatingRowStyle BackColor="White" />
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1″ runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString1 %>"
        DeleteCommand="DELETE FROM [Customers] WHERE [CustomerID] = @CustomerID" InsertCommand="INSERT INTO [Customers] ([CustomerID], [ContactTitle], [CompanyName], [ContactName]) VALUES (@CustomerID, @ContactTitle, @CompanyName, @ContactName)"
        ProviderName="<%$ ConnectionStrings:NorthwindConnectionString1.ProviderName %>"
        SelectCommand="SELECT [CustomerID], [ContactTitle], [CompanyName], [ContactName] FROM [Customers] WHERE ([CompanyName] LIKE ‘%’ + @CompanyName + ‘%’)"
        UpdateCommand="UPDATE [Customers] SET [ContactTitle] = @ContactTitle, [CompanyName] = @CompanyName, [ContactName] = @ContactName WHERE [CustomerID] = @CustomerID">
        <DeleteParameters>
            <asp:Parameter Name="CustomerID" Type="String" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="ContactTitle" Type="String" />
            <asp:Parameter Name="CompanyName" Type="String" />
            <asp:Parameter Name="ContactName" Type="String" />
            <asp:Parameter Name="CustomerID" Type="String" />
        </UpdateParameters>
        <SelectParameters>
            <asp:ControlParameter ControlID="TextBox1″ Name="CompanyName" PropertyName="Text"
                Type="String" />
        </SelectParameters>
        <InsertParameters>
            <asp:Parameter Name="CustomerID" Type="String" />
            <asp:Parameter Name="ContactTitle" Type="String" />
            <asp:Parameter Name="CompanyName" Type="String" />
            <asp:Parameter Name="ContactName" Type="String" />
        </InsertParameters>
    </asp:SqlDataSource>
</div>

—————-

 

想擁有一套免費的Adobe Flex Builder 3 Pro嗎?
不用再辛苦去搜尋引擎找盜版的來使用,
也不必擔心程式用了60天就掛點..

Adobe 為了鼓勵學術界使用Adobe Flex Builder 3,
特別提供免費的授權序號, 讓您無後顧之憂!

下載步驟:
1. 先到Adobe 官方網站下載 Adobe Flex Builder 3 試用版 (60天)
2. 到 http://www.flexregistration.com/ 註冊您的EMAIL 及上傳一張學生證或在學證明
3. 大概過了一到二星期就會回覆您的EMAIL啦~

Cheers~

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Label1.Text = WebConfigurationManager.AppSettings(TextBox1.Text)
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        If Not Page.IsPostBack Then
            DropDownList1.DataSource = WebConfigurationManager.AppSettings.Keys
            DropDownList1.DataBind()
            TextBox2.Text = WebConfigurationManager.AppSettings(DropDownList1.SelectedValue)
        End If
    End Sub

    Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        TextBox2.Text = WebConfigurationManager.AppSettings(DropDownList1.SelectedValue)
    End Sub

    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        ’1, 寫入Runtimeg設定
        ‘WebConfigurationManager.AppSettings.Set(DropDownList1.SelectedValue, TextBox2.Text)
        ’2, 修改Web.config
        ’2-1, 開啟web.config
        Dim cfg As System.Configuration.Configuration = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath)
        ’2-2, 修改設定
        cfg.AppSettings.Settings(DropDownList1.SelectedValue).Value = TextBox2.Text
        ’2-3, 存檔
        cfg.Save()
    End Sub

    Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        ’1, 開啟web.config
        Dim cfg As System.Configuration.Configuration = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath)
        ’2, 取得appSettings設定區段
        Dim cs As ConfigurationSection = cfg.GetSection("appSettings")
        ’3, 判斷是否有加密過, 以決定加密或解密
        If cs.SectionInformation.IsProtected Then
            cs.SectionInformation.UnprotectSection()
            Response.Write("已解密…")
        Else
            cs.SectionInformation.ProtectSection("DataProtectionConfigurationProvider")
            Response.Write("已加密…")
        End If
        ’4, 存檔
        cfg.Save()
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1″ runat="server">
    <div>
        key :
        <asp:TextBox ID="TextBox1″ runat="server"></asp:TextBox>
        <asp:Button ID="Button1″ runat="server" OnClick="Button1_Click" Text="Get Value" />
        <asp:Label ID="Label1″ runat="server" Text="Label"></asp:Label><br />
        <br />
        <br />
        keys :
        <asp:DropDownList ID="DropDownList1″ runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
        </asp:DropDownList>
        <asp:TextBox ID="TextBox2″ runat="server"></asp:TextBox>
        <asp:Button ID="Button2″ runat="server" Text="修改" OnClick="Button2_Click" />
        <asp:Button ID="Button3″ runat="server" OnClick="Button3_Click" Text="加密/解密" /></div>
    </form>
</body>
</html>