I have a custom control derived from Control which is dynamically added to the form. The control can have negative values in Location and is by default painted relative to the top left corner.
How can I get the control to have negative coordinates and painted relative to right bottom corner for example?
The question title and the question ask two different things.
For the title: yes, you can do relative placement, but you'll need to use nested layout panels, like TableLayoutPanel and FlowLayoutPanel. They should be able to do most, if not all, of what you want to do.
For the actual question:
- Why?
- No, you can't.
I'm not sure you can do it using Location property, w/o doing lot's of extra coding.
But (1) you can set it's "Anchor" property to Right and Bottom instead of Top and Left. Then, each time you resize the Form it will stay in the same spot relative to Right-Bottom corner of containing panel (the Form). Then (2) can set your Top-Left of Location to such values that it will be out of visible area... so Every time your Form (or Panel) is resized - Control will stay out of visible area.
Hopes it help.
You could do something like
Point relativePos = new Point(-10, -10);
control.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
control.Location = new Point(this.ClientSize.Width - control.Width + relativePos.X, this.ClientSize.Height - control.Height + relativePos.Y);
where relative pos is the position relative to the bottom right. The anchor makes sure it stays there on resize.
I made small class to manage position and size depends on container size :
http://www.codeproject.com/Tips/492814/Relative-design-components-on-WinForm