VB窗體載入變半透明

2022-07-04 09:52:02 字數 1995 閱讀 1490

1樓:匿名使用者

private declare function setlayeredwindowattributes lib "user32" (byval hwnd as long, byval crkey as long, byval balpha as byte, byval dwflags as long) as long

private declare function getwindowlong lib "user32" alias "getwindowlonga" (byval hwnd as long, byval nindex as long) as long

private declare function setwindowlong lib "user32" alias "setwindowlonga" (byval hwnd as long, byval nindex as long, byval dwnewlong as long) as long

private const gwl_exstyle = (-20)

private const lwa_alpha = &h2

private const gwl_style = (-16)

private sub form_load()

hscroll1.max = 255

hscroll1.min = 50 '最低透明度,再低hscroll1就看不到了

dim templng as long

dim rtn as long

rtn = getwindowlong(hwnd, gwl_exstyle)

rtn = rtn or ws_ex_layered

setwindowlong hwnd, gwl_exstyle, rtn

setlayeredwindowattributes hwnd, 1, 100, lwa_alpha

hscroll1.value = 100

end sub

private sub hscroll1_change()

dim rtn as long

rtn = getwindowlong(hwnd, gwl_exstyle)

rtn = rtn or ws_ex_layered

setwindowlong hwnd, gwl_exstyle, rtn

setlayeredwindowattributes hwnd, 1, hscroll1.value, lwa_alpha

end sub

2樓:棘棘芽

private declare function setwindowlong lib "user32" alias "setwindowlonga" (byval hwnd as long, byval nindex as long, byval dwnewlong as long) as long

private declare function setlayeredwindowattributes lib "user32" (byval hwnd as long, byval crkey as long, byval balpha as byte, byval dwflags as long) as long

const ws_ex_layered = &h80000

const gwl_exstyle = (-20)

const lwa_alpha = &h2

'const lwa_colorkey = &h1

private sub form_load()

setwindowlong me.hwnd, gwl_exstyle, ws_ex_layered

setlayeredwindowattributes me.hwnd, 0, 180, lwa_alpha

end sub

vb窗體最大化的問題

最好的方法還是直接設定窗體的 borderstyle 為 1 不讓最大化和調整窗體 知你什麼都會啦 在窗體resize事件中計算窗體的縮放比 然後再根據縮放比相應計算返控制元件的實際width height自己計 private sub form resize 物件名.width form1.wid...

vb點選關閉按鈕時窗體隱藏,vb 讓程式點選關閉按鈕時彈出提示框

vb 點選關閉按鈕時會產生 unloadmode 0,可以通過它來判斷實現。private sub form queryunload cancel as integer,unloadmode as integer if unloadmode 0 thenme.hide cancel 1 end if...

如何知道窗體已經最小化,vb中判斷窗體狀態,若為最小化則恢復為正常

樓主可以在窗體的 resize 事件中通過檢測窗體的 windowstate 屬性值來獲知視窗已經最小化。下面是個例子 private sub form resize if me.windowstate vbminimized then msgbox 您已將視窗最小化了 vbokonly,視窗狀態 ...