using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Text; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace AppLauncher { public partial class MainForm : Form { private bool windowDragging = false; private Point windowOffset = new Point(); public MainForm() { InitializeComponent(); this.FormBorderStyle = FormBorderStyle.None; this.StartPosition = FormStartPosition.Manual; } protected override void OnLoad(EventArgs e) { base.OnLoad(e); int requestedHeight = (int)Math.Floor(decimal.Divide((Screen.PrimaryScreen.WorkingArea.Height - this.Height), 2)); this.Location = new Point(Screen.PrimaryScreen.WorkingArea.X, (Screen.PrimaryScreen.WorkingArea.Y + requestedHeight)); //foreach (Screen item in Screen.AllScreens) //{ // richTextBox1.Text += item.Bounds.ToString() + Environment.NewLine; // richTextBox1.Text += item.WorkingArea.ToString() + Environment.NewLine; // richTextBox1.Text += Environment.NewLine; //} } //protected override void OnLocationChanged(EventArgs e) //{ // base.OnLocationChanged(e); // this.Location = new Point(Screen.PrimaryScreen.WorkingArea.X, this.Location.Y); //} protected override void OnPaintBackground(PaintEventArgs e) { base.OnPaintBackground(e); //Graphics g = e.Graphics; //g.TextRenderingHint = TextRenderingHint.AntiAlias; //g.InterpolationMode = InterpolationMode.HighQualityBilinear; //g.PixelOffsetMode = PixelOffsetMode.HighQuality; //g.SmoothingMode = SmoothingMode.HighQuality; //g.FillRectangle(new LinearGradientBrush(this.DisplayRectangle, Color.FromArgb(76, 83, 93), Color.FromArgb(255, 255, 255), -30F), this.DisplayRectangle); } //protected override void OnPaintBackground(PaintEventArgs e) //{ // // do nothing //} //protected override void OnPaint(PaintEventArgs e) //{ // base.OnPaint(e); // if (this.BackgroundImage == null) // { // return; // } // Graphics g = e.Graphics; // g.TextRenderingHint = TextRenderingHint.AntiAlias; // g.InterpolationMode = InterpolationMode.HighQualityBilinear; // g.PixelOffsetMode = PixelOffsetMode.HighQuality; // g.SmoothingMode = SmoothingMode.HighQuality; // g.DrawImage(this.BackgroundImage, Point.Empty); //} private void panel1_MouseDown(object sender, MouseEventArgs e) { if (e.Button != MouseButtons.Left) { return; } windowDragging = true; windowOffset = e.Location; } private void panel1_MouseUp(object sender, MouseEventArgs e) { windowDragging = false; } private void panel1_MouseMove(object sender, MouseEventArgs e) { if (windowDragging) { Point pos = this.PointToScreen(e.Location); //this.Location = new Point(currentScreenPos.X - windowOffset.X, currentScreenPos.Y - windowOffset.Y); int y = Math.Max((pos.Y - windowOffset.Y), Screen.PrimaryScreen.WorkingArea.Y); y = Math.Min(y, (Screen.PrimaryScreen.WorkingArea.Y + Screen.PrimaryScreen.WorkingArea.Height) - this.Height); this.Location = new Point(Screen.PrimaryScreen.WorkingArea.X, y); } } //private void Form1_MouseDown(object sender, MouseEventArgs e) //{ // const int WM_NCLBUTTONDOWN = 0xA1; // const int HT_CAPTION = 0x2; // this.Capture = false; // Message msg = Message.Create(this.Handle, WM_NCLBUTTONDOWN, (IntPtr)HT_CAPTION, IntPtr.Zero); // WndProc(ref msg); //} } }