İşaretçi Form Üzerine Geldiğinde Aktifleşsin - CSharp


C# form uygulamasında fare işaretçisini form üzerine getirdiğimizde tıklamaya gerek kalmadan otomatik olarak odaklanmasını sağlayan alternatif bir örnektir.

Ekran Görüntüsü

Kod


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CSharpIsaretciFormUzerineGeldigindeAktiflessin
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        [DllImport("User32.dll")]
        public static extern bool SetForegroundWindow(IntPtr hWnd);

        [DllImport("User32.dll")]
        public static extern bool ShowWindow(IntPtr hWnd, int show);

        private const int SW_SHOW = 5;


        private void Form1_MouseEnter(object sender, EventArgs e)
        {
            Show();
            WindowState = FormWindowState.Normal;
            Activate();

            ShowWindow(Handle, SW_SHOW);
            SetForegroundWindow(Handle);
        }
    }
}

Yararlanılan Kaynaklar
Etiketler
csharp csharp form csharp windows forms