문제

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).

form.Location = this.tsMacroRecorder.PointToScreen(rbRunMacro.Bounds.Location);

The reason we use ToolStrip.PointToScreen is that ToolStripButton does not offer the PointToScreen method. Therefore, we have to use ToolStripButton.Location to get the location of rbRunMacro relative to its parent control (see link).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top