程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> WinForm完成攔阻窗體上各個部位的點擊殊效實例

WinForm完成攔阻窗體上各個部位的點擊殊效實例

編輯:C#入門知識

WinForm完成攔阻窗體上各個部位的點擊殊效實例。本站提示廣大學習愛好者:(WinForm完成攔阻窗體上各個部位的點擊殊效實例)文章只能為提供參考,不一定能成為您想要的結果。以下是WinForm完成攔阻窗體上各個部位的點擊殊效實例正文


本文實例講述了WinForm完成攔阻窗體上各個部位的點擊殊效,是一個異常適用的技能。分享給年夜家供年夜家參考。詳細剖析以下:

普通來講,windows窗體的題目欄沒法直接經由過程一些默許的事宜來掌握,須要懂得和WM_NCHITTEST相干的windows新聞。

以下示例演示了最簡略的後果片段:他會把客戶區和題目欄的後果交換,好比沒法按住題目欄拖動窗體而是改成了按住客戶區拖動,並禁用了封閉按鈕。 個中m.Result從-2到21都有界說,分離對應了全部窗體的各個部位,好比1代表客戶區,8代表最小化按鈕等等。

詳細功效代碼以下:

using System; 
using System.Windows.Forms; 
namespace WindowsApplication42 
{ 
 public partial class Form1 : Form 
 { 
  public Form1() { InitializeComponent(); this.Text = "雙擊左上角圖標封閉窗體"; } 
  //攔擊題目欄鼠標地位事宜 
  const int WM_NCHITTEST = 0x84; 
  protected override void WndProc(ref Message m) 
  { 
   base.WndProc(ref m); if (m.Msg == WM_NCHITTEST) 
   { 
    switch (m.Result.ToInt32()) 
    { 
     case 1://客戶區 
      m.Result = new IntPtr(2); break; 
     case 2://題目欄 
      m.Result = new IntPtr(1); break; 
     case 20: m.Result = new IntPtr(0); break; 
     default: Console.WriteLine(m); break; 
    } 
   } 
  } 
 } 
}

上面是各個常量的意義:從Delphi7 VCL中摘取:

{ WM_NCHITTEST and MOUSEHOOKSTRUCT Mouse Position Codes } 
 {$EXTERNALSYM HTERROR} 
 HTERROR = -2; 
 {$EXTERNALSYM HTTRANSPARENT} 
 HTTRANSPARENT = -1; 
 {$EXTERNALSYM HTNOWHERE} 
 HTNOWHERE = 0; 
 {$EXTERNALSYM HTCLIENT} 
 HTCLIENT = 1; 
 {$EXTERNALSYM HTCAPTION} 
 HTCAPTION = 2; 
 {$EXTERNALSYM HTSYSMENU} 
 HTSYSMENU = 3; 
 {$EXTERNALSYM HTGROWBOX} 
 HTGROWBOX = 4; 
 {$EXTERNALSYM HTSIZE} 
 HTSIZE = HTGROWBOX; 
 {$EXTERNALSYM HTMENU} 
 HTMENU = 5; 
 {$EXTERNALSYM HTHSCROLL} 
 HTHSCROLL = 6; 
 {$EXTERNALSYM HTVSCROLL} 
 HTVSCROLL = 7; 
 {$EXTERNALSYM HTMINBUTTON} 
 HTMINBUTTON = 8; 
 {$EXTERNALSYM HTMAXBUTTON} 
 HTMAXBUTTON = 9; 
 {$EXTERNALSYM HTLEFT} 
 HTLEFT = 10; 
 {$EXTERNALSYM HTRIGHT} 
 HTRIGHT = 11; 
 {$EXTERNALSYM HTTOP} 
 HTTOP = 12; 
 {$EXTERNALSYM HTTOPLEFT} 
 HTTOPLEFT = 13; 
 {$EXTERNALSYM HTTOPRIGHT} 
 HTTOPRIGHT = 14; 
 {$EXTERNALSYM HTBOTTOM} 
 HTBOTTOM = 15; 
 {$EXTERNALSYM HTBOTTOMLEFT} 
 HTBOTTOMLEFT = 16; 
 {$EXTERNALSYM HTBOTTOMRIGHT} 
 HTBOTTOMRIGHT = 17; 
 {$EXTERNALSYM HTBORDER} 
 HTBORDER = 18; 
 {$EXTERNALSYM HTREDUCE} 
 HTREDUCE = HTMINBUTTON; 
 {$EXTERNALSYM HTZOOM} 
 HTZOOM = HTMAXBUTTON; 
 {$EXTERNALSYM HTSIZEFIRST} 
 HTSIZEFIRST = HTLEFT; 
 {$EXTERNALSYM HTSIZELAST} 
 HTSIZELAST = HTBOTTOMRIGHT; 
 {$EXTERNALSYM HTOBJECT} 
 HTOBJECT = 19; 
 {$EXTERNALSYM HTCLOSE} 
 HTCLOSE = 20; 
 {$EXTERNALSYM HTHELP} 
 HTHELP = 21;

願望本文所述對年夜家的C#法式設計有所贊助。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved