Okay have no idea why it wont upgrade to 2010 .. I did it N.P. ...
Here is the VS 2010 ver of the same project ....
Hope this works ...
Gremmy...
Printable View
Okay have no idea why it wont upgrade to 2010 .. I did it N.P. ...
Here is the VS 2010 ver of the same project ....
Hope this works ...
Gremmy...
Hi,
Again, thanks. I am able to open these files and compile the project into an app.
Yes. If I choose random and set the interval to 120, I get the precise animation style and effect that looks like the Flash demo. Fantastic!
I will need to carefully look at the code, re-read what you've posted, to see what you've done to accomplish this, learn from it.
Much thanks!
Kind Regards,
Great ... Glad it is what you were looking for....
The main reason for the first two styles was to provide a exact 50/50 spread and also where you can allow one step and count the changes..
The code is not too complicated and followed allot of what you already coded, with the difference of using a realizable picture box.
Also i rearranged some of it so that it runs better, and faster..
Note that there are no try catch blocks for incase ....... Only checking that is needed is that the text entry is numeric, however that can be taken care of with this small piece of codeIf your dont understand something, just ask .. ill try to explain it to you in laymans terms ...Code:Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If Not IsNumeric(e.KeyChar) Then
e.Handled = True
End If
End Sub
Hi Gremmy,
Figured out where to place this additional code. It seems to work without error.
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If Not IsNumeric(e.KeyChar) Then
e.Handled = True
End If
End Sub
I've been trying to do a few changes :
successful:
(1) increasing speed by increasing the dots changed per interval to 1000. Seems to better match the speed of the Flash and Delphi Windows demo's.
so far unsuccessful:
(2) trying to figure out (so far unsuccessfully) how to default to random and fill and (like in the Flash demo) clicking on the canvas screen to start and stop (toggle);
so far unsuccessful:
(3) setting up a 30 second default animation time-once started, runs for 30 seconds then stops.
Any suggestions, help much appreciated.
Kind Regards,
ARG .. have to retype .. still getting random BANNED IP Problems...
Okay let me try again ...
#1 - dots changed per interval is calculated in this bit of code
It works like this....Code:Dotcount = CInt(400 / (1000 / Timer1.Interval))
400 (dots) / (per) 1000 (ms) - the actual math used is a little more than that, in that it works out the number per frame.. but i took the numbers from your original spec..
so to make it 1000 per second.. change the above line too
#2 - Goto "Form1.vb Design" in VS .. where you now see the forms design ...Code:Dotcount = CInt(1000 / (1000 / Timer1.Interval))
Click on the radio button that is labled 'Random'. Right click , Properties.. Scroll to Checked and set it to true. this will set random as default ...
#3 - this is a little harder than the others..
First at the top under all the other Private delcarations add
(just above Public sub .....)Code:Private StartTime As Date
In the Button1_click and button3_click subs .. Just after the 'Timer1.Enabled = True' add
and the last one for this mod...Code:StartTime = Date.Now
in the timer1_tick sub just after 'DrawPicture()' add
this should stop the code after 30 seconds..Code:If StartTime.AddSeconds(30) < Date.Now Then
Timer1.Enabled = False
End If
Now to trigger on a canvas click.. add this sub (same like last time)
that should be it ....Code:Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
Timer1.Interval = CInt(TextBox1.Text)
Timer1.Enabled = Not Timer1.Enabled
StartTime = Date.Now
End Sub
Hi Gremmy,
Thanks again.
All of changes finally went in without an error message.
At first, the following code, adding it as a Sub, gave an error message:
error: Error 1 'Private Sub PictureBox1_Click(sender As Object, e As System.EventArgs)' has multiple definitions with identical signatures.Code:Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
Timer1.Interval = CInt(TextBox1.Text)
Timer1.Enabled = Not Timer1.Enabled
StartTime = Date.Now
End Sub
I suspected this meant that there are conflicting items for PictureBox1, so I deleted:
With that piece of code removed, the new one substituted for it, all seems to work OK.Code:Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
End Sub
Again, much thanks!
Kind Regards,
Hi,
I've been learning a lot and very much appreciate your help. Great progress! Getting a little more familiar with the VB UI, code window and editor.
I have been reading online about using Tracker Bars. Two of these would be useful in Form1:
(1) one slider to let the user set the length of time for the animation, ranging from a default of 30 seconds on the left (minimum) to 60 seconds on the right (maximum).
(2) a second slider, instead of a text input box, for the timer interval, ranging from a minimum of, for example, 800 ms to a maximum of, for example, 1200 ms.
While I can import 2 track bars into Form1 design, I'm not sure how to set up the code for each of these sliders to control the variables for length of time and timer interval.
I would appreciate any code suggestions. (And, once I can add these 2 track bars, I would probably need to figure out how to not only delete the text input box, any other irrelevant controls, but also any other old code that would now conflict with these new controls to govern these variables. Big challenge.)
I would welcome any suggestions on adding these, their code, and making this work without conflicts/errors.
Thanks very much.
Kind Regards,
Use both (for now). Have the SLIDER UPDATE EVENT in the Text Event, and vice-versa. When you move the slider, the text will update.
Also, set the upper and lower bounds of the slider, and use the same / as before, to come up with a % of the total range desired. Display the % in the textbox
Right this time you can make the changes .. i will guide you along you way...
#1 - Remove the Textbox from the form ... Right click - 'delete' (you will get a few errors about textbox1 not been defined, dont worry about them right now)
#2 - Add a slider (trackbar) to the form, right click and select 'properties' .. Name it TBinterval... change the minimum value to 100 and maximum value to 1000
#3 - Now find in the code all the lines that haveand change them toCode:Timer1.Interval = CInt(TextBox1.Text)
The errors you had before should be clearing as you change each one ...Code:Timer1.Interval = TBinterval.Value
#4 - delete the sub 'Private Sub TextBox1_KeyPress' as it is no longer needed (all 5 lines up to 'End Sub') .. this should take care of the last error....
#5 - Add another Trackbar to the form, right click - 'properties' ... Name it TBTime... change the minimum value to 30 and maximum value to 60
#6 - now find in the code the line that hasand change it toCode:If StartTime.AddSeconds(30) < Date.Now Then
this should take care of the changes needed to ad the sliders into the project ..Code:If StartTime.AddSeconds(TBTime.Value) < Date.Now Then
no other code needs to be changed or removed ..
Hi Gremmy,
Thanks again. I was able to make these changes successfully.
Continuing to better understand how to make things happen, add, delete, change controls and code.
Much thanks!
Kind Regards,
Here's one that's 15 times faster - sorry it's a bit late being posted!
Code:Option Strict On
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Runtime.InteropServices
Public Class Form1
Public Class syncObject
Public Sub New()
End Sub
End Class
Public syncOb As New syncObject()
Public Declare Sub AttachConsole Lib "Kernel32" (ByRef dwProcessId As Long)
Private Const ATTACH_PARENT_PROCESS As Integer = -1
Private WithEvents timer As System.Windows.Forms.Timer
Private frameCount As UShort = 0US
Private gCanvasWidth As UShort = (500US \ 8) * 8
Private gCanvasHeight As UShort = 300US
Private gDelay As Integer = 1 'ms
Private gProceed As Boolean = False
Private gImage As New System.Drawing.Bitmap(gCanvasWidth, gCanvasHeight, PixelFormat.Format1bppIndexed)
Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
gProceed = False
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.SetClientSizeCore(gCanvasWidth, gCanvasHeight)
Me.Text = "Click the form to start and stop"
SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.DoubleBuffer Or ControlStyles.ResizeRedraw Or ControlStyles.UserPaint, True)
AttachConsole(ATTACH_PARENT_PROCESS)
timer = New Timer()
timer.Interval = 1000
timer.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timer.Tick
Console.WriteLine("FPS: " & frameCount)
frameCount = 0
End Sub
Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
If gProceed Then
Me.FormBorderStyle=Windows.Forms.FormBorderStyle.Sizable
Me.WindowState=FormWindowState.Normal
gProceed = False
Else
Me.FormBorderStyle=Windows.Forms.FormBorderStyle.None
Me.WindowState=FormWindowState.Maximized
gCanvasWidth =CUShort((Me.Width \ 8) * 8)
gCanvasHeight= CUShort(Me.height)
gImage = New System.Drawing.Bitmap(gCanvasWidth, gCanvasHeight, PixelFormat.Format1bppIndexed)
gProceed = True
Dim vThread As New System.Threading.Thread(AddressOf GenerateStatic_Background)
vThread.IsBackground = True
vThread.Name = "Thread for generating static"
vThread.Start(New Object)
End If
End Sub
Private Delegate Sub DrawUpdate_Delegate(ByVal Arg As System.Object)
Private Sub DrawUpdate(ByVal Arg As System.Object)
gImage = DirectCast(Arg, System.Drawing.Bitmap)
Me.Invalidate()
End Sub
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
SyncLock (syncOb)
e.Graphics.DrawImageUnscaled(gImage, 0, 0)
End SyncLock
End Sub
'Super fast speed static thread!
Private Sub GenerateStatic_Background(ByVal Arg As System.Object)
Dim vImg As New System.Drawing.Bitmap(gCanvasWidth, gCanvasHeight, PixelFormat.Format1bppIndexed)
Dim bounds As Rectangle = New Rectangle(0, 0, vImg.Width, vImg.Height)
Dim m_BitmapData As System.Drawing.Imaging.BitmapData = vImg.LockBits(bounds, Imaging.ImageLockMode.ReadWrite, Imaging.PixelFormat.Format1bppIndexed)
Dim total_size As Integer = m_BitmapData.Stride * m_BitmapData.Height
vImg.UnlockBits(m_BitmapData)
Dim ImageBytes(total_size) As Byte
Dim vGen As New System.Security.Cryptography.RNGCryptoServiceProvider
Dim vSeed(3) As Byte
vGen.GetBytes(vSeed)
Dim vRand As Random = New Random(BitConverter.ToInt32(vSeed, 0))
While gProceed
frameCount += 1US
If frameCount Mod 5 = 1 Then System.Threading.Thread.Sleep(gDelay)
SyncLock (syncOb)
m_BitmapData = vImg.LockBits(bounds, Imaging.ImageLockMode.ReadWrite, Imaging.PixelFormat.Format1bppIndexed)
vRand.NextBytes(ImageBytes)
Marshal.Copy(ImageBytes, 0, m_BitmapData.Scan0, total_size)
vImg.UnlockBits(m_BitmapData)
End SyncLock
Try
Me.Invoke(New DrawUpdate_Delegate(AddressOf DrawUpdate), CType(vImg, System.Object))
Catch e As Exception
End Try
End While
End Sub
End Class