| 发表于:2007-01-25 16:25:036楼 得分:2 |
上面的方法有点问题,颜色不太对,你可以使用如下的代码来操作: [dllimport( "gdi32.dll ", charset = charset.auto, exactspelling = true)] private static extern int getpixel(intptr hdc, int nxpos, int nypos); [dllimport( "user32.dll ", entrypoint = "getdcex ", charset = charset.auto, exactspelling = true)] private static extern intptr intgetdcex(intptr hwnd, intptr hrgnclip, int flags); protected override void onclick(eventargs e) { point clientpoint = this.pointtoclient(control.mouseposition); intptr dc = intgetdcex(this.handle, intptr.zero, 0x402); int intcolor = getpixel(dc, clientpoint.x, clientpoint.y); int num1 = intcolor & 0xff; int num2 = (intcolor > > 8) & 0xff; int num3 = (intcolor > > 0x10) & 0xff; this.label1.forecolor = color.fromargb(num1, num2, num3); base.onclick(e); } | | |
|