loading a form

genu

Well-known member
Joined
Jun 9, 2005
Messages
94
Programming Experience
1-3
How do you make it so it loads a form? for example: FORM1 is not visible, but its loading into memory and it has a progress bar. when the form is loaded into memory, the progressbar goes to 100% and then progressbar closes and form just shows..

thx in adavance
 
Like I said, from a Main procedure that you would then make the startup object for your app. The alternative would be to give your slow form a variable of type AnimationForm. Right after the call to MyBase.New in the constructor, instantiate the AnimationForm and call Show. Then as the last line in the Load event handler call Close on the AnimationForm:
VB.NET:
Private af As AnimationForm

Public Sub New()
	MyBase.New()

	Me.af = New AnimationForm
	Me.af.Show()

	InitializeComponent()
End Sub

Private Sub Form1_Load(...) Handles MyBase.Load
	'Do whatever here.

	Me.af.Close()
End Sub
It seems that you are basically creating a "splash screen". I've never created one myself, but it might be a good search term to use to see if anyone else has ideas for you. Also, I believe that splash screen funtionality may be built into VS 2005. I know there is at least a form template for a splash screen.
 
hey JM...that seems to work...but now for somereason...the animaiton form is messed up....its all black...I have no idea why it would affect it
 
It's probably that the AnimationForm isn't being drawn properly because the thread is busy building the main form. In the Activated event handler for the AnimationForm (which you'll have to create from the drop down lists in code view) put the following line of code:

Me.Refresh()
 
thanks JM that fixed it..now I can see the form and the animation...but now the animation does not play. so here is what i tried:

Private Sub loading_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
Me.Refresh()
l.Image = Bitmap.FromFile(System.AppDomain.CurrentDomain.BaseDirectory & "\images\preload.gif")
l.Refresh()
End Sub
 
When you say "image control", do you mean a PictureBox or something else? I've never tried displaying an animated GIF in a Windows app before. Perhaps only the first frame will be displayed unless you put it in a Web Browser control. I don't know. Try doing some experimentation. Does the animation show if you put it in a PictureBox without the other form loading in the background? If so, then it would seem that all the processing is being used to build the main form and there is none left for the animation. If this is the case then I'd say that the only option is multithreading. This will ensure that both tasks get some processing time.
 
I just did a simple test using an animated GIF file and a picturebox control. I loaded the gif in the Form Load event like so:
PictureBox1.Image = Image.FromFile(Application.StartUpPath & "\myGif.gif")
and it works fine. Maybe, your problem is you are setting the .Image source from Design Mode instead of doing it from Form Load. Try setting the image source in code instead of in the Form Designer and see if that fixes your problem.

However i attached the project as well so you can take a look at ...

Cheers ;)
 

Attachments

  • AnimatedGIFS.zip
    84.6 KB · Views: 59
the animated gif plays in the picture box, but it doesnt play when I made it show while the first form is loaded....

btw...can u tell me more about multithreading and how it works
 
I think you probably already know as much detail about multithreading as I'd be prepared to go into here. Time for you to do some reading I'd say. It all sounds like it's more trouble than its worth to me. Why not just show a static splash screen like so many other apps do? Your animation may be a nice touch and set you apart a little bit, but is it really worth the effort for something so trivial?
 
Then again it will be a great learning experience if you could figure it out. I agree though, time to read up. Something like multithreading just can't be fully covered in a single post.
 
Back
Top