如何制作光滑的圆形表格? [英] How to make a smooth round circle form?

查看:256
本文介绍了如何制作光滑的圆形表格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单,我通过以下代码进行了回合:

I have a form that I made round by the following code:

Private Sub DrawEllipse(ByVal sender As Object, ByVal e As PaintEventArgs) Handles MyBase.Paint
        'Me.BackColor = Color.Red
        Dim gp As New Drawing2D.GraphicsPath
        Dim top As Integer = SystemInformation.SizingBorderWidth + 1 + SystemInformation.CaptionHeight
        Dim left As Integer = SystemInformation.SizingBorderWidth + 1
        gp.AddEllipse(New Rectangle(left, top, Me.ClientSize.Width, Me.ClientSize.Height))
        Me.Region = New Region(gp)

        e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
        Using Pen1 As New Pen(Brushes.Blue, 20)
            e.Graphics.DrawEllipse(Pen1, 1, 1, Me.ClientSize.Width, Me.ClientSize.Height)
        End Using
    End Sub



但是如果你试试这段代码,你会发现它没有光滑的圆圈,所以我希望它是一个完美的圆形圆形。

我怀疑的一件事是问题来自形式和边界(蓝色),所以让我们从制作形式一样顺畅。

怎么样?


But if you try this code, you will notice that it don't have a smooth circle,so I want it to be a perfect round circle form.
And just one thing that I suspect is that the problem is from the form, and the border(the blue one), so lets start by making the form as smooth.
So how?

推荐答案

这真的是一个问题。我不知道一个全面的解决方案,也不确定它是否存在。问题是:即使平滑模式(抗锯齿)确实对图形渲染起作用,它也不适用于表单区域。



我建议使用一种解决方法,但它不会那么简单。我的想法是将非矩形区域与透明度结合起来。真正的问题是 System.Windows.Forms 中的透明度支持很糟糕,所以你需要做一些具有限制功能的解决方法。这里解释了这个问题:

http://msdn.microsoft.com/en-us/library/system.windows.forms.form%28v=vs.110%29.aspx [ ^ ]。



因此,使用的技巧是:你使椭圆区域更大,并使统一的透明背景。在此背景之上,您可以绘制一个更小的更小的抗锯齿椭圆,它应该是不透明的。该内椭圆的边缘应位于透明区域内。与不透明但抗锯齿的内椭圆边缘混合应产生一些平滑效果。



-SA
This is really a problem. I don't know a comprehensive solution and not sure if it even exists. The problem is: even though the smoothing modes (antialiasing) does work on rendering of graphics, it is not applied to the form regions.

I would suggest one workaround though, but it is not going to be as simple. My idea is to combine a non-rectangular region with transparency. The real problem is that transparency support in System.Windows.Forms sucks, so you need to do some workaround, with limiting capabilities. The problem is explained here:
http://msdn.microsoft.com/en-us/library/system.windows.forms.form%28v=vs.110%29.aspx[^].

So, the trick to use is: you make your elliptic region a bit bigger, and make the uniform transparent background. On top of this background, you draw an anti-aliased ellipse of slighter smaller size, which should be non-transparent. The edges of this inner ellipse should be inside the transparent region. The blending with non-transparent but antialiased inner ellipse edges should produce some smoothing effect.

—SA


这篇关于如何制作光滑的圆形表格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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