C#实现文字移动

来源:互联网 发布:fc2最新域名 fc2cn.com 编辑:程序博客网 时间:2024/06/06 14:27

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

namespace label
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Point LPos;

        private void Form1_Load(object sender, EventArgs e)
        {
            LPos = new Point(this.label1.Location.X, this.label1.Location.Y);
            this.timer1.Start();
            DataClasses1DataContext db = new DataClasses1DataContext();
            List<DrugStock> DList = new List<DrugStock>();
            DList = (from c in db.DrugStock select c).ToList();
            if (DList != null && DList.Count > 0)
            {
                int i = 0;
                foreach (DrugStock DInfo in DList)
                {
                   
                        label1.Text = label1.Text + "/r/n" + DInfo.ProduceCode;
                   
                }
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            //if (label1.Location.Y< 0 && Math.Abs(label1.Location.Y) - label1.Height >= 0)
            //{
            //    label1.Location = new Point(panel1.Height, label1.Location.X);
            //    return;
            //}
            //label1.Location = new Point(label1.Location.Y, label1.Location.X);
            int FWidth = this.panel1.Width;
            int FHeight = this.panel1.Height;

            Point LPos1 = new Point(this.label1.Location.X, this.label1.Location.Y);
            if (LPos1.Y < FHeight)
            {
                this.label1.Location = new Point(LPos1.X, LPos1.Y- 2);
                if (LPos1.Y <= 0-FHeight)
                {
                    this.label1.Location = LPos;
                }
                return;
            }
            else
            {
                this.label1.Location = new Point(12,0);
            }

        }
        //#region Properties
        //[Category("Appearance"),
        //           Description("Label前景色")]
        //public System.Drawing.Color LabelForeColor
        //{
        //    get { return label1.ForeColor; }
        //    set { label1.ForeColor = value; }
        //}

 

        //[Category("Appearance"),
        //            Description("LabelText")]
        //public string LabelText
        //{
        //    get { return label1.Text; }
        //    set
        //    {

        //        label1.Text = value;
        //        if (value == "")
        //            timer1.Enabled = false;
        //        else timer1.Enabled = true;
        //    }
        //}
        //#endregion

    }
}

原创粉丝点击