想要以图形方式在表单上的屏幕上移动文本(没有文本框)?

时间:2013-12-22 03:29:38

标签: c#

我希望能够在屏幕顶部或任何起始位置移动文本字符串(以图形方式绘制)。我是图形的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);
        }
    }
}

0 个答案:

没有答案