My textboxes and labels are fine in design view, but when I switch over to Debug or Build, a couple of the textboxes are pushed together and the labels aren't in their original spots. Haven't seen this before and was wondering if anyone has any suggestions as to why and how to fix?

Dani AI

Generated

Quick, practical add-on to the thread (building on points from , and ). If resize handlers, anchors and parent/container settings are already checked, the usual WinForms causes to inspect next are: designer-localized resources, automatic runtime scaling, parent resizing/flow, and any code that runs after InitializeComponent.

Common root causes and what they do

  • Localizable = True: the designer moves many properties (Location, Size, Text, etc.) into the form’s .resx per‑language; the values in those resource entries are what the form uses at runtime for that culture.
  • AutoScale / DPI / font changes: AutoScaleMode (Font or Dpi) will scale positions/sizes at runtime if the designer’s scaling differs from the environment.
  • Parent/container or RightToLeft settings and anchor/dock combinations: a parent size change or layout policy can shift children at run time.
  • Hidden runtime code or designer-order issues can overwrite positions after InitializeComponent.

Quick checks and a runtime inspector
Add a small dump in Form.Load to see actual runtime positions (Output window). This recursively prints names, parents and locations so you can compare against the designer:

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    PrintPositions(Me, "")
End Sub

Private Sub PrintPositions(parent As Control, indent As String)
    For Each c As Control In parent.Controls
        Debug.WriteLine(indent & c.Name & ": Loc=" & c.Location.ToString() & ", Size=" & c.Size.ToString() & ", Parent=" & If(c.Parent Is Nothing, "None", c.Parent.Name))
        If c.HasChildren Then PrintPositions(c, indent & "  ")
    Next
End Sub

Practical fixes

  • Check the form’s Localizable property and the Language selector; if you don’t need localization set Localizable = False (or correct the Default-language positions).
  • If scaling causes jumps, try AutoScaleMode = None (or ensure design-time and runtime DPI/font are consistent).
  • For robust layouts use TableLayoutPanel/FlowLayoutPanel rather than absolute coordinates.
  • If you must edit .resx, back it up first; remove or correct the specific Location/Size entries and rebuild.
    Finally, recheck for any code that runs after InitializeComponent that could reposition controls (per ). These steps will narrow the cause and give a safe fix.

Recommended Answers

All 12 Replies

Do you have any code in the form's resize event or any code anywhere that changes their location?

Also, is the screen resolution any different when debugging/release?

No, there's no code in the form resize even and none that changes the location. And yes, the resolution is the same. The form was working great until I had to add one more textbox and label. No problems during design view, but as soon as I entered debug mode or checked the build, the boxes were pushed together and labels were moved away from on top of the textboxes. All textboxes and labels are anchored the same as well (top, left).

What form border style are you using?

I know I have had some issues when desinging in Sizable and then changing it to Fixed3D ect..

Are these controls placed inside another? ie. Panel, Groupbox ect..

I'm currently am using the Fixed 3d style and it hasn't changed. And no they are all inside the same panel. If it helps, I could add a screenshot to show what I am talking about.

Sure, if you don't mind.

Is AutoSize set to False for all Labels or any changes in FontSize ?

I've set the Autosize to both False and True for the labels and there has been no changes in fontsize. I've narrowed the problem down to JUST the labels as they keep getting shifted further to the right while in debug/build mode, compared to where they are in design view. I've also deleted the designer code, saved the program and restarted it while pasting the designer code back in to try and reset the contsruction with no luck.

Is there a way to view the location of these items while debug mode is displayed to see if it varies from design view?

Show us your Designer code of the form (whole code).
Its hard to tell what can be wrong, but for sure there is some "additional" code that changes position of controls.

Mitja - I sent you a pm with the designer code

Found the X,Y coordinates in the .resx part of the designer code, which is where the wrong coordinates were being displayed.

Iam glad you found it. I told you there has to be some code that does changes.
From now on you will know where to look if this kind of issue appears.
bye

commented: Good job Mitja! +5
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.