1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ニコ動のように文字が右から左に流れるだけの C#プログラム

Posted at

実行例
 c:> ScrlStr2.exe "あいうえお"

image.png

ScrlStr2.cs
//c:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe /target:winexe ScrlStr2.cs
using System;
using System.IO;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;
public partial class TransparentTextScroller
	: Form
{
	private Timer timer;
	private string textToScroll = "テスト/test";
	private int position;
	private int position_y;
	public TransparentTextScroller()
	{
		this.StartPosition = FormStartPosition.Manual;
		this.Location = new Point(0, 0);
		this.Width = Screen.PrimaryScreen.Bounds.Width;
		this.Height = Screen.PrimaryScreen.Bounds.Height;
		this.TopMost = true;
		this.FormBorderStyle = FormBorderStyle.None;
		this.BackColor = Color.DarkSlateBlue;
		this.TransparencyKey = Color.DarkSlateBlue;
		this.Font = new Font("Meiryo UI", 32, FontStyle.Bold);
		this.DoubleBuffered = true;
		position = this.Width;
		position_y = (new Random()).Next(10, Screen.PrimaryScreen.Bounds.Height- 100);
		timer = new Timer();
		timer.Interval = 50;
		timer.Tick += Timer_Tick;
		timer.Start();
	}
	public void setString(String s)
	{
		textToScroll = s;
	}
	private void Timer_Tick(object sender, EventArgs e)
	{
		position -= 12; // スクロールの速度
		if (position < -TextRenderer.MeasureText(textToScroll, this.Font).Width)
		{
			//position = this.Width;
			//position_y = (new Random()).Next(10, Screen.PrimaryScreen.Bounds.Height- 100);
			Environment.Exit(0);
		}
		this.Invalidate();
	}
	protected override void OnPaint(PaintEventArgs e)
	{
		base.OnPaint(e);
		Brush brush = new SolidBrush(Color.White);
		Graphics g = e.Graphics;
		g.SmoothingMode = SmoothingMode.None;
		StringFormat sf = new StringFormat();
		GraphicsPath path = new GraphicsPath();
		path.AddString(textToScroll, this.Font.FontFamily,
		 (int)this.Font.Style, this.Font.Size, new PointF(position, position_y), sf);
		Pen p = new Pen(Color.Black, 4.5f);
		p.LineJoin = LineJoin.Round;
		g.DrawPath(p, path);
		g.FillPath(Brushes.White, path);
		p.Dispose();
		path.Dispose();
	}
}
static class Program
{
	[STAThread]
	static void Main(string[] args)
	{
		Application.EnableVisualStyles();
		Application.SetCompatibleTextRenderingDefault(false);
		TransparentTextScroller tts = new TransparentTextScroller();
		tts.setString(args[0]);
		Application.Run(tts);
	}
}
1
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?