none
Move a picture box RRS feed

  • Question

  • Hi all,

    I program on a windows CE 6.0 smart device (.net compact framework 2.5) and I have a problem to move a picture box, when I move the picture box, it draw "marks" behind it.

    There are picture of picturebox movement on my program :

    ImageShack® - Online Photo and Video Hosting
    ImageShack® - Online Photo and Video Hosting

    here is my <acronym title="Visual Basic">vb</acronym> code :

    Imports System.Object
    Imports System.Drawing
    Imports System.Drawing.Drawing2D
    Imports System.Windows.Forms
    Imports System.Threading.Thread
    Imports System.IO.Ports

    Public Class Form1
    Dim x As Integer

    Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
    If e.Button = MouseButtons.Left Then
    x = e.X
    End If
    End Sub

    Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
    If e.Button = MouseButtons.Left Then
    PictureBox1.Left += (e.X - x)
    End If
    End Sub

    End Class


    Thanks for your help.
    Wednesday, January 26, 2011 11:35 PM

All replies

  • I see absolutely nothing with the code in your post that would explain this type of behavior.  Is there any more code other than what you included in your post that is drawing to the form during this time (like a background image or something)?  The code posted works fine on emulators and devices that I have, regardless of what version of the Compact Framework is used (although there is no such thing as Compact Framework 2.5 - there is 2.0, 2.0 SP1, 2.0 SP2, and 3.5).  Have you tested on an emulator or on a different device?  Do you know that other graphics or Windows Forms programs run okay on this device?
    Tom Gensel PTG Systems, LLC
    http://www.ptgsystems.com
    Thursday, January 27, 2011 12:57 AM
  • Hi,

    Just to characterize the behaviour of your device, replace the matching line in your code with a line below. ( you should know the 'width of your picture' or do some iterations with different values.)

    PictureBox1.Left +=( 5+ Width of your picture)

    Do you observe multiple pictures of full size now?

    Regards,

    Mansukh

    Thursday, January 27, 2011 4:21 AM
  • I tried different image sizes as well as different iterations of values on the PictureBox translation, but despite that I only ever see a single image, never multiple images.  Do you see different results with different images sizes?  What is the size of the image you are using?  Also, you might try adding range checks to the size being reported in the event args to make sure they are unreasonably large for some reason.
    Tom Gensel PTG Systems, LLC
    http://www.ptgsystems.com
    Thursday, January 27, 2011 6:14 AM
  • sorry, I made mistake,  I use version 3.5 of compact framework. Even if I use this code only with a white back color, it makes me multiple images (I try also to change backcolor of picturebox, to set transparency or white but it fails).

    I have tested my program with emulator (under visual studio 2008), other graphic windows forms programs run ok.

    The size of my picturebox is 100 x 100 and I have tested many sizes but it's not working.

    I have tried what you write me Mansukh but when I move the picturebox, I don't see the movement and sometimes, picturebox blocks for few seconds and we can see multiple images too sometimes.

     

    Thanks for your help.

    Thursday, January 27, 2011 5:39 PM
  • Your last post says you tested in the emulator, but you didn't make clear what the result of that test was.  Are you saying that the result in the emulator was the same (i.e. multiple images) as your testing on the device?
    Tom Gensel PTG Systems, LLC
    http://www.ptgsystems.com
    Thursday, January 27, 2011 6:40 PM
  • Yes the result is the same in the two cases (test on the device, and with emulator) .

     

    Thursday, January 27, 2011 8:11 PM
  • Can you post the content of  your Form's InitializeComponent?  I'm interested in seeing the properties on the Form and PictureBox.
    Tom Gensel PTG Systems, LLC
    http://www.ptgsystems.com
    Thursday, January 27, 2011 8:42 PM
  • Sorry, how can I see my form's initialize component ?
    Thursday, January 27, 2011 8:49 PM
  • In Visual Studio, right click on your form's .VB file (e.g. Form1.vb) and select "View Code".  In the dropdown box in the upper left of the edit window, select your Form (e.g. Form1), then in the upper right drop down box where it (probably) says "(Declarations)" select InitializeComponent instead.  You will then be able to view and copy the code from Private Sub InitializeComponent and post it here.
    Tom Gensel PTG Systems, LLC
    http://www.ptgsystems.com
    Friday, January 28, 2011 12:53 AM
  • I tried similar code on my device and my observations are also similar.

    The picture is moving to a new location, but takes some noticable time to remove the picture from previous position. So multiple pictures are seen on the screen momentorily.

    I tried to invalidate the related region, but still no improvements.

    Regards,

    Mansukh

    Friday, January 28, 2011 4:59 AM
  • This is my form's initialize component :

     

    <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
    Partial Public Class Form1
      Inherits System.Windows.Forms.Form
    
      'Form overrides dispose to clean up the component list.
      <System.Diagnostics.DebuggerNonUserCode()> _
      Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing AndAlso components IsNot Nothing Then
          components.Dispose()
        End If
        MyBase.Dispose(disposing)
      End Sub
    
      'Required by the Windows Form Designer
      Private components As System.ComponentModel.IContainer
    
      'NOTE: The following procedure is required by the Windows Form Designer
      'It can be modified using the Windows Form Designer. 
      'Do not modify it using the code editor.
      <System.Diagnostics.DebuggerStepThrough()> _
      Private Sub InitializeComponent()
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form1))
        Me.PictureBox1 = New System.Windows.Forms.PictureBox
        Me.SuspendLayout()
        '
        'PictureBox1
        '
        Me.PictureBox1.Image = CType(resources.GetObject("PictureBox1.Image"), System.Drawing.Image)
        Me.PictureBox1.Location = New System.Drawing.Point(77, 347)
        Me.PictureBox1.Name = "PictureBox1"
        Me.PictureBox1.Size = New System.Drawing.Size(91, 86)
        Me.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage
        '
        'Form1
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(96.0!, 96.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi
        Me.BackColor = System.Drawing.Color.White
        Me.ClientSize = New System.Drawing.Size(800, 480)
        Me.ControlBox = False
        Me.Controls.Add(Me.PictureBox1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
        Me.KeyPreview = True
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.TopMost = True
        Me.ResumeLayout(False)
    
      End Sub
      Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
    
    End Class
    

    Friday, January 28, 2011 7:38 AM
  • Since what you want to do is move the PictureBox, try changing the Location member instead of Left.


    Bruce Eitman (eMVP)
    Senior Engineer
    Bruce.Eitman AT Eurotech DOT com
    My BLOG http://geekswithblogs.net/bruceeitman

    Eurotech Inc.
    www.Eurotech.com
    Friday, January 28, 2011 2:06 PM
    Moderator
  • I just tried your code, or rather algorithm, in C# on a CE 6.0 device.  It worked without any artifacts.

    I set up the picture box with a red background and an image that was smaller than the box, then a grey background fitted to the image.  Both worked as expected.


    Bruce Eitman (eMVP)
    Senior Engineer
    Bruce.Eitman AT Eurotech DOT com
    My BLOG http://geekswithblogs.net/bruceeitman

    Eurotech Inc.
    www.Eurotech.com
    Friday, January 28, 2011 5:09 PM
    Moderator
  • Same here - it works fine on any device and emulator I try, even with the exact same Form and PictureBox properties.  I'd be inclined to say there is a problem with device (like the display driver) but I have no explanation for why you are seeing it on an emulator, because I do not.

    Edit: To clarify, I am testing your actual VB code, not a C# version, but the language choice wouldn't make a difference.


    Tom Gensel PTG Systems, LLC
    http://www.ptgsystems.com

    Friday, January 28, 2011 5:49 PM
  • and is  it possible to mix C# and vb under VS2008? How can I do same program with 2 languages ? Thanks
    Saturday, January 29, 2011 1:40 AM
  • So you think, I could not do that on my device :(?
    Sunday, January 30, 2011 9:18 PM
  • This is going a bit off topic from the original post, but -

    Yes, that's one of the main aspects of the .NET Common Language Runtime (CLR) - that anything you can do in one supported language you can usually do in another.  Now, sometimes one language lets you do something easier or clearer than another, but certainly in the case of something as simple as this, it really doesn't matter.  In fact, there are free .NET code converters on the internet that will convert code from one language to another for you.  Here's one if you'd like to investigate - http://www.developerfusion.com/tools/convert/vb-to-csharp/.

    You can also use different assemblies written in C# and VB.NET together in a single program, or merge assemblies written in different languages together into a single assembly using a program called ILMerge which can be downloaded from the .NET Framework Developer Center. 

    End the end, however, I don't believe the choice of language is going to make any difference to your original problem here.


    Tom Gensel PTG Systems, LLC
    http://www.ptgsystems.com
    Monday, January 31, 2011 1:52 AM