|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace test
 ...{
public partial class Form1 : Form
 ...{
public Form1()
 ...{
InitializeComponent();
}
private int textAlpha = 0;
private int textAlphaDelta = 4;
private int textAlphaMax = 251;
private void Form1_Paint(object sender, PaintEventArgs e)
 ...{
// 更改图形设置以绘制清晰的文本
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;

// 确定位于文本上方和下方的
// 线条的位置
float lineLeftX = Size.Width / 4;
float lineRightX = 3 * Size.Width / 4;
int lineVerticalBuffer = Size.Height / 50;
float lineTopY = Location.Y + lineVerticalBuffer;
float lineBottomY = Location.Y + Size.Height - lineVerticalBuffer;



// 绘制文章的文本
using (StringFormat textFormat = new StringFormat(StringFormatFlags.LineLimit))
 ...{
textFormat.Alignment = StringAlignment.Near;
textFormat.LineAlignment = StringAlignment.Near;
textFormat.Trimming = StringTrimming.EllipsisWord;
int textVerticalBuffer = 4 * lineVerticalBuffer;
//Rectangle textRect = new Rectangle(Location.X, Location.Y + textVerticalBuffer, Size.Width, Size.Height - (2 * textVerticalBuffer));
Rectangle textRect = new Rectangle(Location.X, textAlpha, Size.Width, Size.Height - (2 * textVerticalBuffer));
using (Brush textBrush = new SolidBrush(Color.FromArgb(textAlpha, ForeColor)))
 ...{
e.Graphics.DrawString("IT知道网itwis.com - 打造主流程序开发、网络应用、资源共享、电脑技术资讯站", this.Font, textBrush, textRect, textFormat);
}
}
}

private void timer1_Tick(object sender, EventArgs e)
 ...{

// 更改要绘制的文本的 alpha 值
// 逐步增加值,直至达到 textAlphaMax,然后再逐步减小值
// 当值重新为零时移动到下一文章
textAlpha += textAlphaDelta;
if (textAlpha >= textAlphaMax)
 ...{
textAlphaDelta *= -1;
}
else if (textAlpha <= 0)
 ...{
// FadingComplete(this, new EventArgs());
textAlpha = 0;
textAlphaDelta *= -1;
}
//label1.Text = textAlpha.ToString();
//label1.Refresh();
this.Refresh();
}

private void Form1_Load(object sender, EventArgs e)
 ...{
this.Height = 300;
this.Width = 600;
}
}
}
| |