By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,473 Members | 1,267 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,473 IT Pros & Developers. It's quick & easy.

problem with loading an instance of a form before a database call

P: 2
Hi there,

I have a strange problem with creating an instance of a form which I want to use as a custom message box.
The idea is that when the user clicks the button to perform a database search, an instance of this form is loaded.

The background image of the form never displays but the text on the form does - but it all works fine when I remove the call to the database.

I also tried putting a "proper" VB message box just before the database call and when I block it this way it seems to allow the image to draw on the form.
I also tried using a timer delay before the database call - just a couple of seconds to see if that would allow it time to draw the image.

Can anyone please explain to me where I am going wrong?

Expand|Select|Wrap|Line Numbers
  1.  
  2.   Dim msg As New frmMsg
  3.   msg.TopMost = True
  4.   msg.BackgroundImage = My.Resources.msgBoxPlate
  5.   msg.Show()
  6.   doDataBaseCall()
  7.   msg.Close()
  8.  
  9.  

This is the onLoad code from the "message form"
Expand|Select|Wrap|Line Numbers
  1.  
  2.   txtMsg.Text = "Please Wait"
  3.   Me.BackgroundImage = My.Resources.msgBoxPlate
  4.   Me.BackgroundImageLayout = ImageLayout.Center
  5.  
  6.  
I am using dot net 3.5 and Visual Studio 2008
Thanks for any assistance that ye can provide!
Aug 9 '10 #1

✓ answered by Aimee Bailey

If the database query or queries are large, then you may find the dialog wont paint properly, a simple fix maybe just sticking a...

Expand|Select|Wrap|Line Numbers
  1. Application.DoEvents();
  2.  
before you call your query. give it a go, and then let me know what happens ok :)

Share this Question
Share on Google+
2 Replies


Aimee Bailey
Expert 100+
P: 197
If the database query or queries are large, then you may find the dialog wont paint properly, a simple fix maybe just sticking a...

Expand|Select|Wrap|Line Numbers
  1. Application.DoEvents();
  2.  
before you call your query. give it a go, and then let me know what happens ok :)
Aug 10 '10 #2

P: 2
Hi Aimee,

Thanks very much for your reply. I gave that a try and it works a charm!

I had never heard of the DoEvents() function before, I looked it up on MSDN, so for anyone else who encounters this problem:

http://msdn.microsoft.com/en-us/libr....doevents.aspx

And from that:

If you call DoEvents in your code, your application can handle the other events. For example, if you have a form that adds data to a ListBox and add DoEvents to your code, your form repaints when another window is dragged over it. If you remove DoEvents from your code, your form will not repaint until the click event handler of the button is finished executing.


best regards
Dermot
Aug 10 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.