Hi
How To Make This Faster

Private Sub MonMove()
        For A = 0 To (Cnt - 1)
            MyControlArray(A).Location = New Point(MyControlArray(A).Left _
- 1,MyControlArray(A).Top)
        Next
    End Sub

first i make A Hundred of PictureBox Later
I use Array
How To Make it Faster ,When It Appear More than 20 Box
It Will BeCome Slower And Slower Later It Move Each Box You Can See IT Move Each Box
My COde So Slow
When TimerTick Will Call MonMove
Timer InterVal is 10
Another Class
Array Code

Public Class BulletArray
    Inherits System.Collections.CollectionBase
    Private ReadOnly HostForm As System.Windows.Forms.Form
    Public Sub New(ByVal host As System.Windows.Forms.Form)
        HostForm = host
        Me.AddNewBullet()
    End Sub
    Public Function AddNewbullet() As System.Windows.Forms.PictureBox
        Dim aPictureBox As New System.Windows.Forms.PictureBox()
        Me.List.Add(aPictureBox)
        HostForm.Controls.Add(aPictureBox)
        aPictureBox.Top = Count * 25
        aPictureBox.Left = 100
        aPictureBox.Tag = Me.Count
        aPictureBox.BackColor = Color.Black
        aPictureBox.Size = New Size(10, 5)
        AddHandler aPictureBox.Click, AddressOf ClickHandler
        Return aPictureBox
    End Function
    Default Public ReadOnly Property Item(ByVal Index As Integer) As  _
       System.Windows.Forms.PictureBox
        Get
            Return CType(Me.List.Item(Index), System.Windows.Forms.PictureBox)
        End Get
    End Property

    Public Sub Remove()
        If Me.Count > 0 Then
            HostForm.Controls.Remove(Me(Me.Count - 1))
            Me.List.RemoveAt(Me.Count - 1)
        End If
    End Sub
    Public Sub ClickHandler(ByVal sender As Object, ByVal e As  _
   System.EventArgs)
        MessageBox.Show("you have clicked button " & CType(CType(sender,  _
           System.Windows.Forms.PictureBox).Tag, String))
    End Sub

End Class

This Code Change From MSDN ButtonArrayProject
Thanks For Help

Dani AI

Generated

Moving a large number of PictureBox controls on every tick is slow because each control is a full Windows control: moving one generates window messages, invalidates regions, and forces the UI thread to repaint many separate elements. The simplest, fastest fix is to stop using a control per bullet and draw them yourself on a single, double‑buffered surface. That’s what was pointing to—draw all bullets in one Paint pass instead of repositioning many controls.

A practical pattern to follow:

  • Keep a lightweight Bullet class (X, Y, velocity, size). Reuse instances; avoid allocating per tick.
  • Use one custom control or Panel and enable double buffering (ControlStyles). Update bullet positions on a single timer, then Invalidate the surface (or only the changed regions).
  • Do all drawing in OnPaint/ Paint using the cached bullets list. Cache brushes/pens and avoid creating GDI objects inside the draw loop.

Example (VB.NET sketch):

Public Class Bullet
    Public X As Single, Y As Single, DX As Single
    Public Width As Integer = 10, Height As Integer = 5
End Class

Public Class BulletSurface
    Inherits Panel
    Private bullets As New List(Of Bullet)
    Public Sub New()
        Me.SetStyle(ControlStyles.UserPaint Or ControlStyles.AllPaintingInWmPaint _
            Or ControlStyles.OptimizedDoubleBuffer, True)
        Me.UpdateStyles()
    End Sub
    Protected Overrides Sub OnPaint(e As PaintEventArgs)
        e.Graphics.Clear(Me.BackColor)
        For Each b In bullets
            e.Graphics.FillRectangle(Brushes.Black, b.X, b.Y, b.Width, b.Height)
        Next
    End Sub
End Class

Performance tips and cautions:

  • Use a timer interval around 20–33 ms (30–50 FPS). 10 ms is usually unnecessary and expensive.
  • Reuse Bullet objects and brushes; avoid per-frame allocations.
  • If you must keep real controls, add/remove them inside SuspendLayout/ResumeLayout and reuse them rather than recreating.
  • For thousands of objects or GPU acceleration, consider Direct2D/DirectX or WPF.
  • Be careful with threads: keep UI work on the UI thread; compute physics off-thread then marshal results to the UI.

For : porting to this single-surface approach will usually eliminate the slowdown you see when >20 PictureBoxes are moving.

Recommended Answers

All 6 Replies

What are you trying to do?

Make It Faster

Yes. I got that.

What is it that you want to go faster??
Do you want something to move?
Do you want to add pictureboxes faster?
What?

I Change The Location Of Each Control
When It HAve More Control It Will Be Slower
It Move Each Control Not All In one Step
I Want To Move in One Step Not Move Each Control
I See How About Multithread

Yes. Well.
Having 100 pictureboxes on the form and moving them at the same time in a timer event, will slow things down.
Based on the name of your class BulletArray I'm gonna assume that the pictureboxes contain a picture of a bullet, and that moving the picturebox somehow will simulate that the bullet is moving.

You should instead look into using GDI, and use the Paint method for a panel to move your bullet.
is just a sample of what can be done, practically flicker free.
The sample is based on this article.

Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.