一般來說
程序范例
圖表
圖表
圖表
我們的程序范例示范了三種動畫效果
運用之前「如何利用程序代碼動態存取組件信息」的技巧
{
AssemblyInfoClass myAssembly = new AssemblyInfoClass();
this
// 指派數組成員
arrImages[
arrImages[
arrImages[
arrImages[
}
圖表
如果您要使用 Visual C# 來制作「關於」對話框
private void AboutBox_Load(object sender
{
AssemblyInfoClass myAssembly = new AssemblyInfoClass();
labelProductName
labelVersion
labelCopyright
labelCompanyName
textBoxDescription
myAssembly
}
要顯示「關於」對話框
{
// 顯示關於對話框
AboutBox MyAboutBox = new AboutBox();
// 設定關於對話框的啟始位置
MyAboutBox
MyAboutBox
}
當用戶點選不同的選項按鈕時
private void RadioButtons_CheckedChanged(object sender
EventArgs e)
{
if(optWink
{
tmrAnimation
}
else if(optBall
{
tmrAnimation
}
else if(optText
{
tmrAnimation
}
OnResize(EventArgs
}
自訂函式 RadioButtons_CheckedChanged 會叫用 OnResize 函式來產生不同的圖形
protected override void OnResize(EventArgs ea)
{
if (optWink
{
Graphics grfx = CreateGraphics();
// 重繪窗體
this
}
else if (optBall
{
Graphics grfx = CreateGraphics();
grfx
double dblRadius = Math
intBallRadiusX = (int)(dblRadius * grfx
intBallRadiusY = (int)(dblRadius * grfx
intBallMoveX = (int)(Math
intBallMoveY = (int)(Math
intBitmapWidthMargin = intBallMoveX;
intBitmapHeightMargin = intBallMoveY;
intBallBitmapWidth =
intBallBitmapHeight =
bitmap = new Bitmap(intBallBitmapWidth
grfx = Graphics
grfx
// 繪制球形
grfx
intBallPositionX = (int)(ClientSize
intBallPositionY = (int)(ClientSize
}
else if (optText
{
Graphics grfx = CreateGraphics();
grfx
}
}
最後
{
// 眨眼效果
if(optWink
{
Graphics grfx = CreateGraphics();
// 將數組中之圖形繪制在畫面上
grfx
(ClientSize
(int)((ClientSize
arrImages[intCurrentImage]
intCurrentImage += j;
if(intCurrentImage ==
{
j =
}
else if(intCurrentImage ==
{
j =
}
}
else if(optBall
{
Graphics grfx = CreateGraphics();
// 將球繪制在畫面上
grfx
(int)(intBallPositionY
intBallBitmapWidth
// 移動球的位置
intBallPositionX += intBallMoveX;
intBallPositionY += intBallMoveY;
// 球碰到左右邊界
if(intBallPositionX + intBallRadiusX >= ClientSize
{
intBallMoveX =
SystemSounds
}
// 球碰到上下邊界
if(intBallPositionY + intBallRadiusY >= ClientSize
{
intBallMoveY =
SystemSounds
}
}
else if (optText
{
Graphics grfx = CreateGraphics();
// 設定文字的字型與大小
Font font = new Font(
// 設定要顯示的文字
string strText =
SizeF sizfText = new SizeF(grfx
// X坐標與Y坐標的配對
PointF ptfTextStart = new PointF((float)(ClientSize
(float)(ClientSize
PointF ptfGradientStart = new PointF(
PointF ptfGradientEnd = new PointF(intCurrentGradientShift
// 設定筆刷
LinearGradientBrush grBrush = new LinearGradientBrush(ptfGradientStart
// 將文字繪制在畫面上
grfx
// 以不同的坐標繪制文字
intCurrentGradientShift += intGradiantStep;
if (intCurrentGradientShift ==
{
intGradiantStep =
}
else if (intCurrentGradientShift ==
{
intGradiantStep =
}
}
}
From:http://tw.wingwit.com/Article/program/net/201311/13166.html