image - Screen Capture program in VB.NET -
i had created application captures screenshot of desktop screen. works button have used in form. want make thing works automatically using timers whenever try run program nullreferenceexception occur can 1 tell me whats going wrong here.
timercapture interval=5 timersave interval=6 here code can tell scenario:
public class form1 private sub timercapture_tick(byval sender system.object, byval e system.eventargs) handles timercapture.tick dim bounds rectangle dim screenshot system.drawing.bitmap dim graph graphics bounds = screen.primaryscreen.bounds screenshot = new system.drawing.bitmap(bounds.width, bounds.height, system.drawing.imaging.pixelformat.format32bppargb) graph = graphics.fromimage(screenshot) graph.copyfromscreen(bounds.x, bounds.y, 0, 0, bounds.size, copypixeloperation.sourcecopy) picturebox1.image = screenshot end sub private sub timersave_tick(byval sender system.object, byval e system.eventargs) handles timersave.tick me.picturebox1.image.save("d:\\capture.bmp") end sub private sub form1_load(byval sender system.object, byval e system.eventargs) handles mybase.load ' me.windowstate = formwindowstate.minimized 'me.showintaskbar = false end sub private sub timerclose_tick(byval sender system.object, byval e system.eventargs) handles timerclose.tick me.close() end sub private sub capture_btn_click(byval sender system.object, byval e system.eventargs) handles capture_btn.click dim bounds rectangle dim screenshot system.drawing.bitmap dim graph graphics bounds = screen.primaryscreen.bounds screenshot = new system.drawing.bitmap(bounds.width, bounds.height, system.drawing.imaging.pixelformat.format32bppargb) graph = graphics.fromimage(screenshot) graph.copyfromscreen(bounds.x, bounds.y, 0, 0, bounds.size, copypixeloperation.sourcecopy) picturebox1.image = screenshot end sub private sub save_btn_click(byval sender system.object, byval e system.eventargs) handles save_btn.click me.picturebox1.image.save("d:\\capture.bmp") end sub end class thanks in advance....
i think problem in timersave_tick, if, reason haven't valued me.picturebox1.image in timercapture_tick, throw nullreferenceexception while trying access picturebox1.image.
try modify in such way:
private sub timersave_tick(byval sender system.object, byval e system.eventargs) handles timersave.tick if(me.picturebox1.image isnot nothing) me.picturebox1.image.save("d:\\capture.bmp") end if end sub anyway, should able debug under visual studio, see exception thrown..
Comments
Post a Comment