现在的位置: 首页 > 综合 > 正文

.net C# 改变VS2005中屏保,实现字幕滚动和字体消隐技术

2013年09月13日 ⁄ 综合 ⁄ 共 2808字 ⁄ 字号 评论关闭
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(
"//by 闫磊 Email:Landgis@126.com,yanleigis@21cn.com 2007.10.23"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;
        }


        
    }

}

 

抱歉!评论已关闭.