我正在try 在WinForm应用程序中创建组件类椭圆形使得在www.example.com中没有响应

我在另一台电脑上试过了,还是一样

使其不响应并重新启动Visual Studio.密码有什么问题吗?请带我

谢谢

Imports System.ComponentModel
Imports System.Runtime.InteropServices

Public Class Ellipse
    Inherits Component

    <DllImport("gdi32.dll", EntryPoint:="CreateRoundRectRgn")>
    Private Shared Function CreateRoundRectRgn(ByVal nL As Integer, ByVal nT As Integer, ByVal nR As Integer, ByVal nB As Integer, ByVal nWidthEllipse As Integer, ByVal nHeightEllipse As Integer) As IntPtr
    End Function

    Private control As Control
    Private cornerRadius As Integer = 25
    Public Property TargetControl As Control
        Get
            Return control
        End Get
        Set(ByVal value As Control)
            control = value
            AddHandler control.SizeChanged, Sub(sender, eventArgs) control.Region = Region.FromHrgn(CreateRoundRectRgn(0, 0, control.Width, control.Height, cornerRadius, cornerRadius))
        End Set
    End Property
    Public Property CornerRedius As Integer
        Get
            Return CornerRedius
        End Get
        Set(ByVal value As Integer)
            CornerRedius = value
            If control IsNot Nothing Then
                control.Region = Region.FromHrgn(CreateRoundRectRgn(0, 0, control.Width, control.Height, cornerRadius, cornerRadius))
            End If
        End Set
    End Property
End Class

当我将corner radius值从0更改为25时,它变得没有响应,Visual Studio重新启动.

result not responding ellipse

推荐答案

我想我明白问题所在了.你有这个字段:

Private cornerRadius As Integer = 25

然后这个属性:

Public Property CornerRedius As Integer

注意第二种情况下的拼写错误.在你的属性设置器中,你有这个:

CornerRedius = value

每次设置属性时,您都设置了属性.这就是我在 comments 这个问题时提到的无限循环.VS标记为对我的警告,所以我假设它对你做了同样的事情,但你忽略了它.我还注意到你返回的是属性,而不是getter中的字段.这就解释了为什么你的财产是空白的设计器开始,而不是显示25,这让我困惑时,看你的视频.

显然,您打算设置字段而不是属性,但您可能根本没有注意到拼写错误.您似乎试图为字段和属性指定相同的名称,如果您没有拼写错误的属性名称,这将失败.大多数人会命名支持字段,以便它们易于识别,例如:

Private _cornerRadius As Integer = 25

Public Property CornerRadius As Integer
    Get
        Return _cornerRadius
    End Get
    Set(ByVal value As Integer)
        _cornerRadius = value

        If control IsNot Nothing Then
            control.Region = Region.FromHrgn(CreateRoundRectRgn(0, 0, control.Width, control.Height, _cornerRadius, _cornerRadius))
        End If
    End Set
End Property

如果你不喜欢使用前导下划线,你可以使用cornerRadiusValue来代替.

.net相关问答推荐

无法通过构建目标访问 dotnet 的环境变量

MassTransit RespondAsync 无法返回空值

为什么不能使用 null 作为 Dictionary 的键?

如何在没有抽象基类的情况下强制覆盖后代中的方法?

如何以编程方式判断类型是 struct 还是类?

如何在 C# 中打开 Excel 文件?

如何根据新的安全策略在 .Net 中发送邮箱?

如何使用反射在 .NET 中调用重载方法

如何制作通用类型转换函数

是否有 Linq 方法可以将单个项目添加到 IEnumerable

ReaderWriterLockSlim 什么时候比简单的锁更好?

让 String.Replace 只打整个单词的方法

判断 .NET 中的目录和文件写入权限

从 'System.Int32' 到 'System.Nullable`1[[System.Int32, mscorlib]] 的无效转换

如何以编程方式删除 WebClient 中的 2 个连接限制

嵌套的 Try/Catch 块是个坏主意吗?

Guid.Parse() 或 new Guid() - 有什么区别?

任何人都知道缺少枚举通用约束的好方法吗?

不签署 .NET 程序集有什么问题吗?

为什么 IList 不支持 AddRange