在建立C#的無邊框窗體的時候,在任務欄上點擊窗體的時候,無法顯示系統的右鍵菜單。由於是C#隱藏掉了系統的右鍵菜單,使用以下代碼顯示出來就可以了。不過存在一個問題是,最大化的時候會把任務欄也覆蓋掉,界面占滿整個屏幕

1、在Class裡面加入

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Runtime.InteropServices;


namespace WindowsFormsApplication1


...{

class Class1


...{

System.Windows.Forms.Form FormA;


public void Skin(System.Windows.Forms.Form frm)


...{

FormA = frm;


frm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;

frm.BackColor = System.Drawing.SystemColors.Desktop;

frm.TransparencyKey = System.Drawing.SystemColors.Desktop;


NoneBorder();

}


// http://blog.csdn.Net/hbxtlhx/archive/2007/08/01/1721061.ASPx

[DllImport("user32.dll", EntryPoint = "GetWindowLong", CharSet = CharSet.Auto)]

public static extern int GetWindowLong(HandleRef hWnd, int nIndex);


[DllImport("user32.dll", EntryPoint = "SetWindowLong", CharSet = CharSet.Auto)]

public static extern IntPtr SetWindowLong(HandleRef hWnd, int nIndex, int dwNewLong);

void NoneBorder()


...{

int WS_SYSMENU = 0x00080000; // 系統菜單

int WS_MINIMIZEBOX = 0x20000; // 最大最小化按鈕


int windowLong = (GetWindowLong(new HandleRef(FormA, FormA.Handle), -16));

SetWindowLong(new HandleRef(FormA, FormA.Handle), -16, windowLong | WS_SYSMENU | WS_MINIMIZEBOX);

}

}

}
2、在Form中調用

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;


namespace WindowsFormsApplication1


...{

public partial class Form1 : Form


...{

Class1 SkinClass = new Class1();


public Form1()


...{

InitializeComponent();


SkinClass.Skin(this);

}

}

}