C# 要在窗体上以图形方式(无文本框)在屏幕上移动文本吗?

C# 要在窗体上以图形方式(无文本框)在屏幕上移动文本吗?,c#,C#,我希望能够在屏幕顶部或任何起始位置移动以图形方式绘制的文本字符串。我对图形的C方面还不熟悉。我知道onPaint必须被覆盖 我希望代码在屏幕上移动,所以我不确定是否需要使用计时器,我想应该是这样 使用的代码:所有图形 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; usin

我希望能够在屏幕顶部或任何起始位置移动以图形方式绘制的文本字符串。我对图形的C方面还不熟悉。我知道onPaint必须被覆盖

我希望代码在屏幕上移动,所以我不确定是否需要使用计时器,我想应该是这样

使用的代码:所有图形

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DDHBindingExcelSheet
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            Bitmap bitmap = new Bitmap(@"C:\Users\home-1\Desktop\Saved Data 07-12 Acorn\My Documents\Writings\My Pictures\book folder\More Pictures\hellsBellz5.jpg");
            e.Graphics.DrawImage(bitmap, 0, 0);

            System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Yellow);
            System.Drawing.Graphics frm;
            frm = this.CreateGraphics();
            frm.FillRectangle(myBrush, new Rectangle(50, 50, 150, 150));
            myBrush.Dispose();
            frm.Dispose();

            System.Drawing.Graphics fm = this.CreateGraphics();
            string drawString = "Sample Text";
            System.Drawing.Font drawFont = new System.Drawing.Font("Arial", 16);
            System.Drawing.SolidBrush drawBrush = new
                System.Drawing.SolidBrush(System.Drawing.Color.Black);
            float x = 150.0f;
            //float x = 150;
            float y = 10.0f;


            //Want to be able to graphically moved text across the top of the screen
            //so that it looks like a banner moving slowly across the screen.
            for (int index = 150; index < 300; index++)
            {
                fm.DrawString(drawString, drawFont, drawBrush, x, y);
                fm.DrawString("Cordinates For-Loop", drawFont, drawBrush, 10, 10);
            }

            drawFont.Dispose();
            drawBrush.Dispose();
            fm.Dispose();
            base.OnPaint(e);
        }
    }
}

如果不是强制使用WiFrm,您是否考虑进入WPF?它当然提供了一套更好的工具来处理这类应用。事实上,不,我过去没有使用过WPF。我试图尽可能多地学习C图形。我用Java做了一个完整的扑克游戏,所以我尝试用C做同样的事情。必须有一种方法在计时器或类似的东西上在屏幕上移动文本。我想用paintComponent在屏幕上移动文本