画线 [英] drawing string

查看:74
本文介绍了画线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小程序
如你所见
眨眼太多
感谢您对此程序的任何帮助,因此它不会闪烁

i have a small program
like you can see
it blinks too much
thanks for any help for this program so it will not blink

using System;
using System.Drawing;
using System.Windows.Forms;

namespace FlowOutString
{
    public partial class frmFlow : Form
    {
        string FineString = " ";
        Graphics g;
        PointF thispoint;
        Font thisFont = new Font("Times New Roman", 100);
        SolidBrush thisbrush = new SolidBrush(Color.Red);

        public frmFlow()
        {
            InitializeComponent();
        }

        private void frmFlow_Load(object sender, EventArgs e)
        {
            g = this.CreateGraphics();
            timer1.Start();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            FineString = "(-: Smile :-)";
            timer1.Interval = 25;
            g.Clear(BackColor);
            g.DrawString(FineString, thisFont, thisbrush, getPoint());
        }
        protected PointF getPoint()
        {
            thispoint.X -= 5;

            if (thispoint.X <= 0)
            {
                thispoint.X = this.Width;
            }
            thispoint.Y = 180;
            return thispoint;
        }
    }
}

推荐答案

写道:​​

g = this.CreateGraphics();

g = this.CreateGraphics();



这是错误的代码.不要这样改为处理绘画事件




This is bad code. Don''t do it. Handle the paint event instead


写道:​​

g.Clear(BackColor);

g.Clear(BackColor);



这将擦除文本,这意味着它将绘制一个空白区域.因此,它会闪烁.

如果您处理绘画事件并在计时器中调用Invalidate()来触发它,则将有所帮助.您也可以打开双重缓冲.

this.SetStyle(

ControlStyles.AllPaintingInWmPaint |

ControlStyles.UserPaint |

ControlStyles.DoubleBuffer,true);


会做到的.

不确定该代码如何与CreateGraphics的糟糕用法一起使用,因此请首先解决该问题.



This wipes the text, which means that it draws a blank area. Therefore, it flickers.

If you handle the paint event and call Invalidate() in your timer to fire it, that will help. You can also turn on double buffering.

this.SetStyle(

ControlStyles.AllPaintingInWmPaint |

ControlStyles.UserPaint |

ControlStyles.DoubleBuffer,true);


Will do that.

Not sure how this code will play with the awful use of CreateGraphics, so fix that first.


这篇关于画线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆