|
-
July 23rd, 2008, 05:10 AM
#1
[RESOLVED] Picture boxes and threading
I am designing a program that is supposed to find test examples for a problem according to certain rules. I have a small form with some text boxes for rule input. When a button is pressed this starts a new thread with the necessary calculations running at below normal priority so as not to interfere with my other processes while it does the calculations in the background.
Within this thread a new form is opened with a picture box. The results of the calculations are supposed to be viewed in this window until another valid example is found (then that one should be shown). However, when I move the window to see the original window (so that I can see the progress being made) or even just click on the window, the contents of the window go white and do not return even when other results should be drawn.
How can I change my code so that the picture remains and changes even if the window is moved around? Also, how do I prevent the closing of the picture window (Form2) from closing the other window running the calculations (Form1)?
Below is an outline of the code:
Code:
Public Class Form1
Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button.Click
'Some initializing
Dim t As Threading.Thread
t = New Threading.Thread(AddressOf Me.Calculations)
t.Priority = ThreadPriority.BelowNormal
t.Start()
'Some more stuff
End Sub
Public Sub Calculations
Dim F2 As New Form2
Do While <more calculations are to be made>
'Some calcuations
If <the calculations are valid> Then
If Not F2.Created Then
F2.Show()
End If
AddHandler F2.PictureBox.Paint, AddressOf F2.PictureBox_Paint
F2.PictureBox.Refresh()
End If
Loop
End Sub
End Class
Public Class Form2
Public Sub PictureBox_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs)
'Draw a whole bunch of things
End Sub
End Class
SharpDevelop 3.1
.NET Framework 3.5
Windows XP (SP3)
-
July 23rd, 2008, 07:03 AM
#2
Re: Picture boxes and threading
Add this line in ..
Code:
AddHandler F2.PictureBox.Paint, AddressOf F2.PictureBox_Paint
F2.PictureBox.Refresh()
Application.DoEvents()
End If
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
WPF Articles : 3D Animation 1 , 2 , 3
Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.
-
July 23rd, 2008, 07:30 AM
#3
Re: Picture boxes and threading
Thanks Boet
That works perfectly!
SharpDevelop 3.1
.NET Framework 3.5
Windows XP (SP3)
-
July 23rd, 2008, 12:45 PM
#4
Re: Picture boxes and threading
No Problem ... I'm glad you solved it ...
But do us a small favour, Please mark this thread resolved.. (Thread tools, just above the first post) ...
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
WPF Articles : 3D Animation 1 , 2 , 3
Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.
-
July 24th, 2008, 03:31 AM
#5
Re: Picture boxes and threading
Cool, will do so. Could you help me though with the problem of making the windows independent of each other (other than the info sent to Form2), so that if I close one, the other stays open. For example, when closing F2 while another picture could still be drawn?
SharpDevelop 3.1
.NET Framework 3.5
Windows XP (SP3)
-
July 24th, 2008, 06:40 AM
#6
Re: Picture boxes and threading
Okay for this, i need to know a bit more about whats happening ... it sounds like what you are saying is that when form2 opens form1 closes ??
Can you explain it a little more ...
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
WPF Articles : 3D Animation 1 , 2 , 3
Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.
-
July 24th, 2008, 07:57 AM
#7
Re: [RESOLVED] Picture boxes and threading
The following happens. When I initiate the program, Form1 opens with a whole bunch of text boxes for input. When I press a button, these inputs are used to create data. If a valid data set is created, the output is printed to a picture box on Form2.
If I close F1 during the calculations, the form closes but the calculations continue (in the thread) and any valid data sets are still drawn to F2. I want it to stop, but for F2 to remain open.
If I close F2 with F1 open or not, the program crashes when a valid data set is found and attempt is made to draw it. How do I prevent that from happening?
I hope that makes it clearer.
SharpDevelop 3.1
.NET Framework 3.5
Windows XP (SP3)
-
July 24th, 2008, 08:33 AM
#8
Re: [RESOLVED] Picture boxes and threading
Okay .. i think i get it ..
Give me a little time to lookup a few things..
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
WPF Articles : 3D Animation 1 , 2 , 3
Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|