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:

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:
- one parameter
point location - 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
Post a Comment