Skip to content

Roslyn: What Button1.TextAlign property assignment will compile in VB.NET for WinForms? #81517

@jerrywa0h

Description

@jerrywa0h

Scenario:
You are working on a Visual Basic .NET Framework 4.8 application (Hello) and using Roslyn to compile dynamic source code into a standalone executable (Hello.exe) for Windows.

Problem:
When compiling controls property assignment statements with Roslyn, some lines compile successfully, while others do not. For example:

  • Button1.BackColor = System.Drawing.Color.LightBlue (COMPILES)
  • Button1.TextAlign = ContentAlignment.MiddleRight (DOES NOT COMPILE)

Question:
What is the correct Visual Basic statement for setting Button1.TextAlign so that Roslyn will compile it successfully?

Details:

  • The problematic line fails during Roslyn compilation.
  • ContentAlignment is referenced directly, as in the designer code, but does not compile dynamically.
  • Please clarify what statement or reference will work for setting the TextAlign property during runtime when compiling with Roslyn.

Context:

  • The goal is to dynamically compile source code for a Windows Forms application using Roslyn.
  • Some property assignments (BackColor, etc.) work; others (TextAlign) do not.

Request:

  • Provide the correct syntax or approach to assign Button1.TextAlign in code that Roslyn will compile successfully.
  • If there are references or import statements required, please specify.
  • Any alternate solutions or workarounds are appreciated.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions