Gents,
I have an animation on my form, a bouncing ball. The animation is function good, but it is bouncing behind all the controls. Howe do I bring the ball to front of the controls
Best Regards
Cathrine
Private Sub Timer4_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer4.Tick If CheckBox1.Checked = True Then Dim grfx As Graphics = CreateGraphics()grfx.DrawImage(bitmap, _
CInt(ballPositionX - ballBitmapWidth / 2), _ CInt(ballPositionY - ballBitmapHeight / 2), _ballBitmapWidth, ballBitmapHeight)
grfx.Dispose()
ballPositionX += ballMoveX
ballPositionY += ballMoveY
If ballPositionX + ballRadiusX >= ClientSize.Width _ Or ballPositionX - ballRadiusX <= 0 ThenballMoveX = -ballMoveX
Beep()
End If If ballPositionY + ballRadiusY >= ClientSize.Height _ Or ballPositionY - ballRadiusY <= 0 ThenballMoveY = -ballMoveY
Beep()
End If End If End Sub

How do I bring the animation in my form, to front of the controls?
Ruxana Patel
See my new post which shows how to do such things.
http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=557731&SiteID=1
Qi Sheng
Hey Tall Dude,
Thank you for the replies.
I have not found any solution yet, how to bring the bouncing ball to front of the controls in my form! There must be a code for this.
Is there anybody else who can help me with this code
Best Regards
Cathrine
Eric Murphy
I don't think you want to send all of your controls to the front and then to the back.
Try doing your drawing on a panel and doing a bring to front / send to back of the panel in the timer event. Might work.
Or you could use a specially shaped form on top of your form.
See my reply to post "How to move form without the title bar "
I'm a newbie, so these may not be the best answers.
Hossam El-Deen
Also see
http://www.developmentnow.com/g/20_2004_11_0_0_9426/Drawing-at-highest-z-layer.htm
genocide77
I'm guessing right click on the button
and there should be like a button where it expands to the right
then in that menu, press "Send to Back"
again, I'm completely guessing and I don't have my Express VB currently installed...
SO..
Keehun Nam
Tobi
Okay,
the following code demonstrates how to drag a ball around a form and in front of the one button living on the form.
The approach is to make a control, the ball. Click and drag near the ball, not in it, to move it.
<
Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _Partial
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 Thencomponents.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() Me.Button1 = New System.Windows.Forms.Button Me.TextBox1 = New System.Windows.Forms.TextBox Me.SuspendLayout() ' 'Button1 ' Me.Button1.Location = New System.Drawing.Point(503, 266) Me.Button1.Name = "Button1" Me.Button1.Size = New System.Drawing.Size(75, 23) Me.Button1.TabIndex = 1 Me.Button1.Text = "Button1" Me.Button1.UseVisualStyleBackColor = True ' 'TextBox1 ' Me.TextBox1.Location = New System.Drawing.Point(0, 0) Me.TextBox1.Multiline = True Me.TextBox1.Name = "TextBox1" Me.TextBox1.Size = New System.Drawing.Size(899, 631) Me.TextBox1.TabIndex = 2 ' 'Form1 ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center Me.ClientSize = New System.Drawing.Size(902, 633) Me.Controls.Add(Me.Button1) Me.Controls.Add(Me.TextBox1) Me.Name = "Form1" Me.Text = "Form1" Me.ResumeLayout(False) Me.PerformLayout() End Sub Friend WithEvents Button1 As System.Windows.Forms.Button Friend WithEvents TextBox1 As System.Windows.Forms.TextBoxEnd
ClassImports
System.Drawing.PrintingImports
System.Drawing.Drawing2DPublic
Class Form1 Private mouseOffset As Point Private isMouseDown As Boolean = False Private Sub Form1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.DoubleClick Me.Close() End Sub Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim shape As New System.Drawing.Drawing2D.GraphicsPathshape.AddEllipse(150, 20, 60, 60)
TextBox1.Region =
New System.Drawing.Region(shape)TextBox1.BringToFront()
End Sub Private Sub Form1_MouseDown(ByVal sender As Object, _ ByVal e As MouseEventArgs) Handles MyBase.MouseDown Dim xOffset As Integer Dim yOffset As Integer If e.Button = Windows.Forms.MouseButtons.Left ThenxOffset = -e.X - SystemInformation.FrameBorderSize.Width
yOffset = -e.Y - SystemInformation.FrameBorderSize.Height
mouseOffset =
New Point(xOffset, yOffset)isMouseDown =
True End If End Sub Private Sub Form1_MouseMove(ByVal sender As Object, _ ByVal e As MouseEventArgs) Handles MyBase.MouseMove If isMouseDown Then Dim mousePos As Point = Control.MousePositionmousePos.Offset(mouseOffset.X, mouseOffset.Y)
TextBox1.Location = mousePos
End If End Sub
Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUpisMouseDown =
False End SubEnd
Class