winforms - moving and placing child window near parent window C# -


Grass proof.

I have created a child form by pressing any button. I want to make it near the parents 'limits,

If the parents' form is taken by the user then the hair window is there.

Thank you.

First of all, you have to keep a reference to the child's form in parent. Second, you need to insert a representative for the parent's move and resize event (the same representative method will be enough). Third, you need to use the method where you want your child to have the form anywhere.

The following code is an example of what you want:

  public partial class form 1: form   

{

  form2 _form2; Int _offset = 5; Public Form 1 () {Initialization (); This.Move + = New EventHandler (Movseform); This.Resize + = New Event Handler (MoveSubForm); } Private Zero form1_load (object sender, event date e) {_form2 = new form 2 (); _form2.Show (); Movoshoot (this, E); } Secure Zero MoveSubForm (Object Sender, EventArgs E) {If (_form2! = Faucet) {_form2.Height = this.Highight / 2; _form2.Width = this.Width / 3; _form2.Left = this.Left + this.Width + _offset; _form2.Top = this.Top; }}   

It should be in conformity with the parent of your child, in which 5 pixels are offset, where children have a height of 1/2 and 1/3 parents Are detailed in With this example I hope that you will be able to get what you want from your project.

Cheers, CEC

Comments