VS2019中Visual Basic移除窗体默认边框后自定义关闭按钮报错求助
Hey there, let's tackle this error you're seeing. That "Property access must assign to the property or use its value" message usually pops up when the compiler thinks you're trying to access a property (not a method) — and here's why it's happening after removing the default form border:
Most likely, you've accidentally created a naming conflict with the Close method of the Form class. When you removed the default border and started building custom UI elements, you might've defined something (like a property, variable, or even a custom button named Close) that's overriding the built-in Close() method. The compiler now sees Me.Close as that property instead of the method to shut down the form.
Here's how to fix it:
1. Fix the naming conflict (recommended)
- Do a quick search in your form's code for any instances where you've declared something named
Close. For example, if you have a line likePublic Property Close As Booleanor a button accidentally named justClose, rename that item to something unique — likeIsClosePendingorbtnCustomClose. - Once you rename the conflicting member,
Me.Close()will work just like it did before, since the compiler will now reference the Form's built-in method again.
2. Explicitly call the base class method (if you don't want to rename)
If for some reason you need to keep the conflicting name, you can tell the compiler to use the base Form class's Close method directly:
MyBase.Close()
Drop that line into your custom close button's Click event, and it'll bypass any custom properties/variables named Close in your form.
Quick example of a working custom close button
Here's what your button click handler should look like once the conflict is fixed:
Private Sub btnCustomClose_Click(sender As Object, e As EventArgs) Handles btnCustomClose.Click ' This will properly close the form now Me.Close() ' Or use MyBase.Close() if you kept the conflicting name End Sub
Just double-check that your form's FormBorderStyle is set to None (you probably already did this, but it's worth confirming to ensure your custom UI behaves as expected).
内容的提问来源于stack exchange,提问作者Crann Moroney

