Link to home
Start Free TrialLog in
Avatar of dba123
dba123

asked on

VB.NET Clipboard questions with Print Screens

I want to build an app that on any computer's PC, when they hit the print screen button, I want my VB.NET app to instantly capture that and send it to either a database table, email as an attachment, or as a jpg or something in a share on our network.

Questions:

1) I know you can use the clipboard class in the Forms namespace but I'm wondering should I check for a bitmap after the user hits their print screen or another type?

2) I'm using SQL 2005, and I want to insert this data into a table however not sure what datatype to use.   I believe SQL 2005 has a new datatype to handle images...

3) About the clipboard itself, what type of memory is it stored in?  I assume it's not saved on the hard disk?

4) Should I use GetData or GetImage in the Clipboard Class?

5) How would I grab the event, and awaken my VB.NET code to grab the picture from the clipboard?  If a user clicks the print screen button, is there any way possible to capture that event then fire off my VB.NET which I'll code to somehow shove the information into my SQL 2005 table?
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dba123
dba123

ASKER

Then again, I can't just provide a web button that they can click on to perform the print screen for them because then they would loose focus of whatever they were trying to print screen because they would have to gain focus on the IE webform and that's all the print screen of the desktop would show...them print screening the button that fires off the print screen.  So I really do need to figure out if I can trigger my VB.NET code based off them clicking on the print screen key, and somehow capture that event...not sure if that's possible?
"So I really do need to figure out if I can trigger my VB.NET code based off them clicking on the print screen key, and somehow capture that event...not sure if that's possible?"

The code I just posted does this...but it is for WINFORMS...not sure if this is possible in WebForms as I don't develop for the web.
The only way to get something like this to work with webforms would be writing an activex control and give it full permissions to execute on the client's pc.  The problem there is getting a digital signature for the control so ie doesn't have a nervous breakdown, the certs cost around $500 (the last time i looked which was a while ago) and they only give certs to companies afaik, and they want to talk to you first which in South Africa is a real pain cos you have to be at work at 3 in the friggin morning.
Avatar of dba123

ASKER

Idle_Mind , so yours traps an even when they press a certain key on their keboard?  does your current example account for the print screen key?
Avatar of dba123

ASKER

I don't want to show the user a picturebox, just send it.  If I have to show a picture box, then pop it up and close it real fast so they don't really have to know much about it if you really need it to get this to work after they press the print screen key
"does your current example account for the print screen key?"

Yes...it traps the PrtScr key...even when the apps is not in focus.



"I don't want to show the user a picturebox, just send it.  If I have to show a picture box, then pop it up and close it real fast so they don't really have to know much about it if you really need it to get this to work after they press the print screen key"

The PictureBox is ONLY there for illustrative purposes and is NOT needed for the app to work.

The screenshot is captured into a Bitmap instance called "bmp".  In the code below, you can do anything in the part where it says "do something with bmp...":

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim data As IDataObject = Clipboard.GetDataObject()
        If data.GetDataPresent(GetType(System.Drawing.Bitmap)) Then
            Timer1.Stop()
            Dim bmp As Bitmap = CType(data.GetData(GetType(System.Drawing.Bitmap)), Bitmap)

            ' do someting with bmp...
            PictureBox1.Image = bmp
        End If
    End Sub

So there you could send it to your database, email it, or save it to the network share...