※Using google translate※

[C#][For beginners]Display images in the front row

・Display the image and prevent the application from being removed

・Can be created with Visual Studio


Preparation steps + source code

  1. ※To disable it, enter "112358" while the application is active.
  2. Created using C# "Windows Forms Application (.NET Framework)"
  3. Open the designer properties
  4. Enter "F1_KD" in KeyDown
  5. Enter "F1_CL" in FormClosing
  6. Place the PictureBox wherever you like
  7. Copy and paste the code
  8. Change the namespace part to your project name.
  9. Set the RGB value of "use_color" in the code to a color that is not used in the image.
    ※Please note that there is an old bug in Windows that makes clicking work or not depending on the color!
  10. (If you want to run it automatically after starting the PC) Delete /* and */ in the code.

using System;
using System.Diagnostics;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Bgpic
{
    public partial class Form1 : Form
    {
        Keys[] password = { Keys.D1, Keys.D1, Keys.D2, Keys.D3, Keys.D5, Keys.D8 };
        int pcount = 0;
        Image img = Image.FromFile(@"X.png"); //Any image path.
        MyHook myHook = new MyHook();
        Color use_color = Color.FromArgb(1, 1, 1); //Change the color here.
        public Form1()
        {
            InitializeComponent();
            myHook.Hook();
            this.FormBorderStyle = FormBorderStyle.None;
            this.WindowState = FormWindowState.Maximized;
            this.TopMost = true;
            pictureBox1.Width = Screen.PrimaryScreen.Bounds.Width;
            pictureBox1.Height = Screen.PrimaryScreen.Bounds.Height;
            this.TransparencyKey = use_color;
            this.BackColor = use_color;
            pictureBox1.BackColor = use_color;
            this.FormBorderStyle = FormBorderStyle.None;
            /*
            Microsoft.Win32.RegistryKey regkey =
            Microsoft.Win32.Registry.CurrentUser.OpenSubKey(
            @"Software\Microsoft\Windows\CurrentVersion\Run", true);
            regkey.SetValue(Application.ProductName, Application.ExecutablePath);
            regkey.Close();
            */
            
            Itv();
        }
        public async void Itv()
        {
            await Task.Delay(30);
            this.FormBorderStyle = FormBorderStyle.None;
            this.WindowState = FormWindowState.Maximized;
            this.TopMost = true;
            pictureBox1.Width = Screen.PrimaryScreen.Bounds.Width;
            pictureBox1.Height = Screen.PrimaryScreen.Bounds.Height;
            Draw();
            Itv2();
        }
        public void Draw()
        {
            if (pictureBox1.Image != null)
            {
                pictureBox1.Image.Dispose();
            }
            Bitmap canvas = new Bitmap(pictureBox1.Width, pictureBox1.Height);
            Graphics g = Graphics.FromImage(canvas);
            //Position and size are optional.
            g.DrawImage(img, (canvas.Width - img.Width) / 2, (canvas.Height - img.Height) / 2 + 800, img.Width, img.Height);
            pictureBox1.Image = canvas;
            g.Dispose();
        }
        public void Itv2()
        {
            Itv();
        }
        private void F1_KD(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == password[pcount])
            {
                pcount++;
                if (pcount >= password.Length)
                {
                    /*
                    Microsoft.Win32.RegistryKey regkey =
                    Microsoft.Win32.Registry.CurrentUser.OpenSubKey(
                    @"Software\Microsoft\Windows\CurrentVersion\Run", true);
                    regkey.DeleteValue(Application.ProductName);
                    regkey.Close();
                    */
                    Application.Exit();
                }
            }
            else
            {
                pcount = 0;
            }
        }
        class MyHook
        {
            delegate int delegateHookCallback(int nCode, IntPtr wParam, IntPtr lParam);
            [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
            static extern IntPtr SetWindowsHookEx(int idHook, delegateHookCallback lpfn, IntPtr hMod, uint dwThreadId);

            [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
            [return: MarshalAs(UnmanagedType.Bool)]
            static extern bool UnhookWindowsHookEx(IntPtr hhk);

            [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
            static extern IntPtr GetModuleHandle(string lpModuleName);

            IntPtr hookPtr = IntPtr.Zero;
            delegateHookCallback callback;
            public void Hook()
            {
                callback = HookCallback;
                using (Process curProcess = Process.GetCurrentProcess())
                using (ProcessModule curModule = curProcess.MainModule)
                {
                    hookPtr = SetWindowsHookEx(
                        13,
                        callback,
                        GetModuleHandle(curModule.ModuleName),
                        0
                    );
                }
            }

            int HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
            {
                Keys k = (Keys)(short)Marshal.ReadInt32(lParam);
                short sk = (short)k;
                if (0x30 <= sk && sk <= 0x39)
                {
                    return 0;
                }
                return 1;
            }

            public void HookEnd()
            {
                UnhookWindowsHookEx(hookPtr);
                hookPtr = IntPtr.Zero;
            }
        }

        private void F1_CL(object sender, FormClosingEventArgs e)
        {
            if (pcount < password.Length) e.Cancel = true;
        }
    }
}

			

Completed!

Display images in the front row

Reference

I'll add it later as I remember.