• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 933
  • Last Modified:

VB.Net - subsequent form's Center Parent not good enough

I've got a popup form, show dialog, set to center parent.
Any easy way to move it up a notch or two (vertically)?

I like the positioning except that it's hanging over some text on the parent form, that I'd rather avoid hiding...
0
sirbounty
Asked:
sirbounty
  • 3
  • 3
3 Solutions
 
Bob LearnedCommented:
The StartPosition is only a place to start when the form is first show.  If you want to move the form after it is shown, you can do that.  You will get a little jump, though, as the form is moved.  In order to keep from jumping, you could handle centering the child on the parent with your own code.

Bob
0
 
Joel CoehoornDirector of Information TechnologyCommented:
You can use manual, and set the form's left and top properties accordingly.  However, I think those properties work relative to the screen (I could be wrong in cases where you set the form's owner, I'd have to check that again to remember for sure), so you may need to use the parent form's PointToScreen() method to get your position set correctly relative to that form.
0
 
sirbountyAuthor Commented:
I was thinking that I would have to do some calculations with the parent form's position, but wasn't sure if that was different with .Net....
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
Bob LearnedCommented:
It is pretty much the same as with VB6, but you have some different properties for the Form to help you:  DisplayRectangle, ClientSize, and Bounds.

Bob
0
 
sirbountyAuthor Commented:
This seems to do it...does the logic look okay?

       Dim frmCal As New frmCalendar
       frmCal.StartPosition = FormStartPosition.Manual
       frmCal.Left = (Me.Left + (Me.Width / 2)) - frmCal.Width / 2
       frmCal.Top = ((Me.Top + (Me.Height / 2)) - frmCal.Height / 2) - 30 ' Subtract 30 twips to raise the top property of frmCal

And now that I've done it, I still want what I was thinking of adding earlier...some sort of border.  But that's another question.
0
 
sirbountyAuthor Commented:
Based on your comments Bob, would it be better to set the bounds, rather than the top/left properties?
0
 
Bob LearnedCommented:
That code looks good.  The Bounds property is good for getting the Top, Left, Width and Height, and probably wouldn't help much here.

Bob
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now