WPF 無邊框窗體滑鼠拖動改變大小和移動

2021-10-11 02:46:29 字數 1583 閱讀 4782

**:**

protected override void onsourceinitialized(eventargs e)} 

protected virtual intptr wndproc(intptr hwnd, int msg, intptr wparam, intptr lparam, ref bool handled)

**:

private const int wm_nchittest = 0x0084;

private readonly int agwidth = 12; //拐角寬度

private readonly int bthickness = 4; // 邊框寬度

private point mousepoint = new point(); //滑鼠座標

protected virtual intptr wndproc(intptr hwnd, int msg, intptr wparam, intptr lparam, ref bool handled)

// 視窗左下角

else if (this.actualheight + this.top - this.mousepoint.y <= this.agwidth

&& this.mousepoint.x - this.left <= this.agwidth)

// 視窗右上角

else if (this.mousepoint.y - this.top <= this.agwidth

&& this.actualwidth + this.left - this.mousepoint.x <= this.agwidth)

// 視窗右下角

else if (this.actualwidth + this.left - this.mousepoint.x <= this.agwidth

&& this.actualheight + this.top - this.mousepoint.y <= this.agwidth)

// 視窗左側

else if (this.mousepoint.x - this.left <= this.bthickness)

// 視窗右側

else if (this.actualwidth + this.left - this.mousepoint.x <= this.bthickness)

// 視窗上方

else if (this.mousepoint.y - this.top <= this.bthickness)

// 視窗下方

else if (this.actualheight + this.top - this.mousepoint.y <= this.bthickness)

else // 視窗移動

#endregion

}return intptr.zero;

}

**:

public enum hittest:int

無邊框窗體拖動和改變大小

const int htleft 10 const int htright 11 const int httop 12 const int httopleft 13 const int httopright 14 const int htbottom 15 const int htbottomlef...

WPF實現可改變大小的無邊框窗體

這裡記載乙個wpf中比較實用的功能,怎樣處理乙個無邊框窗體。通常的做法是設定windowstyle none 和resizemode noresize 但這樣有乙個問題,窗體的大小不能夠通過拖動進行改變。於是,很多的解決方式如下 這樣的解決方案基本上達到了效果,不過較真起來依然存在問題,因為只能夠拖...

拖動無邊框窗體

frm main.cs 1 using system 2using system.collections.generic 3using system.componentmodel 4using system.data 5using system.drawing 6using system.linq ...