Home>
class test01: Form {
   protected override void OnPaint
                   (PaintEventArgs e) {
      Font f = new Font ("MS Gothic",
                        12);
 e.Graphice.DrawString
("Character 1", f, new SolidBrush (Color.
                        Black), 0,0);
("Character 2", f, new SolidBrush (Color.
                        Black), 0,20);
("Character 3", f, new SolidBrush (Color.
                        Black), 0,40);
}
public static void Main () {
    Application.Run (new test01);
}
}
Code

I found a way to scroll by c # side by search, but can't find a vertical scroll, please tell me how to write. I'm glad that it is as simple as possible.

I will supplement you in response.
I want to make
RPG's prologue-like character string flows vertically
I want to make it.
Now using Notepad in Windows
Window display with Application.Run,
I'm writing a prologue sentence in DrawString
It is about.
The environment is c # 5.0.
The horizontal telop was found in the search,
Since the flow direction is different, it is not used as a reference.

This is the explanation,
Was it a supplement?

  • Answer # 1

    Using Visual Studio is not as difficult as someone who can study programming can't understand.
    Learning to program with Notepad is quite inefficient, so learn how to use Visual Studio now.

    using System;
    using System.Drawing;
    using System.Windows.Forms;
    namespace WindowsFormsApp1
    {
        static class Program
        {
            ///<summary>
            /// The main entry point for the application.
            ///</summary>
            [STAThread]
            static void Main ()
            {
                Application.EnableVisualStyles ();
                Application.SetCompatibleTextRenderingDefault (false);
                Application.Run (new MainForm ());
            }
        }
        class MainForm: Form
        {
            public MainForm ()
            {
                var telop = new Telop
                {
                    Dock = DockStyle.Fill,
                    Font = new Font ("MS Gothic", 12),
                    Lines = new []
                    {
                        "Character 1", "Character 2", "Character 3"
                    }
                };
                Controls.Add (telop);
                telop.Run ();
            }
        }
        class Telop: Control
        {
            public string [] Lines {get;set;}
            public int Position {get;set;}
            public int LineHeight {get;set;} = 20;
            public void Run ()
            {
                Position = 0;
                Animator.Animate (1000, (frame, frequency) =>
                {
                    if (! Visible || IsDisposed) return false;
                    Position = frame * (Height + Lines.Length * LineHeight)/frequency;
                    Invalidate ();
                    return true;
                });
            }
            protected override void OnPaint (PaintEventArgs e)
            {
                base.OnPaint (e);
                var brush = new SolidBrush (ForeColor);
                for (int i = 0;i<Lines.Length;i ++)
                {
                    e.Graphics.DrawString (Lines [i], Font, brush, 0, Height-Position + i * LineHeight);
                }
            }
        }
        public static class Animator
        {
            ///<summary>
            /// Provide animation function by specifying the time and number of frames of one frame.
            ///</summary>
            ///<param name = "interval">1 Specifies the frame time in milliseconds.</param>
            ///<param name = "frequency">
            /// frequency is the number of times the callback is called minus 1. For example, when frequency is 10, it is called 11 times.
            ///</param>
            ///<param name = "callback">
            /// Specify a callback in the form of bool callback (int frame, int frequency).
            /// frame is incremented by 1 from 0 to the frequency value.
            /// frequency is the same as the argument.
            ///</param>
            public static void Animate (int interval, int frequency, Func<int, int, bool>callback)
            {
                var timer = new System.Windows.Forms.Timer ();
                timer.Interval = interval;
                int frame = 0;
                timer.Tick + = (sender, e) =>
                {
                    if (callback (frame, frequency) == false || frame>= frequency)
                    {
                        timer.Stop ();
                    }
                    frame ++;
                };
                timer.Start ();
            }
            ///<summary>
            /// Provide animation function by specifying duration.
            ///</summary>
            ///<param name = "duration">Specifies the duration in milliseconds.</param>
            ///<param name = "callback">
            /// Specify a callback in the form of bool callback (int frame, int frequency).
            /// frame is incremented by 1 from 0 to the frequency value.
            /// frequency is the number of times the callback is called minus 1. For example, when frequency is 10, it is called 11 times.
            ///</param>
            public static void Animate (int duration, Func<int, int, bool>callback)
            {
                const int interval = 25;
                if (duration<interval) duration = interval;
                Animate (25, duration/interval, callback);
            }
        }
    }

    Please refer to Animating Controls in Windows Forms for how to use Animator in the above source.

Related articles