绕过System.Windows.Forms.Control的角落? [英] Rounding the corners of System.Windows.Forms.Control?

查看:71
本文介绍了绕过System.Windows.Forms.Control的角落?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我们如何才能将System.Windows.Forms.Control转入角落?当我们编写一个类并使用以下代码时:

Hi
How can we rounded the corner to System.Windows.Forms.Control? When We write a class And use this code:

Inherits System.Windows.Forms.Control





像这个样本:


http://up9.iranblog.com/images/b2xr3xtp4btdl093kf1y.jpg





Like this sample:


http://up9.iranblog.com/images/b2xr3xtp4btdl093kf1y.jpg

推荐答案

使用以下代码:
Imports System.Drawing.Drawing2D

Public Class UserControl1
    Private _radius As Int32 = 20
    Private _opacity As Int32 = 125
    Private _backColor As System.Drawing.Color = Color.Black

    Private Sub UserControl1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        Dim rect As Rectangle = Me.ClientRectangle
        rect.X = rect.X + 1
        rect.Y = rect.Y + 1
        rect.Width -= 2
        rect.Height -= 2
        Using bb As GraphicsPath = GetPath(rect, _radius)
            Using br As Brush = New SolidBrush(Color.FromArgb(_opacity, _backColor))
                e.Graphics.FillPath(br, bb)
            End Using
        End Using
    End Sub

    Protected Function GetPath(ByVal rc As Rectangle, ByVal r As Int32) As GraphicsPath
        Dim x As Int32 = rc.X, y As Int32 = rc.Y, w As Int32 = rc.Width, h As Int32 = rc.Height
        r = r << 1
        Dim path As GraphicsPath = New GraphicsPath()
        If r > 0 Then
            If (r > h) Then r = h
            If (r > w) Then r = w
            path.AddArc(x, y, r, r, 180, 90)
            path.AddArc(x + w - r, y, r, r, 270, 90)
            path.AddArc(x + w - r, y + h - r, r, r, 0, 90)
            path.AddArc(x, y + h - r, r, r, 90, 90)
            path.CloseFigure()
        Else
            path.AddRectangle(rc)
        End If
        Return path
    End Function
End Class


它创建了舍入的用户控件.希望对您有帮助.


It create Rounded User Control.I hope it will help you.


我以前从未做过,但是这些链接可能会对您有所帮助
c-sharp-how-to-add-round-corner- [ ^ ]
圆形按钮窗口形式为c# [ ^ ]
^ ]
我认为也许您应该考虑使用WPF应用程序,因为我相信所有这些对您而言都将容易完成.
Well I have never done this before but these links might help you
c-sharp-how-to-add-round-corner-to-button[^]
rounded button windows form c#[^]
My Google Search[^]
I think maybe you should look into doing a WPF app instead as I believe all this would be a lot easier to accomplish for you.


您必须使用(或创建)自定义控件. Google是您的朋友.
You have to use (or create) a custom control. Google is your friend.


这篇关于绕过System.Windows.Forms.Control的角落?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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