在WINFORM里,(C#)怎么制作可以上下滚动的字幕。要必须带有格式的移动(字体的大小,颜色跟着移动),用户可以自己任意的输入文字,或导入文本。

解决方案 »

  1.   

    不是HTML里就有吗?我靠,I服里YOU!你也可以把这个控件做成一个自定义控件放到ASP.NEG的工具箱里!
      

  2.   

    namespace Screen_Saver
    {
     using System;
     using System.Drawing;
     using System.Collections;
     using System.ComponentModel;
     using System.Windows.Forms;
     using System.Data;
     /// <summary>
     /// http://riji.163.com/weblog/page/metababy
     /// </summary>
     public class ScreenSaver : System.Windows.Forms.Form
     {
      /// <summary>
      /// http://shop1471977.taobao.com
      /// </summary>
      private System.ComponentModel.Container components;
      private System.Windows.Forms.Timer timerSaver;
      private System.Windows.Forms.Label lblMarquee;  private int iSpeed = 2;
      private string strMarqueeText="花纯春撰写的屏幕保护程序";  private System.Drawing.Font fontMarquee = new System.Drawing.Font ("Arial", 20, 
       System.Drawing.FontStyle.Bold); //定义字体和加粗字体以及字的大小
      private Color colorMarquee = System.Drawing.Color.FromArgb(255,255,255); //字体颜色,这里为白色,可以随便改,试一下其他的颜色吧,RGB分别表示为红黄蓝,其取值从0~255,不同的组合,出现不同的颜色  private int iDistance=0;
      private int ixStart= 0;
      private int iyStart= 0;   public ScreenSaver()
      { 
       InitializeComponent();   lblMarquee.Font=fontMarquee;
       lblMarquee.ForeColor=colorMarquee; 
       Cursor.Hide(); 
      }  /// <summary>
      /// Clean up any resources being used.
      /// </summary>
      protected override void Dispose( bool disposing )
      {
       if( disposing )
       {
        if (components != null) 
        {
         components.Dispose();
        }
       }
       base.Dispose( disposing );
      }
      /// <summary>
      /// 花纯春撰写的 c# 屏幕保护程序
      /// 共同学习探讨C#,欢迎来我的BLOG:http://riji.163.com/weblog/page/metababy
      /// </summary>
      private void InitializeComponent()
      {
       System.Resources.ResourceManager resources = new System.Resources.ResourceManager (typeof
        (ScreenSaver));
       this.components = new System.ComponentModel.Container ();
       this.timerSaver = new System.Windows.Forms.Timer (this.components);
       this.lblMarquee = new System.Windows.Forms.Label ();   timerSaver.Interval = 1;
       timerSaver.Enabled = true;
       timerSaver.Tick += new System.EventHandler (this.timerSaver_Tick);
       lblMarquee.Location = new System.Drawing.Point (88, 0);
       lblMarquee.Size = new System.Drawing.Size (128, 48);
       lblMarquee.ForeColor = System.Drawing.Color.White;
       lblMarquee.TabIndex = 0;
       lblMarquee.Visible = false;
       this.MaximizeBox = false;
       this.StartPosition = FormStartPosition.Manual;
       this.AutoScaleBaseSize = new System.Drawing.Size (5, 13);
       
       this.KeyPreview = true;
       this.WindowState = FormWindowState.Maximized;   this.ShowInTaskbar = false;
       this.Icon = (System.Drawing.Icon) resources.GetObject ("$this.Icon");
       this.ControlBox = false;
       this.MinimizeBox = false;
       this.BackColor = System.Drawing.Color.Black;
       this.ClientSize = new System.Drawing.Size (300, 300);
       this.KeyDown += new System.Windows.Forms.KeyEventHandler (this.Form1_KeyDown);
       this.MouseDown += new System.Windows.Forms.MouseEventHandler (this.Form1_MouseDown);
       this.MouseMove += new System.Windows.Forms.MouseEventHandler (this.Form1_MouseMove);
       this.Controls.Add (this.lblMarquee);
      }  protected void timerSaver_Tick (object sender, System.EventArgs e)
      { 
       lblMarquee.Text=strMarqueeText; 
       lblMarquee.Height=lblMarquee.Font.Height; 
       lblMarquee.Width=lblMarquee.Text.Length*2*(int)lblMarquee.Font.Size;//注意,这里,因为用的是汉字,所以,要乘以2,如果,屏保显示的是英文,就可以不要乘2,一个汉字相当于两个半角英文。   PlayScreenSaver();
      }  private void PlayScreenSaver()
      {
       //得到屏幕工作区.
       System.Drawing.Rectangle ssWorkArea = System.Windows.Forms.Screen.GetWorkingArea(this);   lblMarquee.Location=new System.Drawing.Point(ssWorkArea.Width - iDistance,
        lblMarquee.Location.Y);   //如果当前是隐藏,则使文本再显示出来.
       lblMarquee.Visible=true;   // Increment the label distance based on the speed set by the user.
       iDistance += iSpeed;
       // 如果文本移出屏幕,那我们将其放到右边再跑一次.
       if (lblMarquee.Location.X <= -(lblMarquee.Width))
       {
        //复位距离.
        iDistance = 0;    //如果文本在顶部,则移到中间.
        if (lblMarquee.Location.Y == 0)
         lblMarquee.Location=new System.Drawing.Point(lblMarquee.Location.X,
          (ssWorkArea.Height / 2));     // 如果文本在中间则移到下面.
        else if(lblMarquee.Location.Y== ssWorkArea.Height /2)
         lblMarquee.Location=new System.Drawing.Point(lblMarquee.Location.X,ssWorkArea.Height - 
          lblMarquee.Height);
         //返回顶部.
        else
         lblMarquee.Location=new System.Drawing.Point(lblMarquee.Location.X,0);
       } 
      }  protected void Form1_MouseDown (object sender, System.Windows.Forms.MouseEventArgs e)
      {
       StopScreenSaver();
      }  protected void Form1_MouseMove (object sender, System.Windows.Forms.MouseEventArgs e)
      {
       // 记录鼠标当前位置.
       if (ixStart == 0 && iyStart == 0)
       {
        //传递鼠标当前位置(座标)给变量.
        ixStart = e.X;
        iyStart = e.Y;
        return;
       }
        // 屏保运行后,有鼠标动作吗? 如果有,则停止,退出
       else if (e.X != ixStart || e.Y != iyStart)
        StopScreenSaver();  }  private void StopScreenSaver()
      {
       Cursor.Show(); 
       timerSaver.Enabled=false;
       Application.Exit();
      }  protected void Form1_KeyDown (object sender, System.Windows.Forms.KeyEventArgs e)
      {
       StopScreenSaver(); 
      }  /// <summary>
      /// 程序运行起点.
      /// </summary>
      public static void Main(string[] args) 
      {
       if (args.Length==1)
       {
        //显示选项对对话框,在这里,你可以自定义想要的选项和功能,我只是演示一下,带不同参数的实现,下同
        if (args[0].Substring(0,2).Equals("/c"))
        {
         MessageBox.Show("不可用选项",
          "花纯春撰写 C# 屏幕保护程序",MessageBoxButtons.OK,MessageBoxIcon.Information); 
         Application.Exit();
        }
         //正常启动屏保.
        else if (args[0]=="/s") 
         Application.Run(new ScreenSaver());     //显示密码对话框
        else if (args[0]=="/a")
        {
         MessageBox.Show("这个屏保不支持密码","花纯春撰写 C# 屏幕保护程序",MessageBoxButtons.OK,MessageBoxIcon.Information);
         Application.Exit();
        }
       } 
        //其它的任何参数 --> 运行
       else 
        Application.Run(new ScreenSaver());
      } }
    }
     
      

  3.   

    http://blog.csdn.net/metababy/archive/2005/11/03/521481.aspx
      

  4.   

    谢谢 metababy(花纯春) ,但是你这个屏幕保护能满足我这个需求吗?
    比如有这样的文字要上下移动:
     |————————————————————————
     |            屏幕(字体40,颜色绿色)           |
     |     花纯春做的屏幕保护程序(字体20,颜色黑色)|
     | 。(下面还很多)|
     | (注:括号里的文字是注解,不显示)            |
     |————————————————————————
    这样也能在保持各行的格式情况下移动?
    还有:TO(天外来痴),我可能不比如懂,但是你也不要这样,大家都是学技术,都有先后和高低,何必呢。在说已经注明是在WINFORM下了,你那个HTML,ASP.NET什么的好象在WEBFORM下的吧
      

  5.   

    Label、TextBox、PictureBox...都可以用来做你说的东西