在客戶區右下角繪製 Logo 圖片:
protected override void OnPaintBackground(PaintEventArgs e) {
base.OnPaintBackground(e);
if (myLogonImage != null) {
int x = ClientSize.Width - myLogonImage.Width;
int y = ClientSize.Height - myLogonImage.Height;
if (e.ClipRectangle.IntersectsWith(new Rectangle(x, y, myLogonImage.Width, myLogonImage.Height))) {
e.Graphics.DrawImage(myLogonImage, x, y, myLogonImage.Width, myLogonImage.Height);
}
}
}
[DllImport("user32.dll")]
private static extern bool LockWindowUpdate(IntPtr hWnd);
protected override void OnScroll(ScrollEventArgs se) {
if (bolFixedBackground) {
if (se.Type == ScrollEventType.ThumbTrack) {
LockWindowUpdate(IntPtr.Zero); // 解鎖
Refresh(); // 立即重繪
LockWindowUpdate(this.Handle); // 鎖定
} else {
LockWindowUpdate(IntPtr.Zero);
Invalidate(); // 標記失效,稍後重繪
}
}
base.OnScroll(se);
}
關鍵策略:捲動中 (ThumbTrack) 解鎖→重繪→鎖定,防止系統預設捲動破壞背景;捲動結束 (ThumbPosition 等) 僅標記失效,避免閃爍。