[DllImport("user32.dll", EntryPoint = "GetDC")]
創(chuàng)新新互聯(lián),憑借十余年的網(wǎng)站設(shè)計(jì)制作、網(wǎng)站設(shè)計(jì)經(jīng)驗(yàn),本著真心·誠(chéng)心服務(wù)的企業(yè)理念服務(wù)于成都中小企業(yè)設(shè)計(jì)網(wǎng)站有1000+案例。做網(wǎng)站建設(shè),選創(chuàng)新互聯(lián)。
public static extern IntPtr GetDC(IntPtr hWnd);
[DllImport("user32.dll", EntryPoint = "ReleaseDC")]
public static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDC);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
先找到你要截圖的那個(gè)窗體的 句柄 然后根據(jù)這個(gè)句柄得到改窗體的DC 創(chuàng)建一個(gè)bitmap 然后填充 得到的bitmap后 顯示到picturebox里面
Dim PictureBox11(1) as PictureBox ‘放在最前面
Dim i as integer
Form_load 設(shè)i=0
動(dòng)態(tài)添加:
if ipicturebox11.ubound then load(picturebox11(i))
picturebox11(i).loadpicture("圖片地址")
Picture11(i).PaintPicture Picture11(i).Picture, 0, 0, Picture11(i).Width, Picture11(i).Height
picturebox11(i).visible=true
i=i+1
動(dòng)態(tài)刪除
i=i-1
unload picturebox11(i)
用Button控件就可以了 修改BackgroundImage 屬性 類似這樣
Button1.BackgroundImage = Image.FromFile("C:\Users\hp\Desktop\EMOTICONS\EMOTICON SMILE.png")
如果要實(shí)現(xiàn)動(dòng)態(tài)效果的話需要2個(gè)圖片當(dāng)Button1_MouseHover事件時(shí)也就是鼠標(biāo)停留在button上的時(shí)候顯示一個(gè)圖片,當(dāng)Button1_MouseLeave事件時(shí),也就是鼠標(biāo)離開(kāi)button時(shí)顯示原來(lái)的圖片,這樣就是動(dòng)態(tài)的了.
我有個(gè)笨辦法,先用API抓圖到內(nèi)存里,然后再在根據(jù)你點(diǎn)鼠標(biāo)的屏幕工作區(qū)坐標(biāo),去那圖里取色。
-----------------------
'抓圖所需的API
Private Declare Function CreateCompatibleDC Lib "GDI32" (ByVal hDC As Integer) As Integer
Private Declare Function CreateCompatibleBitmap Lib "GDI32" (ByVal hDC As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer) As Integer
Private Declare Function SelectObject Lib "GDI32" (ByVal hDC As Integer, ByVal hObject As Integer) As Integer
Private Declare Function BitBlt Lib "GDI32" (ByVal srchDC As Integer, ByVal srcX As Integer, ByVal srcY As Integer, ByVal srcW As Integer, ByVal srcH As Integer, ByVal desthDC As Integer, ByVal destX As Integer, ByVal destY As Integer, ByVal op As Integer) As Integer
Private Declare Function DeleteDC Lib "GDI32" (ByVal hDC As Integer) As Integer
Private Declare Function DeleteObject Lib "GDI32" (ByVal hObj As Integer) As Integer
Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal hwnd As Integer) As Integer
Const SRCCOPY As Integer = HCC0020
'抓圖的部分
Dim hDC, hMDC As Integer
Dim hBMP, hBMPOld As Integer
Dim sw, sh As Integer
hDC = GetDC(0)
hMDC = CreateCompatibleDC(hDC)
sw = Screen.PrimaryScreen.Bounds.Width
sh = Screen.PrimaryScreen.Bounds.Height
hBMP = CreateCompatibleBitmap(hDC, sw, sh)
hBMPOld = SelectObject(hMDC, hBMP)
BitBlt(hMDC, 0, 0, sw, sh, hDC, 0, 0, SRCCOPY)
hBMP = SelectObject(hMDC, hBMPOld)
Dim bmp As Bitmap = Image.FromHbitmap(New IntPtr(hBMP))
DeleteDC(hDC)
DeleteDC(hMDC)
DeleteObject(hBMP)
......
'取點(diǎn)的顏色
bmp.GetPixel(e.X, e.Y)
----------------------------
關(guān)鍵就是這些你自己組合吧,你分給的太少了,很麻煩,恕我不幫你改全了。如果要仔細(xì)幫你改,請(qǐng)另開(kāi)高分貼,不要用新馬甲來(lái)