绕过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.