Frm_Main.cs
View Code
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Text;
7 using System.Windows.Forms;
8
9 namespace MoveFontInForm
10 {
11 public partial class Frm_Main : Form
12 {
13 public Frm_Main()
14 {
15 InitializeComponent();
16 }
17
18 private void timer1_Tick(object sender, EventArgs e)//用Timer来控制滚动速度
19 {
20 label1.Left -= 2;//设置label1左边缘与其容器的工作区左边缘之间的距离
21 if (label1.Right < 0)//当label1右边缘与其容器的工作区左边缘之间的距离小于0时
22 {
23 label1.Left = this.Width;//设置label1左边缘与其容器的工作区左边缘之间的距离为该窗体的宽度
24 }
25 }
26
27 private void button1_Click(object sender, EventArgs e)
28 {
29 timer1.Enabled = true;//开始滚动
30 }
31
32 private void button2_Click(object sender, EventArgs e)
33 {
34 timer1.Enabled = false;//停止滚动
35 }
36
37 private void button3_Click(object sender, EventArgs e)
38 {
39 this.Close();//关闭窗体
40 }
41 }
42 }
Frm_Main.designer.cs
View Code
1 namespace MoveFontInForm
2 {
3 partial class Frm_Main
4 {
5 /// <summary>
6 /// 必需的设计器变量。
7 /// </summary>
8 private System.ComponentModel.IContainer components = null;
9
10 /// <summary>
11 /// 清理所有正在使用的资源。
12 /// </summary>
13 /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
14 protected override void Dispose(bool disposing)
15 {
16 if (disposing && (components != null))
17 {
18 components.Dispose();
19 }
20 base.Dispose(disposing);
21 }
22
23 #region Windows 窗体设计器生成的代码
24
25 /// <summary>
26 /// 设计器支持所需的方法 - 不要
27 /// 使用代码编辑器修改此方法的内容。
28 /// </summary>
29 private void InitializeComponent()
30 {
31 this.components = new System.ComponentModel.Container();
32 this.button1 = new System.Windows.Forms.Button();
33 this.button2 = new System.Windows.Forms.Button();
34 this.button3 = new System.Windows.Forms.Button();
35 this.label1 = new System.Windows.Forms.Label();
36 this.timer1 = new System.Windows.Forms.Timer(this.components);
37 this.SuspendLayout();
38 //
39 // button1
40 //
41 this.button1.Location = new System.Drawing.Point(27, 125);
42 this.button1.Name = "button1";
43 this.button1.Size = new System.Drawing.Size(75, 23);
44 this.button1.TabIndex = 0;
45 this.button1.Text = "演示 ";
46 this.button1.UseVisualStyleBackColor = true;
47 this.button1.Click += new System.EventHandler(this.button1_Click);
48 //
49 // button2
50 //
51 this.button2.Location = new System.Drawing.Point(152, 125);
52 this.button2.Name = "button2";
53 this.button2.Size = new System.Drawing.Size(75, 23);
54 this.button2.TabIndex = 1;
55 this.button2.Text = "暂停";
56 this.button2.UseVisualStyleBackColor = true;
57 this.button2.Click += new System.EventHandler(this.button2_Click);
58 //
59 // button3
60 //
61 this.button3.Location = new System.Drawing.Point(280, 125);
62 this.button3.Name = "button3";
63 this.button3.Size = new System.Drawing.Size(75, 23);
64 this.button3.TabIndex = 2;
65 this.button3.Text = "退出";
66 this.button3.UseVisualStyleBackColor = true;
67 this.button3.Click += new System.EventHandler(this.button3_Click);
68 //
69 // label1
70 //
71 this.label1.AutoSize = true;
72 this.label1.BackColor = System.Drawing.Color.Transparent;
73 this.label1.Font = new System.Drawing.Font("宋体", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
74 this.label1.ForeColor = System.Drawing.Color.White;
75 this.label1.Location = new System.Drawing.Point(0, 56);
76 this.label1.Name = "label1";
77 this.label1.Size = new System.Drawing.Size(428, 21);
78 this.label1.TabIndex = 3;
79 this.label1.Text = "好消息:本店让利大酬宾,所有商品八折。";
80 //
81 // timer1
82 //
83 this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
84 //
85 // Form1
86 //
87 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
88 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
89 this.BackgroundImage = global::MoveFontInForm.Properties.Resources._05;
90 this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
91 this.ClientSize = new System.Drawing.Size(374, 189);
92 this.Controls.Add(this.label1);
93 this.Controls.Add(this.button3);
94 this.Controls.Add(this.button2);
95 this.Controls.Add(this.button1);
96 this.Name = "Form1";
97 this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
98 this.Text = "窗体中的滚动字幕";
99 this.ResumeLayout(false);
100 this.PerformLayout();
101
102 }
103
104 #endregion
105
106 private System.Windows.Forms.Button button1;
107 private System.Windows.Forms.Button button2;
108 private System.Windows.Forms.Button button3;
109 private System.Windows.Forms.Label label1;
110 private System.Windows.Forms.Timer timer1;
111 }
112 }
作者:墨明棋妙
出处:http://www.cnblogs.com/ynbt/
关于作者:专注于.Net、WCF和移动互联网开发。
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,如有问题,可以通过ynbt_wang@163.com联系我,非常感谢。 。
出处:http://www.cnblogs.com/ynbt/
关于作者:专注于.Net、WCF和移动互联网开发。
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,如有问题,可以通过ynbt_wang@163.com联系我,非常感谢。 。