Home > Blockchain >  Why does my form look so different after publish vs release?
Why does my form look so different after publish vs release?

Time:05-28

I've went to publish my first vb.net windows form and was surprised the format I meticulously combed over became all skewed after publishing.

See attached

Why did the controls change to older style '3d' and the overall ratio of the form stretched in the horizontal? My calendar date pickers also changed format.

Is there a way to make the published form look exactly like the release version, down to the pixel?

CodePudding user response:

You can control visual styles before you create your UI thread, but VB.Net will enable visual styles for you in Sub Main, which is inaccessible to you! You can get around this by creating your own Sub Main, but you also need to choose this new method as the entry point to your application.

' in a new class file, I called Program.vb
Public Module Program
    <STAThread>
    Public Sub Main()
        Application.VisualStyleState = VisualStyles.VisualStyleState.NonClientAreaEnabled
        Application.Run(New Form1())
    End Sub
End Module

In the project properties, click Startup object, choose Program

enter image description here

My Form1 has two TextBoxes. Here's the code

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.TextBox1.BorderStyle = BorderStyle.FixedSingle
        Me.TextBox2.BorderStyle = BorderStyle.Fixed3D
        Me.FormBorderStyle = FormBorderStyle.FixedSingle
    End Sub
End Class

and here is the result

enter image description here

Note with Application.EnableVisualStyles() instead, I'm getting all single borders.

enter image description here

Hope some setting of visual styles does the trick

CodePudding user response:

For anyone experiencing appearance issues, I can share that in my case, this seems to be related to my project starting first in visual studio 2019 and then I changed over VS 2022. I am happy to report that as soon as I copied my code over to a clean project in 2022, everything works great! The published copy looks completely identical to the release/debug version and I didn’t need to play with any settings in the Main Sub! Thank you djv for working with me!

  • Related