熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

在c#.net中畫帶陰影效果的文字

2022-06-13   來源: .NET編程 
<!StartFragment>using System;
using SystemDrawing;
using SystemDrawingText;
using SystemDrawingDrawingD;
using SystemCollections;
using SystemComponentModel;
using SystemWindowsForms;
using SystemData;

namespace WindowsApplication
{
/// <summary>
/// Form的摘要說明
/// </summary>
public class Form : SystemWindowsFormsForm
{
/// <summary>
/// 必需的設計器變量
/// </summary>

private SystemComponentModelContainer components = null;
private string TextToDraw =

public Form()
{
//
// Windows 窗體設計器支持所必需的
//

InitializeComponent();

// 在 InitializeComponent 調用後添加任何構造函數代碼

thisSetStyle(ControlStylesResizeRedrawtrue);

}


/// <summary>
/// 清理所有正在使用的資源
/// </summary>

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
componentsDispose();
}
}
baseDispose( disposing );
}


#region Windows Form Designer generated code
/// <summary>
/// 設計器支持所需的方法 不要使用代碼編輯器修改
/// 此方法的內容
/// </summary>
private void InitializeComponent()
{
//
// Form
//
thisAutoScaleBaseSize = new SystemDrawingSize( );
thisBackColor = SystemDrawingColorWhite;
thisClientSize = new SystemDrawingSize( );
thisFont = new SystemDrawingFont(Tahoma F
SystemDrawingFontStyleBold SystemDrawingGraphicsUnitPoint ((SystemByte)()));
thisName = Form;
thisText = Form;
thisPaint += new SystemWindowsFormsPaintEventHandler(thisForm_Paint);

}

#endregion


/// <summary>
/// 應用程序入口點
/// </summary>

[STAThread]
static void Main()
{
ApplicationRun(new Form());
}

protected override void OnPaintBackground(PaintEventArgs e)
{
LinearGradientBrush b = new LinearGradientBrush(thisClientRectangle
ColorBlueColorAliceBluef);
eGraphicsFillRectangle(bthisClientRectangle);
bDispose();
}

private void Form_Paint(object sender SystemWindowsFormsPaintEventArgs e)
{
// 創建一個小的Bitmap
Bitmap bm = new Bitmap(thisClientSizeWidth/thisClientSizeHeight/);

//得到 Graphics 對象
Graphics g = GraphicsFromImage(bm);

// 必須使用 antialiased rendering hint
gTextRenderingHint = TextRenderingHintAntiAlias;

//this matrix zooms the text out to / size and offsets it by a little right and down

Matrix mx = new Matrix(ff);

gTransform = mx;

// 畫陰影

gDrawString(TextToDrawFontnew SolidBrush( ColorFromArgb( ColorBlack))
StringFormatGenericTypographic );

gDispose();
eGraphicsInterpolationMode=InterpolationModeHighQualityBicubic;
eGraphicsTextRenderingHint=TextRenderingHintAntiAlias;
eGraphicsDrawImage(bmthisClientRectanglebmWidthbmHeightGraphicsUnitPixel);
eGraphicsDrawString(TextToDrawFontBrushesWhiteStringFormatGenericTypographic);
bmDispose();
}
}
}
From:http://tw.wingwit.com/Article/program/net/201311/11367.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.