Выравнивание окон в программировании: примеры на JavaScript, CSS, Python и C#

Вот несколько способов добиться выравнивания окон на разных языках программирования:

  1. JavaScript:

    // Center an element horizontally and vertically in the window
    function alignElementToWindow(element) {
    element.style.position = 'fixed';
    element.style.top = '50%';
    element.style.left = '50%';
    element.style.transform = 'translate(-50%, -50%)';
    }
    // Usage:
    const myElement = document.getElementById('myElement');
    alignElementToWindow(myElement);
  2. CSS:

    /* Center an element horizontally and vertically in the window */
    .centered-element {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    }
    /* Usage: */
    <div class="centered-element">Hello World</div>
  3. Python с Tkinter:

    import tkinter as tk
    # Create a window
    window = tk.Tk()
    # Center the window on the screen
    window.eval('tk::PlaceWindow . center')
    # Start the event loop
    window.mainloop()
  4. C# с Windows Forms:

    using System;
    using System.Windows.Forms;
    public class MainForm : Form
    {
    public MainForm()
    {
        // Center the form on the screen
        StartPosition = FormStartPosition.CenterScreen;
    }
    // Entry point
    public static void Main()
    {
        Application.Run(new MainForm());
    }
    }