Вот несколько способов добиться выравнивания окон на разных языках программирования:
-
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); -
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> -
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() -
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()); } }