String with Mark in C#

Asked

Viewed 100 times

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, however I have two problems that should be simple, what I would like as soon as the words start to enter the left, they immediately appear on the right, as is the majority.

The code remains for further 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";
        }
    }
}

Result obtained so far: Ele funciona dessa forma

  • has some outline / q model you want ?

  • @Rovannlinhalis do not have a specific, I searched but did not find one that fits what I want, I found several that are equal or close to mine

  • @M.Marins For Marquee you get the effect, at a certain cost, using a same Timer... but this "phantom presentation" form I have no idea how you could do

  • @Leandroangelo I’m researching a lot, I found an effect called Ishittestvisible that has to be used in WPF, however I’m not able to use it outside, and to do what I did in WPF is not so simple, and I’m not sure if it gives...

  • I imagine something like this: https://www.quackit.com/html/codes/html_marquee_code.cfm but for windows Forms. but clarify "as soon as the words start to enter the left, they immediately appear on the right", in which position this would be on the screen ?!... where your current screen ?

  • @Rovannlinhalis I edited the publication to facilitate...

Show 1 more comment

1 answer

0

  • In your Form, set the following properties:

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

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

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

  • 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;
        }
    
    
    }
    

Utilizing:

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

Upshot: inserir a descrição da imagem aqui (soon I put an animation with the result)

I could not solve some "winks" that the text gives, with more time I try to solve.

  • unfortunately I could not deploy this model in mine, I made a new one and it worked well, but this wink ends up getting in the way too, which would be the part that makes it return?

  • @M.Marins the point is that I do not use a Label, if it were, should be 2, one for each side and control the position of both. I use the Graphics to write on the screen, and if the atualX is negative, the difference I write on the other side of the screen... The issue of blinking has how to solve, but I need to search a little

  • I tried to do this once, but I had problems because this message changes so the size ends up complicating, as I take a message from a txt it becomes very unpredictable.

  • the way I did, it calculates the position in real time, the only problem is if the message is bigger than the screen... then you have to decrease the source

  • Yes, it’s quite interesting that your code, but it’s not going to work for me, but you know something about my other question, of getting me to click on that track and achieve what’s behind it, I know that some companies have managed using a ghost-like effect, but I only managed to locate an event in WPF, but there I can not pass this project... If you know something like that..

Browser other questions tagged

You are not signed in. Login or sign up in order to post.