星期二, 8月 18, 2009

C# 表單配置分隔線(Separator Line)

剛好需要用到,google一下第一頁就有解答了,真扯XD

[原文內容如下]

Separator Line on Form [C#]

To simulate the line in Windows Forms use a Label control.

Set its Height to 2 pixels and BorderStyle to Fixed3D.

Thats all, see the example.

[C#]
// separator bevel line

label1.AutoSize = false;

label1.Height = 2;

label1.BorderStyle = BorderStyle.Fixed3D;
Reference:Separator Line on Form [C#]

Microsoft Visual Studio International Pack 1.0 SR1 版

Microsoft Visual Studio International Pack 1.0 SR1 版簡述

Visual Studio International Pack 中提供了一組類別庫以幫助 .NET 程式開發人員建立全球化的應用程式.
更新後的 SR1 版本則包括了功能修正後的日文 Kana 轉換類別庫以及日文 Yomi 自動完成類別庫.
其他的元件則沒有變動.

安裝完後記得將參考的DLL檔加入專案內:ChineseConverter.dll

using Microsoft.International.Converters.TraditionalChineseToSimplifiedConverter;
private string TraditionalToSimplifiedConverter(string SourceString, string Language)
{
string newString = string.Empty;
newString= ChineseConverter.Convert(SourceString, ChineseConversionDirection.TraditionalToSimplified);
return newString;
}

星期日, 8月 16, 2009

C# 實現Webclient保持Session的方法

最近使用webclient在實現非同步上傳的功能,
但server端由於會驗證session值是否已存在,
即存取 A.aspx 頁面後會產生一個session,
再存取 B.aspx 頁面後會驗證A.aspx產生的session,
而原本的webclient是沒有辦法保持session,
因此需要透過繼承webclient物件改寫其中的 GetWebRequest
並將需保持的session透過CookieContainer來保存,
即可實現。

namespace BigdControls
{
    public class HttpWebClient:WebClient
    {
        // Cookie 容器
        private CookieContainer cookieContainer;

        public HttpWebClient()
        {
            this.cookieContainer = new CookieContainer();
        }

        public HttpWebClient(CookieContainer cc)
        {
            this.cookieContainer = cc;
        }

        /// <summary>
        /// Cookie 容器
        /// </summary>
        public CookieContainer MyCookies
        {
            get { return this.cookieContainer; }
            set { this.cookieContainer = value; }
        }

        /// <summary>
        /// 覆寫web request方法,讓webclient能保持session
        /// </summary>
        /// <param name="address"></param>
        /// <returns></returns>
        protected override WebRequest GetWebRequest(Uri address)
        {
            //throw new Exception(); 
            WebRequest request ;
            request = base.GetWebRequest(address);
            //判斷是不是HttpWebRequest.只有HttpWebRequest才有此属性 
            if (request is HttpWebRequest)
            {
                HttpWebRequest httpRequest = request as HttpWebRequest;
                httpRequest.CookieContainer = this.cookieContainer;
            }
                return request;
            }
        }
}

Reference:
实现支持会话的WebClient

.Net Draw thumbnail using VB.Net

' called when the thumbnail needs to be drawn
Private Sub DrawItem(ByVal g As Graphics, ByVal index As Integer)
' get the item that needs to be drawn
Dim item As ListViewItem = Me.Items(index)

' init values used for drawing
Const size As Integer = ThumbnailSize.Large
Dim textHeight As Integer = Me.Font.Height

' calculate area to draw thumbnail, usually would center the vertical position
' but this moves the thumbnail down when the title contains a very long
' string, instead, center the horizontal position, but always draw
' the vertical position from a set amount from the top
Dim bounds As New Rectangle( _
item.Bounds.Left + (item.Bounds.Width - size) \ 2, _
item.Bounds.Top + 2, _
size, size)

Dim image As Bitmap
Try
' draw the thumbnail image
' could cache the thumbnail to be more efficient
Dim photo As Photo = DirectCast(item.Tag, Photo)
image = New Bitmap(photo.ThumbnailPath)
g.DrawImage(image, _
bounds.Left + (size - image.Width) \ 2, _
bounds.Top + (size - image.Height) \ 2, _
image.Width, image.Height)
Catch ex As Exception
' could not draw the thumbnail
Finally
If Not (image Is Nothing) Then image.Dispose()
End Try

' erase the thicker selected border
If Not item.Selected Then
g.DrawRectangle(_penBack, bounds)
End If

' border
g.DrawRectangle(DirectCast(IIf( _
item.Selected, _penSelected, _penFrame), Pen), bounds)

' title, calculate the area to draw the title
Dim rc As New RectangleF(bounds.Left, _
bounds.Bottom + 4, _
bounds.Width, textHeight + 1)

' draw the title, different background if selected or not
g.FillRectangle(DirectCast(IIf(item.Selected, _
_brushSelected, _brushBack), SolidBrush), rc)
g.DrawString(item.Text, Me.Font, Brushes.Black, rc, _format)
End Sub

其他你感興趣的文章

Related Posts with Thumbnails