Visual Studio C#
.net Framework
Hi, I have followed this tutorial: https://www.youtube.com/watch?v=oKQlPE57gYg to 4:20 but after testing then I got this error message and I don’t know how to fix it.
Error Message
This is all my code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Energy_Organizer
{
public partial class Form1 : Form
{
private bool drag;
private int mouseX;
private int mouseY;
private const int WM_NCHITTEST = 0x84;
private const int HTCLIENT = 0x1;
private const int HTCAPTION = 0x2;
private bool m_aeroEnabled;
private const int CS_DROPSHADOW = 0x00020000;
private const int WM_NCPAINT = 0x0085;
private const int WM_ACTIVEAPP = 0x001C;
[System.Runtime.InteropServices.DllImport("dwmapi.dll")]
public static extern int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS pMarInset);
[System.Runtime.InteropServices.DllImport("dwmapi.dll")]
public static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize);
[System.Runtime.InteropServices.DllImport("dwampi.dll")]
public static extern int DwmIsCompoisionEnabled(ref int pfEnabled);
[System.Runtime.InteropServices.DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")]
private static extern IntPtr CreateRoundRectRgn
(
int nLeftRect,
int nTopRect,
int nRightRect,
int nBottomRect,
int nWidthEllipse,
int nHeightEllipse
);
public struct MARGINS
{
public int leftWidth;
public int rightWidth;
public int topHeight;
public int bottomHeight;
}
protected override CreateParams CreateParams
{
get
{
m_aeroEnabled = CheckAeroEnabled();
CreateParams cp = base.CreateParams;
if (!m_aeroEnabled)
cp.ClassStyle |= CS_DROPSHADOW; return cp;
}
}
private bool CheckAeroEnabled()
{
if (Environment.OSVersion.Version.Major >= 6)
{
int enabled = 0; DwmIsCompoisionEnabled(ref enabled);
return (enabled == 1) ? true : false;
}
return false;
}
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_NCPAINT:
if (m_aeroEnabled)
{
var v = 2;
DwmSetWindowAttribute(this.Handle, 2, ref v, 4);
MARGINS margins = new MARGINS()
{
bottomHeight = 1,
leftWidth = 0,
rightWidth = 0,
topHeight = 0
}; DwmExtendFrameIntoClientArea(this.Handle, ref margins);
}
break;
default: break;
}
base.WndProc(ref m);
if (m.Msg == WM_NCHITTEST && (int)m.Result == HTCLIENT) m.Result = (IntPtr)HTCAPTION;
}
public Form1()
{
InitializeComponent();
}
}
}
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Forms;
namespace Energy_Organizer
{
internal class Gradient_Sidebar_Panel : System.Windows.Forms.Panel
{
public Color gradientTop {get; set;}
public Color gradientBottom {get; set;}
protected override void OnPaint(PaintEventArgs e)
{
LinearGradientBrush linear = new LinearGradientBrush(this.ClientRectangle, this.gradientTop, this.gradientBottom, 90F);
Graphics graphics = e.Graphics;
graphics.FillRectangle(linear, this.ClientRectangle);
base.OnPaint(e);
}
}
}
I have already tried the basic tipps from Visual Studio but nothing works.
I hope somebody can Help me 🙂 Thx
New contributor
Mr Ex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.