1

I need a control panel, which is docked to the right side of my primary screen, here's how I've done that:

        var PrimaryScreen = Screen.PrimaryScreen;
        var WorkingArea = PrimaryScreen.WorkingArea;            

        this.Width = WorkingArea.Width / 6;
        this.Height = WorkingArea.Height;
        int X = WorkingArea.Width - this.Width;
        int Y = WorkingArea.Location.Y;
        this.Location = new Point(X, Y);

This works exactly, how I want it too, with one slight problem. I would need to simultaneously resize the primary screen workingarea, so other maximized forms / apps won't overlap my panel. Also, my panel should be always visible.

I had found a post here, exactly concerning this topic: Reserve screen area in Windows 7

This is how it was suggested there:

public class WorkArea
{
    [System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "SystemParametersInfoA")]
    private static extern Int32 SystemParametersInfo(Int32 uAction, Int32 uParam, IntPtr lpvParam, Int32 fuWinIni);

    private const Int32 SPI_SETWORKAREA = 47;
    public WorkArea(Int32 Left, Int32 Right, Int32 Top, Int32 Bottom)
    {
        _WorkArea.Left = Left;
        _WorkArea.Top = Top;
        _WorkArea.Bottom = Bottom;
        _WorkArea.Right = Right;
    }

    public struct RECT
    {
        public Int32 Left;
        public Int32 Right;
        public Int32 Top;
        public Int32 Bottom;
    }

    private RECT _WorkArea;
    public void SetWorkingArea()
    {
        IntPtr ptr = IntPtr.Zero;
        ptr = Marshal.AllocHGlobal(Marshal.SizeOf(_WorkArea));
        Marshal.StructureToPtr(_WorkArea, ptr, false);
        int i = SystemParametersInfo(SPI_SETWORKAREA, 0, ptr, 0);
    }
}

But the post is over 10 years old, and the solution sadly didn't work for me.

So my question would be: What is the best way to accomplish that? I am open to any suggestions, since I am still learning ;)

arvenyon
  • 153
  • 1
  • 8
  • Sadly I don't have the code right now, but I remember that about 10 months ago I used the same code and something was wrong after correcting it worked in windows 10. – Ashkan Mobayen Khiabani Nov 07 '19 at 10:23
  • @AshkanMobayenKhiabani Any idea, what It coud've been? – arvenyon Nov 07 '19 at 10:27
  • let me see if I can do it again because unfortunately, I don't have the code now. – Ashkan Mobayen Khiabani Nov 07 '19 at 10:28
  • actually this is the code that I used (and altered a bit) [https://stackoverflow.com/questions/6267206/how-can-i-resize-the-desktop-work-area-using-the-spi-setworkarea-flag](https://stackoverflow.com/questions/6267206/how-can-i-resize-the-desktop-work-area-using-the-spi-setworkarea-flag) – Ashkan Mobayen Khiabani Nov 07 '19 at 10:48

0 Answers0