M
M
Mikhail2017-08-31 18:33:51
C++ / C#
Mikhail, 2017-08-31 18:33:51

C# How to fix a form in the background (Like Gadget)?

Hello, I want to create something like a widget (gadget) on the desktop in C #,
but the question arose of how to fix the window on the desktop? So that it can not be raised above the rest of the windows

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
mshak, 2017-09-05
@TheMaxai

public partial class Form1 : Form
    {
        [DllImport("user32.dll")]
        static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);

        static readonly IntPtr HWND_BOTTOM = new IntPtr(1);
        const UInt32 SWP_NOSIZE = 0x0001;
        const UInt32 SWP_NOMOVE = 0x0002;
        const UInt32 SWP_NOACTIVATE = 0x0010;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            SetWindowPos(Handle, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
        }

        private void Form1_Activated(object sender, EventArgs e)
        {
            SetWindowPos(Handle, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
        }
    }

P
Peter, 2017-08-31
@petermzg

So what's stopping you from writing a widget?
Example

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question