WPF-获取元素的位置,将窗体显示在按钮旁边

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Win_Display_Position win = new Win_Display_Position();           

            //显示在按钮旁边
            Button btn = (Button)sender;
            double width = btn.ActualWidth;
            double height = btn.ActualHeight;
            Point point= btn.PointToScreen(new Point(0,0));

            double xpos = point.X;
            double ypos = point.Y;

            win.Left = xpos;
            win.Top = ypos;
            win.ShowDialog();
        }
    }
}
 

猜你喜欢

转载自blog.csdn.net/dxm809/article/details/86136771