🙂 İNSANLARIN EN HAYIRLISI INSANLARA FAYDALI OLANDIR 🙂

Ramazan HABER / C# / Windows Forms Marquee Label Horizontal kullanımı

1-) C# - Windows Forms Marquee Label Horizontal kullanımı

 

 

***** BASİT KOD *****

 

private void timerMarque_Tick(object sender, EventArgs e)

        {

             lblText.Text =

      lblText.Text.Substring(1) + lblText.Text.Substring(0, 1);

        }

 

 

***** DİĞER *****

 

kaynak : https://stackoverflow.com/questions/59029664/news-ticker-with-moving-text-from-left-to-right/59034753#59034753

 

 

 

1- EXTENSİON CLASS

 

 

using System;

using System.Drawing;

using System.Windows.Forms;

 

namespace RmosAcentex

{

    public class MarqueeLabel : Label

    {

        Timer timer;

        public MarqueeLabel()

        {

            DoubleBuffered = true;

            timer = new Timer() { Interval = 100 };

            timer.Enabled = true;

            timer.Tick += Timer_Tick;

        }

        int? left;

        int textWidth = 0;

        private void Timer_Tick(object sender, EventArgs e)

        {

            if (RightToLeft == RightToLeft.Yes)

            {

                left += 3;

                if (left > Width)

                    left = -textWidth;

            }

            else

            {

                left -= 3;

                if (left < -textWidth)

                    left = Width;

            }

            Invalidate();

        }

        protected override void OnPaint(PaintEventArgs e)

        {

            e.Graphics.Clear(BackColor);

            var s = TextRenderer.MeasureText(Text, Font, new Size(0, 0),

                TextFormatFlags.TextBoxControl | TextFormatFlags.SingleLine);

            textWidth = s.Width;

            if (!left.HasValue) left = Width;

            var format = TextFormatFlags.TextBoxControl | TextFormatFlags.SingleLine |

                TextFormatFlags.VerticalCenter;

            if (RightToLeft == RightToLeft.Yes)

            {

                format |= TextFormatFlags.RightToLeft;

                if (!left.HasValue) left = -textWidth;

            }

            TextRenderer.DrawText(e.Graphics, Text, Font,

                new Rectangle(left.Value, 0, textWidth, Height),

                ForeColor, BackColor, format);

        }

        protected override void Dispose(bool disposing)

        {

            if (disposing)

                timer.Dispose();

            base.Dispose(disposing);

        }

    }

}

 

 

 

 

2- KULLANIMI

 

 

    MarqueeLabel label = new MarqueeLabel();

    label.Text = "KAYAN YAZI";

    label.Dock = DockStyle.Fill;

    label.Font = new Font("Arial", 13, FontStyle.Bold);

    label.ForeColor = System.Drawing.Color.Red;

    panelControl1.Controls.Add(label);

                    

 

 

 

 2022 Aralık 30 Cuma
 437