How can I position the window's position on startup to the right side of the user's screen?

后端 未结 6 1036
逝去的感伤
逝去的感伤 2021-02-19 11:17

I am currently creating a sidebar-like WPF application in C#. When a user starts the application, I would like the window to automatically position it\'s self to the side of the

相关标签:
6条回答
  • 2021-02-19 11:36
    <body>
    <script>
    function myfunc()
    {
        w1=window.open('http://www.google.com','Google','left=0,top=0,width=250px,height=250px');
        w2=window.open('http://www.yahoomail.com','Yahoo Mail','left=1166,top=0,width=250px,height=250px');
        w3=window.open('http://www.people.com','People Magazine','left=1166,top=500,width=250px,height=250px');
        w4=window.open('http://www.time.com','Time Magazines','left=0,top=500,width=250px,height=250px');
        w5=window.open('http://www.ew.com','Entertainment Weekly','left=550,top=250,width=250px,height=250px');
    
    }
    
    function myclose()
    {
     w1.close(); w2.close(); w3.close(); w4.close(); w5.close();
     w6=window.open('smartwindow.html',' mywindow',',');
    }
    </script>
        <div id="cover">
        <img src="images/abstract.jpeg" id="1" width="500px" height="400px" alt="color defined"onClick="myfunc()"/>
         <input type="button" value="click to close all windows" onClick="myclose()"/>
         </div>
    </body>
    
    0 讨论(0)
  • 2021-02-19 11:39

    use startPosition property or location property

    0 讨论(0)
  • 2021-02-19 11:43

    in your xaml :

    WindowStartupLocation="Manual" 
    

    in the constructor :

     Left = System.Windows.SystemParameters.PrimaryScreenWidth - Width
     Top=0
    
    0 讨论(0)
  • 2021-02-19 11:45
    public MainWindow()
    {
        InitializeComponent();
        WindowStartupLocation = WindowStartupLocation.Manual;
        Left =  System.Windows.Forms.SystemInformation.PrimaryMonitorSize.Width - Width;
    }
    
    0 讨论(0)
  • 2021-02-19 11:48

    Description

    You can use Screen from System.Windows.Forms.

    So add reference to the System.Windows.Forms.dll and System.Drawing.dll. Then change the Left and Height property in the MainWindow_Loaded method.

    Sample

    public MainWindow()
    {
        InitializeComponent();
        this.Loaded += new RoutedEventHandler(MainWindow_Loaded);
    }
    
    void MainWindow_Loaded(object sender, RoutedEventArgs e)
    {
        this.Left = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Right - this.Width;
        this.Top = 0;
        this.Height = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height;
    }
    

    More Information

    • MSDN - Screen Class
    0 讨论(0)
  • 2021-02-19 11:57

    You can do this without referencing win forms assemblies by using SystemParameters. In the code behind for your window XAML:

    MainWindow() {
        InitializeComponents();
    
        this.Loaded += new RoutedEventHandler(
          delegate(object sender, RoutedEventArgs args) {
            Width = 300;
            Left = SystemParameters.VirtualScreenLeft;
            Height = SystemParameters.VirtualScreenHeight;
        }
    }
    

    SystemParameters documentation

    0 讨论(0)
提交回复
热议问题