0

我正在尝试找到一种在表单上的每个控件上使用UseCompatibleTextRendering属性的方法。但是,当我使用以下代码时,它似乎不是一个选项:

For Each ocontrol As Control In Form1.Controls
    ocontrol.UseCompatibleTextRendering = True
Next

ocontrol似乎没有该选项,但具有按钮的所有其他选项。如果我做Buttion1.UseCompatibleTextRendering = True那么它工作得很好。

任何帮助都会很棒!

4

1 回答 1

2

It is not a property of Control. Only Button, CheckListBox, GroupBox, Label, LinkLabel and PropertyGrid have the property. There's a good reason for that, only those controls display text that's rendered by Winforms instead of Windows.

Do consider that this property only exist to keep compatibility with apps that were started back in .NET 1.x. It is very unusual to want to fall back to GDI+ text drawing when you've got TextRenderer. Which renders text the same way as native Windows controls, like TextBox, ComboBox, ListView, TreeView, etc.

You'll want to set the application's default instead of setting it for every control. Project + Properties, Application tab, click the "View Application Events" button. Make the class look like this:

Partial Friend Class MyApplication
    Protected Overloads Shared ReadOnly Property UseCompatibleTextRendering() As Boolean
        Get
            Return True
        End Get
    End Property
End Class
于 2012-06-19T22:35:18.673 回答