PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Compact Framework
drawing directly onto picturebox
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Compact Framework
drawing directly onto picturebox
![]() |
drawing directly onto picturebox |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
Hi
Im making a signature capture and have been looking at examples, got it working ok but i have a problem im captureing all the points so i can redraw the image at will which i have code for in the paint event of a picture box if i try to redraw the image every time there is a new point in the image then it works but starts to slow down the point taking and the image drawing starts to flicker after the first few points. if i dont refresh the image untill the mouse up event it works flawlessly but it is not very good usability for soneone trying to sign the screen as they have to lift the pen to see there progress i have made an application in a normal win32 app and this code solves my problem Dim oldX As Integer Dim oldY As Integer Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown oldX = e.X oldY = e.Y End Sub Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove If Not e.Button = Windows.Forms.MouseButtons.Left Then Exit Sub Dim g As Graphics = PictureBox1.CreateGraphics g.DrawLine(Pens.Black, oldX, oldY, e.X, e.Y) oldX = e.X oldY = e.Y End Sub but when i try the same in a compact framework app i get a not supported exception. Anyone got any ideas?? Pete |
|
|
|
#2 |
|
Guest
Posts: n/a
|
The CreateGraphics method is only supported on CF 3.5. Out of interest
instead of re-writting what other have already written, have you looked at Rob Tiffany's Windows Mobile Accelerator. This set of libraries contains a signature capture control with source code. -- Simon Hart Visual Developer - Device Application Development MVP http://simonrhart.blogspot.com "MoosePR@gmail.com" wrote: > Hi > > Im making a signature capture and have been looking at examples, got > it working ok but i have a problem > > im captureing all the points so i can redraw the image at will which i > have code for in the paint event of a picture box > > if i try to redraw the image every time there is a new point in the > image then it works but starts to slow down the point taking and the > image drawing starts to flicker after the first few points. > > if i dont refresh the image untill the mouse up event it works > flawlessly but it is not very good usability for soneone trying to > sign the screen as they have to lift the pen to see there progress > > i have made an application in a normal win32 app and this code solves > my problem > > > Dim oldX As Integer > Dim oldY As Integer > Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e > As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown > oldX = e.X > oldY = e.Y > End Sub > > Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e > As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove > If Not e.Button = Windows.Forms.MouseButtons.Left Then Exit > Sub > Dim g As Graphics = PictureBox1.CreateGraphics > g.DrawLine(Pens.Black, oldX, oldY, e.X, e.Y) > oldX = e.X > oldY = e.Y > End Sub > > but when i try the same in a compact framework app i get a not > supported exception. > > Anyone got any ideas?? > > Pete > |
|
|
|
#3 |
|
Guest
Posts: n/a
|
Thanks for your reply Simon.
The finished product will be for sale, so i realy want to make sure that i am not stealing anyones source for my own gains, hence recoding it myself!! All i really need to do is just draw the new segment onto the picturebox rather than redrawing the entire signature. I have the code to redraw the entire thing (in the paint event) should there be any problems with start ment etc forcing a repaint. I am just struggling to create a graphics element and link it to the picturebox from outside of the picturebox paint event i have tried dim g as graphics = graphics.fromHdc(pbSig.Handle) which compiles but again gives me an error at runtime. and dim g as graphics = graphics.fromImage(pbSig.image) Also compiles but does not like the fact my picturebox has no image assigned to it. anyone got any ideas how i can add a single line to a picturebox without having to repaint the entire contents?? Pete |
|
|
|
#4 |
|
Guest
Posts: n/a
|
The problem with your code is the pbSig.Handle is a windows handle and
Graphics.FromHDC requires a device context. You could P/Invoke the native GetDC method in this case pass the window handle and then use the returned DC to create your Graphics instance. Peter -- Peter Foot Microsoft Device Application Development MVP www.peterfoot.net | www.inthehand.com In The Hand Ltd - .NET Solutions for Mobility <MoosePR@gmail.com> wrote in message news:910e6be6-c830-41f7-84d6-6d554828e11b@j22g2000hsf.googlegroups.com... > Thanks for your reply Simon. > > The finished product will be for sale, so i realy want to make sure > that i am not stealing anyones source for my own gains, hence recoding > it myself!! > > All i really need to do is just draw the new segment onto the > picturebox rather than redrawing the entire signature. > > I have the code to redraw the entire thing (in the paint event) should > there be any problems with start ment etc forcing a repaint. > > I am just struggling to create a graphics element and link it to the > picturebox from outside of the picturebox paint event > > i have tried > > dim g as graphics = graphics.fromHdc(pbSig.Handle) > > which compiles but again gives me an error at runtime. > > and > > dim g as graphics = graphics.fromImage(pbSig.image) > > Also compiles but does not like the fact my picturebox has no image > assigned to it. > > anyone got any ideas how i can add a single line to a picturebox > without having to repaint the entire contents?? > > Pete |
|
|
|
#5 |
|
Guest
Posts: n/a
|
Thanks for your reply!! the code works fine in normal .net but when i
try it in the compact framework it does not. I also tried turning on double buffering which is not supported either. I have found a solution to my problem. If i create a global bitmap the size of my picture box then on my mousemove event just add the line from last point to this point, then just asign the bitmap to the picture box. It works very fast and gives me smooth tracing no matter how much is already there and no matter how fast you move the pen(mouse) It is far simpler than any of the methods i have found on the web, doesnt involve overriding anything and you dont have to save a big list of point either!!! Thanks for the help guys ![]() |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 


