c# - Open second form, right next first form -


i'am using winforms.

i created application finished. consider following: have 2 forms, first form starts @ application startup, second form needs opened right next first form.

example:

form collision

how can access location of first form @ second form? should send "this" constructor of second form?

edit

following code helped me out:

private void changelogtoolstripmenuitem_click(object sender, eventargs e) {      if (_changelog.isdisposed)      {             _changelog = new changelog();      }             _changelog.location = new point((left + width), top);             _changelog.show(); } 

a basic rule keep in mind when designing one's constructor: never give unnecessary information constructor.

so, need here not other window, rather it's position. better, need position new window should located at.

this means shouldn't let second form know first form, instead it's constructor should take either:

  1. one parameter point location
  2. two parameters int x, int y

depending on preferance. (should) of course have both constructors, can decide whether give point location or int x, int y.

this being said, forget read. better using constructor @ all, set property manually when creating second form:

secondform form = new secondform() {     location = new point(this.right, this.top) }; 

which other way of saying:

secondform form = new secondform(); form.location = new point(this.right, this.top); 

Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -