0

I noticed that after upgrading my software from .NET 4 to 4.8 all of my ShowDialogs send the new form to the primary display rather than keeping it on top of the previous form. It almost seems as if the parent form was assumed in previous versions of the framework? All of the googling I have done is telling me to use ShowDialog(this) to set a parent form but as far as I can tell that sets the forms Owner, not parent.

Dim dlg As dlgCheckUser = New dlgCheckUser(seckey)
Dim dr As DialogResult = dlg.ShowDialog
If dr = DialogResult.No Then
  MessageForm.ShowMessageByKey("msg_passcodeFail_OK")
End If
dlg.Dispose()

I tried going through the code and passing a reference all the way down to where it does the ShowDialog but ShowDialog(this) is setting the form owner and there is no "CenterToOwner" method to use in the form_load. I went back and downgraded to .NET 4, changing nothing else and it works perfectly. The dialog form opens right on top of the previous form like it did previously.

LarsTech
  • 80,625
  • 14
  • 153
  • 225
Migals
  • 1
  • 2
  • Set a breakpoint on this code. When it hits, use Debug > Windows > Threads. You need to make sure that code runs on the main thread. – Hans Passant Apr 26 '23 at 13:42
  • @HansPassant I checked both on 4 and 4.8, it seems like all the code is running in that main thread. There is some other threads open but it appears to be background code from .NET and nothing that I programed. – Migals Apr 26 '23 at 15:25
  • Do you have your form set up correctly? [Show a child form in the centre of Parent form in C#](https://stackoverflow.com/a/944919/719186). – LarsTech Apr 26 '23 at 15:42
  • @LarsTech StartPosition was always set to CenterParent. The code is currently not setup to call ShowDialog(this) and even when I call ShowDialog with (this) it does not actualy set the Parent form, it sets the owner to (this). The other issue is that I am calling this ShowDialog from within a class so (this) does not actually exist. I setup the same code to call directly from another form using ShowDialog(this) and it still doesnt work in my .NET 4.8 version of the code. Again, calling ShowDiloag(this) is not setting the parent form to anything but rather the owner. – Migals Apr 26 '23 at 17:24
  • Well, open a new project and see if you can recreate the issue. You have something going on that we can't see. – LarsTech Apr 26 '23 at 17:44

0 Answers0