Customizable Prompter (C# .NET 2008)

A basic prompter I made in order to help me do a video. Very useful when you don’t have time to learn a whole script and you need to shoot a video, and in other tricky situations. Text scrolls from bottom to top, at an adjustable speed.

You can find the source code below, and you can also download the full application for Windows.

Form1.cs

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 WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        int speed = 9;
        String text;

        String current_text;
        Label[] paragraphs = new Label[1000];

        int current_label = 0;

        int max_temp = 1;

        public void next_text()
        {
            int block_length = 150;
            current_text = "";

            int j = 0;
            while (j < text.Length)
            {
                if (text[j] == '\n')
                {
                    break;
                }
                j++;
            }

            block_length = j;

            if (block_length > 300) block_length = 300;

            for (int i = 0; i <= block_length; i++)
            {
                if (text.Length - 1 >= i) current_text += text[i]; 
            }

            String new_text = "";

            for (int i = (block_length+1); i < text.Length; i++)
            {
                new_text += text[i];
            }
            
            text = new_text;

            current_label++;

            paragraphs[current_label] = new Label();
            this.Controls.Add(paragraphs[current_label]);
            
            System.Drawing.Font myfont = new System.Drawing.Font(System.Drawing.FontFamily.GenericSerif,72);

            paragraphs[current_label].AutoSize = true;
            paragraphs[current_label].Text = current_text;
            paragraphs[current_label].Font = myfont;
            paragraphs[current_label].Visible = true;
            paragraphs[current_label].Left = 0;

            System.Drawing.Size mysize = new System.Drawing.Size(750, 10000);

            paragraphs[current_label].MaximumSize = mysize;


            paragraphs[current_label].Top = this.Height;
            paragraphs[current_label].BackColor = System.Drawing.Color.Transparent;
        }

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            MessageBox.Show("Please select a text file to display on the prompter");
            text = "";
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.Title = "Please select a text file to display on the prompter";
            openFileDialog1.Filter = "Text file|*.txt|Any file|*";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                text = System.IO.File.ReadAllText(openFileDialog1.FileName);
                this.Activate();
            }
            else
            {
                Application.Exit();
            }
        }

        private void Form1_Resize(object sender, EventArgs e)
        {

        }
        private void timer1_Tick_1(object sender, EventArgs e)
        {

            for (int i = max_temp; i <= current_label; i++)
            {
                if (paragraphs[i].Top + paragraphs[i].Height >= 0) paragraphs[i].Top -= speed;
                else max_temp = i;
            }
          if ((paragraphs[current_label].Top * -1) + this.Height > paragraphs[current_label].Height)
           {
               next_text();
           }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("After you click OK, the text will start scrolling in " + timer2.Interval.ToString() + " ms");
            button1.Visible = false;
            timer2.Enabled = true;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            next_text();
        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            speed--;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            speed++;
        }

        private void button4_Click(object sender, EventArgs e)
        {
            for (int i = 1; i <= current_label; i++) paragraphs[i].Dispose();
            text = System.IO.File.ReadAllText("c:\\scroll.txt");
            current_label = 0;
            next_text();
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            next_text();
            timer1.Enabled = true;
            timer2.Enabled = false;
        }

    }
}

Form1.Designer.cs

namespace WindowsFormsApplication1
{
    partial class Form1
    {
        /// <summary>
        /// Erforderliche Designervariable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Verwendete Ressourcen bereinigen.
        /// </summary>
        /// <param name="disposing">True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Vom Windows Form-Designer generierter Code

        /// <summary>
        /// Erforderliche Methode für die Designerunterstützung.
        /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.timer1 = new System.Windows.Forms.Timer(this.components);
            this.button1 = new System.Windows.Forms.Button();
            this.button2 = new System.Windows.Forms.Button();
            this.button3 = new System.Windows.Forms.Button();
            this.button4 = new System.Windows.Forms.Button();
            this.timer2 = new System.Windows.Forms.Timer(this.components);
            this.button5 = new System.Windows.Forms.Button();
            this.SuspendLayout();
            // 
            // timer1
            // 
            this.timer1.Interval = 50;
            this.timer1.Tick += new System.EventHandler(this.timer1_Tick_1);
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(393, 351);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(75, 23);
            this.button1.TabIndex = 1;
            this.button1.Text = "Start";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // button2
            // 
            this.button2.Location = new System.Drawing.Point(12, 12);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(75, 23);
            this.button2.TabIndex = 2;
            this.button2.Text = "-";
            this.button2.UseVisualStyleBackColor = true;
            this.button2.Click += new System.EventHandler(this.button2_Click_1);
            // 
            // button3
            // 
            this.button3.Location = new System.Drawing.Point(92, 12);
            this.button3.Name = "button3";
            this.button3.Size = new System.Drawing.Size(74, 23);
            this.button3.TabIndex = 3;
            this.button3.Text = "+";
            this.button3.UseVisualStyleBackColor = true;
            this.button3.Click += new System.EventHandler(this.button3_Click);
            // 
            // button4
            // 
            this.button4.Location = new System.Drawing.Point(172, 12);
            this.button4.Name = "button4";
            this.button4.Size = new System.Drawing.Size(75, 23);
            this.button4.TabIndex = 4;
            this.button4.Text = "reset";
            this.button4.UseVisualStyleBackColor = true;
            this.button4.Click += new System.EventHandler(this.button4_Click);
            // 
            // timer2
            // 
            this.timer2.Interval = 10000;
            this.timer2.Tick += new System.EventHandler(this.timer2_Tick);
            // 
            // button5
            // 
            this.button5.Location = new System.Drawing.Point(43, 200);
            this.button5.Name = "button5";
            this.button5.Size = new System.Drawing.Size(75, 23);
            this.button5.TabIndex = 5;
            this.button5.Text = "Look here";
            this.button5.UseVisualStyleBackColor = true;
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(800, 434);
            this.Controls.Add(this.button5);
            this.Controls.Add(this.button4);
            this.Controls.Add(this.button3);
            this.Controls.Add(this.button2);
            this.Controls.Add(this.button1);
            this.Name = "Form1";
            this.Text = "Prompter";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.Resize += new System.EventHandler(this.Form1_Resize);
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.Timer timer1;
        private System.Windows.Forms.Button button2;
        private System.Windows.Forms.Button button3;
        private System.Windows.Forms.Button button4;
        private System.Windows.Forms.Timer timer2;
        private System.Windows.Forms.Button button5;

    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close