הערה
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות להיכנס או לשנות מדריכי כתובות.
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות לשנות מדריכי כתובות.
Question
Saturday, October 25, 2014 2:28 PM
Setting the property StartPosition to CenterParent does not work for a specific form. It opens slightly below the calling form. Both forms are the same size (1300.700). In both forms the StartPosition = CenterParent.
Any ideas welcome.
John
All replies (20)
Thursday, October 30, 2014 1:22 AM ✅Answered | 1 vote
It's this piece of code inside subLoad() that's causing your form to go down.
Dim intBoundWidth As Integer = Screen.PrimaryScreen.Bounds.Width
Dim intBoundHeight As Integer = Screen.PrimaryScreen.Bounds.Height
Dim intX As Integer = intBoundWidth - Me.Width
Dim intY As Integer = intBoundHeight - Me.Height
Me.Location = New Point(intX / 2, intY / 2)
Saturday, October 25, 2014 2:29 PM
BTW, both forms open with ShowDialog.
Saturday, October 25, 2014 5:23 PM | 2 votes
Hi,
do you use the overload of ShowDialog that sets the owner of the new Form? Do you assign the owner before showing the form? like:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim f As New Form
f.StartPosition = FormStartPosition.CenterParent
f.ShowDialog(Me)
End Sub
[And is the calling (parent) form completely visible on the screen?]
Regards,
Thorsten
Sunday, October 26, 2014 7:42 AM
Thanks Thorsten,
I believe I am doing what you mention above.
The calling from is as follows
I click on button "Patient Details" (See red circle). This executes the following code
Dim frm = New frmCustomerColumnar(intCustomerID)frm.StartPosition = FormStartPosition.CenterParentfrm.ShowDialog(Me)
which opens the new form as shown below.
The new form does not open exactly on top of the calling form.
Regards,
John
Monday, October 27, 2014 2:56 AM | 1 vote
Hi JohnPapa05,
According to your description, you'd like to open the new form on top of the calling form.
I suggest you setting the StartPostion to Manual, and setting the location equal to the parent form.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim frm = New frmCustomerColumnar(intCustomerID)
frm.Location = Me.Location
frm.StartPosition = FormStartPosition.Manual
frm.ShowDialog(Me)
End Sub
If you have any other concern regarding this issue, please feel free to let me know.
Best regards,
Youjun Tang
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.
Monday, October 27, 2014 7:12 AM
Thanks Youjun for your reply,
I tried your suggestion and it created an additional problem. It resized the popup form. I fixed this by adding frm.Size = Me.Size
Dim frm = New frmCustomerColumnar(intCustomerID)frm.StartPosition = FormStartPosition.Manual
frm.Location = Me.Location
frm.Size = Me.Size
frm.ShowDialog(Me)
Unfortunately the problem still remains
Tuesday, October 28, 2014 1:36 AM
Hi JohnPapa05
As your picture showed, The form is different from the system form.
Have you customize the style of the system form? Maybe you have changed some property in the Customized form.
If you could tell me the change you have done, I would help you better.
Best regards,
Youjun
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.
Tuesday, October 28, 2014 4:04 AM
Try this:
In the Form_Load event of the new form
Me.Position = CType(Me.Parent, Form).Position
Tuesday, October 28, 2014 10:58 AM
Is there a Me.Position property in VB.net?
Tuesday, October 28, 2014 11:59 AM | 1 vote
Hi John,
I have tested this using a few forms that i used the TitleBarImage class that i helped you with a few weeks ago and the TitleBarImage class does not seem to be causing any problems that i can find. It seems to work if you set the Forms up like this.
In the Main Form (Form1) i simply used this code to create the new instance of the 2nd Form (Form2) and show it.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim f2 As New Form2
f2.ShowDialog(Me) 'assigns this form (Form1) as the Owner of the 2nd form (Form2)
End Sub
Then in the 2nd Form (Form2) i simply set the bounds of Form2 to the Bounds of its Owner Form (Form1).
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.ControlBox = False
Me.Text = " "
Me.Bounds = Me.Owner.Bounds
Dim tbimg As Image = Image.FromFile("C:\testfolder\32bpp_32.png")
Dim tbi As New TitleBarImage(Me, tbimg, HorizontalAlignment.Right) 'create a new instance of the TitleBarImage class
tbi.Show() 'Show the image
End Sub
This sets the Location and Size to the same Location and Size of its Owner form. 8)
If you say it can`t be done then i`ll try it
Tuesday, October 28, 2014 12:45 PM
Many thanks IronRazerz (as usual),
Tried it, unsuccessfully though. What is of interest is that the calling form (below) is the only form where if I click on the flag nothing happens. Maybe I changed something inadvertently or I have a special property set up.
When I click on Patient Details I get the picture below which is not CenterParent,
John
Wednesday, October 29, 2014 2:23 AM | 1 vote
Sorry. I meant Me.Location. Anyway, that may not work. Here's another idea. Try setting the parent to the parent of the current form. You are showing them via ShowDialog() so it doesn't matter what form is the parent.
Like:
Main Form will open FormA
FormA will open FormB
Inside Button click in FormA
Using frm as New FormB
frm.ShowDialog(Me.Parent)
End Using
FormB will then be centered inside Main Form instead of FormA.
Wednesday, October 29, 2014 7:02 AM
Thanks for the reply,
I thought you meant Location so I tried it before and you are right, no luck.
On an equally negative note, your new suggestion of ParentCentering on the Parent of the Parent did not work.
I am considering redoing the problematic form, which took eons to prepare.
John
Wednesday, October 29, 2014 10:50 AM | 1 vote
Hi John,
Without us having the whole project to look over and see what may be going wrong, it is pretty much a guessing game. My guess would be that there is some code or a property of the form that is causing this flaw because, you say it is only happening with this one Form and not the others.
Like i say, we don`t know what all the properties of this form are set to, if it is being opened by a main form or another Dialog form, where in the events you are using this code, or if there is other code in one of the other events that is effecting this.
I am sure you have looked already but, compare this form with any other form that does work properly and see if you can find a difference in the forms Properties or if the code in your load events differ somehow. Also check to see if there is any code in the Resize, SizeChanged, or the Shown events that could be causing the problem. 8)
If you say it can`t be done then i`ll try it
Wednesday, October 29, 2014 11:06 AM
Hi IronRazerz,
Will recheck.
John
Wednesday, October 29, 2014 11:38 AM | 1 vote
Is this by any chance an inherited form?
Wednesday, October 29, 2014 11:52 AM
No inheritance.
To make things more interesting, I can open 4-5 other forms from the Parent and they respect the CenterParent property value.
John
Wednesday, October 29, 2014 1:38 PM
How about a screenshot of the properties of the problematic form as well as the codes for its events.
Wednesday, October 29, 2014 2:33 PM
Screenshot and Codes are found below. Hope it helps
Would not allow me to insert code (too big)
Code can be found at
https://dl.dropboxusercontent.com/u/13473531/Form.txt
John
Thursday, October 30, 2014 11:39 AM
Many thanks. You are right.
It was an earlier attempt to position the screen. It was commented out at some point and obviously uncommented.
Once again thanks for your time.
John