使用paint事件进行循环进度条的运行时控制 [英] Using the paint event for run time control of a circular progress bar

查看:71
本文介绍了使用paint事件进行循环进度条的运行时控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



我确定这很简单,但是在我自己寻找正确答案后感到困惑之后我觉得最好问...... .... >


这就是我所拥有的:一个全屏应用程序,包含大量基于计时器的采样和值的图形显示,我想要一个圆形类型的进度条。我四处寻找并找到了一个非常简洁的解决方案(感谢Matt Wilko):



Hello,

Im sure this is simple, but after confusing myself searching around for the correct answer I thought it best to ask....

Here's what I have: A full screen app with lots of timer based sampling and graphical display of values alongside which I wanted a circular type progress bar. I searched around and found a really neat solution (thanks to Matt Wilko):

Private Sub DrawProgress(g As Graphics, rect As Rectangle, percentage As Single)
        'Draws the circular progress counter
        'work out the angles for each arc
        Dim progressAngle = CSng(360 / 100 * percentage)
        Dim remainderAngle = 360 - progressAngle

        'create pens to use for the arcs
        Using progressPen As New Pen(ThmVSEndColNormal, 4), remainderPen As New Pen(ThmTextColBody, 4)
            'set the smoothing to high quality for better output
            g.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
            'draw the arcs
            g.DrawArc(progressPen, rect, -90, progressAngle)
            g.DrawArc(remainderPen, rect, progressAngle - 90, remainderAngle)
        End Using

        'draw the text in the centre by working out how big it is and adjusting the co-ordinates accordingly
        Using fnt As New Font(Me.Font.FontFamily, 14)
            Dim text As String = percentage.ToString + "%"
            Dim textSize = g.MeasureString(text, fnt)
            Dim textPoint As New Point(CInt(rect.Left + (rect.Width / 2) - (textSize.Width / 2)), CInt(rect.Top + (rect.Height / 2) - (textSize.Height / 2)))
            'now we have all the values draw the text
            g.DrawString(text, fnt, Brushes.White, textPoint)
        End Using
    End Sub





在示例中,Matt调用Paint事件中的例程:





In the example Matt calls the routine in the Paint event thus:

DrawProgress(e.Graphics, New Rectangle(GrpControl.Left + 15, GrpControl.Top + ProgCountDown.Top, ProgCountDown.Height, ProgCountDown.Height), 40)





其中40是所需的值,这里静态但显然需要更改。



现在,我可以分配一个全局变量到我需要的百分比,将其发送到'DrawProgress'子,然后每次更改 的值时刷新或使表单无效,但整个屏幕和所有控件刷新导致令人讨厌的抖动。



我仍​​然在掌握.net,所以请原谅我缺乏理解,但我可以就如何妥善处理这个问题做一些建议。在我看来,我可能只需要使DrawProgress子中创建的图形对象无效,所以我不会强迫整个屏幕重新绘制。



最终我'我喜欢为这个圆形进度条制作控制类,因为它真的很整洁,我会用它很多但是那是另一天....



where 40 is the value required, its static here but obviously needs to change.

Now, I can assign a global variable to the percentage I need, send that off to the 'DrawProgress' sub and then refresh or invalidate the the form each time the value changes which does work, but the whole screen and all the controls refresh causing a nasty jitter.

I'm still getting to grips with .net so forgive my lack of understanding, but I could do with some advice on how to handle this properly. It seems to me that I perhaps need to invalidate just the graphics object created in the DrawProgress sub so Im not forcing the whole screen to re-paint.

Eventually I'd like to make control class for this circular progress bar as it's really neat and I'll use it a lot but that's for another day....

推荐答案

OK ...我搜索了一下,在这里找到了它: http://stackoverflow.com/questions/26928523/visual-basic-circular-progress-bar [ ^ ]



现在我明白了这个问题。

在这个建议中,进度条被绘制在一个表格上 - 我想你已经做了同样的事情。

你应该做的是:

创建一个类( - 文件)并命名。

这个类应该从控件继承。

现在在其中放置一个Property来为它提供可视化的百分比。

也许你想让控件 - 背景半透明 - 我们可以添加它。

覆盖它中的OnPaint-Method并像你的表单一样。

也许你必须修改Resize-Event因为你想拥有一个二次调整大小。



但实际上:现在你只使控件无效,而不是放置它的表格。
OK ... I searched a little around and found it here : http://stackoverflow.com/questions/26928523/visual-basic-circular-progress-bar[^]

Now I understand the Problem.
In this Suggestion the Progressbar ist painted on a Form - I think, you have done the same.
What you should do is :
Create a Class(-File) and name it.
This class should inherit from control.
Now place a Property in it to give it the percentage for the visualisation.
Perhaps you want to have the controls-Background translucent - we could add it.
Override the OnPaint-Method in it and do it like in your form.
Perhaps you must modify the Resize-Event because you want to have a quadratic resizing.

But in effect : now you invalidate only the control and not the Form on which it is placed.


这篇关于使用paint事件进行循环进度条的运行时控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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