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
rbRunMacro
relative to the entire screen (see link).The reason we use
ToolStrip.PointToScreen
is thatToolStripButton
does not offer thePointToScreen
method. Therefore, we have to useToolStripButton.Location
to get the location ofrbRunMacro
relative to its parent control (see link).