By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,960 Members | 1,368 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,960 IT Pros & Developers. It's quick & easy.

Uploading picture on a form

P: 6
Hello,

When i upload a picture onto my form my mouse starts lagging, everything starts lagging as a matter of fact. I think some settings have to be changed. What is happening to me right now is that i am moving a picture box around the screen and it lags when i move it with the uploading picture on the background. But when there is no picture on the background form there is no lag...! The picture box i am using is transparent is its suppose to show the form. Someone please help!

Thank you
May 14 '10 #1
Share this Question
Share on Google+
5 Replies


Curtis Rutland
Expert 2.5K+
P: 3,256
When you say "uploading" do you mean you are in the active process of uploading a file, or do you mean it starts lagging after you have set a picture in the box?

You mentioned transparency...in my experience that can definitely increase your slow-down. Try turning the transparency off and testing again.
May 15 '10 #2

ThatThatGuy
Expert 100+
P: 449
@MarcosGalarza
What do you mean by "Lagging" ? did you meant flickering.....
May 15 '10 #3

P: 6
@ThatThatGuy
yes it flickers
May 17 '10 #4

ThatThatGuy
Expert 100+
P: 449
@MarcosGalarza
Im not understanding what did you say in your first post...

But let me get it... you are moving a picture via the mouse on a transparent form... or vice-versa... if its something like that then...

set the DoubleBuffered property of he form to true.... this will reduce flickering to much extent
May 18 '10 #5

P: 5
Ok this is what I am understanding:
you have a form with a large background picture (form.backgroundimage) and you have a picture box on top of that with a smaller picture loaded (picturebox.image)

your goal is to move the picturebox around the form when the user moves the mouse, like an oversized specialized mouse cursor, correct? So you are using an image and picturebox with transparency because you don't want the user to see the borders of the picturebox, just the image floating around the background scene, right?

let me know. Is that what you are trying to do?
If so, that method is pretty processor intense, and it may be pretty difficult to get rid of the flickering. However, I think I have an alternative that accomplishes the same goal with no fliker (or a little bit of flicker if your background image is larger than 8192 x 8192 pixles)

If not, then nevermind. I misunderstood.

P.S. What version of vb.net are you using?
Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.     Private f_bmpButterfly As Bitmap
  3.  
  4.     'THIS CODE ASSUMES YOU HAVE A FORM (NAMED Form1) CONTAINING A PICTUREBOX (NAMED PictureBox1)
  5.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  6.  
  7.         '   Load the background image
  8.         PictureBox1.BackgroundImage = New Bitmap("C:\your_background.jpg")
  9.         PictureBox1.Dock = DockStyle.Fill
  10.         PictureBox1.BackgroundImageLayout = ImageLayout.Stretch
  11.  
  12.         '   load the foreground image
  13.         f_bmpButterfly = New Bitmap("C:\your_foreground.png")
  14.  
  15.         'Do not load any image into the foreground (PictureBox1.Image) yet. 
  16.         'the MouseMove event will do that as soon as the user moves the cursor 
  17.         'over the picturebox
  18.     End Sub
  19.  
  20.     Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
  21.         'get rid of the previous foreground image
  22.         If Not IsNothing(PictureBox1.Image) Then
  23.             PictureBox1.Image.Dispose()
  24.             PictureBox1.Image = Nothing
  25.         End If
  26.  
  27.         'Prepare a new, blank foreground image.
  28.         '   By making the foreground image as small as possible (no larger than the butterfly + it's position
  29.         '   the program doesn't have to think about any unneccessary areas of the image when displaying it.
  30.         Dim newBitmap As New Bitmap(e.X + f_bmpButterfly.Width, e.Y + f_bmpButterfly.Height, Imaging.PixelFormat.Format32bppArgb)
  31.  
  32.         'position the butterfly in the foreground
  33.         '   The graphics class is awesome! But don't forget to dispose of it when you're done.
  34.         Dim gr As Graphics
  35.  
  36.         '   Tell the grphics class which image you want to mess with.
  37.         gr = Graphics.FromImage(newBitmap)
  38.  
  39.         '   Paint the butterfly onto the blank foreground
  40.         gr.DrawImage(f_bmpButterfly, e.X, e.Y)
  41.  
  42.         'Display the new foreground image. no need to change the background image
  43.         PictureBox1.Image = newBitmap
  44.  
  45.         'Dispose ummanaged resources
  46.         gr.Dispose()
  47.         gr = Nothing
  48.     End Sub
  49. End Class
May 22 '10 #6

Post your reply

Sign in to post your reply or Sign up for a free account.