Sequence of characters with Marquee in C #

0

I'm developing an application that passes some information to users who are running it. The main idea is to make an informative track, but I have two problems that should be simple, which I would like as soon as I start to enter the words on the left, they immediately appear on the right, as is the majority.

The code is for clarification.

using System;
using System.Collections.Generic;

using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {

            string text = System.IO.File.ReadAllText(@"\...\Texto de Exemplo.txt", Encoding.UTF7);

            label1.Text = text;

            label1.Left -= 7;

            if (label1.Left < 0 && (Math.Abs(label1.Left) > label1.Width))
            {
                label1.Left = this.Width;
            }

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            label1.Left = Screen.PrimaryScreen.Bounds.Width;
            timer1.Start();

            int c = Screen.PrimaryScreen.BitsPerPixel;
            int w = Screen.PrimaryScreen.Bounds.Width;
            int h = Screen.PrimaryScreen.Bounds.Height;

            int altura, largura;
            altura = h - 77;
            largura = w - 10;

            Width = largura;

            Top = altura;
            Left = 4;

            string f;
            f = "teste";
        }
    }
}

Results obtained so far:

    
asked by anonymous 28.06.2018 / 22:52

1 answer

0
  • On your Form, set the following properties:

    BackColor = 218; 255; 195;
    FormBorderStyle = None;
    Opacity = 70%;
    ShowInTaskbar = False;
    StartPosition = Manual;
    TopMost = True;
    Height = 50;
    
  

All of these options can be changed by the Properties window of Visual Studio.

  • Add a Timer (here called timer1) on the Form, and set the interval to 50 milliseconds. Create the Tick event.

  • Now, set the Form code to:

    public partial class FormMarquee : Form
    {
        public Font FonteCaption { get; set; } = new Font("Calibri", 16, FontStyle.Bold);
        public Color ColorCaption { get; set; } = Color.FromArgb(20, 74, 35);
        public int Interval { get { return timer1.Interval; } set { timer1.Interval = value; } }
        public string Caption { get; set; } = "Caption";
        int atualX;
        Graphics g;
    
        public FormMarquee()
        {
            InitializeComponent();
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            this.Width = Screen.PrimaryScreen.WorkingArea.Width;
            this.Location = new Point(0, Screen.PrimaryScreen.WorkingArea.Height - this.Height);
    
        }
    
        protected override void OnShown(EventArgs e)
        {
            base.OnShown(e);
    
            g = this.CreateGraphics();
    
            SizeF s = g.MeasureString(this.Caption, this.FonteCaption);
            atualX = (int)(this.Width - s.Width);
    
            timer1.Enabled = true;
        }
    
        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Enabled = false;
    
            g.Clear(this.BackColor);
    
            SizeF s = g.MeasureString(this.Caption, this.FonteCaption);
            int y = (int)((this.Height - s.Height) / 2);
            int startX = (int)(this.Width - s.Width);
            int limitX = (int)(s.Width * -1);
    
    
            g.DrawString(this.Caption, this.FonteCaption, new System.Drawing.SolidBrush(this.ColorCaption), new PointF(atualX, y));
    
            if (atualX < 0)
            {
                int x2 = this.Width + atualX;
                g.DrawString(this.Caption, this.FonteCaption, new System.Drawing.SolidBrush(this.ColorCaption), new PointF(x2, y));
            }
    
            atualX -= 10;
    
            if (atualX < limitX)
            {
                atualX = startX;
            }
    
            timer1.Enabled = true;
        }
    
    
    }
    
  

Usage:

private void button1_Click(object sender, EventArgs e)
{
    FormMarquee form = new FormMarquee();
    form.Caption = "<<- Exemplo Mensagem Marquee - Rodando... ";
    form.Show();
}
  

Result:      (soonI'llputananimationwiththeresult)

Icouldnotsolvesome"blinks" that the text gives, with more time I try to solve.

    
29.06.2018 / 20:16