I have toolstrip menu with some buttons, menu is located in toolstrip container. What I am trying to accomplish is to open new form exactly at specific toolstripbutton location... This is my code. It works unless I move toolstrip menu to bottom or right side of toolstrip container...
private System.Windows.Forms.ToolStripButton rbRunMacro;
private System.Windows.Forms.ToolStrip tsMacroRecorder;
private void rbRunMacro_Click(object sender, EventArgs e)
{
Rectangle rect = this.rbRunMacro.Bounds;
Point location = PointToScreen ( new Point(this.tsMacroRecorder.Location.X + rect.X, this.tsMacroRecorder.Location.Y + rect.Y));
MacroListForm form = new MacroListForm();
form.StartPosition = FormStartPosition.Manual;
form.Location = location ;
form.Show();
}
You should get the location of
rbRunMacrorelative to the entire screen (see link).The reason we use
ToolStrip.PointToScreenis thatToolStripButtondoes not offer thePointToScreenmethod. Therefore, we have to useToolStripButton.Locationto get the location ofrbRunMacrorelative to its parent control (see link).