|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Problem with creating Multiple instances of Form in VB!
Hello!
In my currently under-development application, I need to create multiple instances of a Form with no title bar (ControlBox = False). I do it this way ... Private oForm as frmNote Public Sub CreateFormInstance() Set oForm = new frmNote oForm.Show End Sub This code works perfect and creates the multiple instances of Form called frmNote. However, I'm facing one very interesting problem with it! When a new instance of frmNote is created and it's hidden behind any already open Application window, whenever I click frmMain (the main form which has a button to create instances of frmNote) Title bar, the instance of frmNote, which was behind a certain application window comes in front of the Application window automatically! Why this happens so? I don't want this to happen. Any work-around for this problem? To put my problem in a better way, I have created a sample VB Project, which has similar functionality coded. I request you to please download the attached ZIP file and run it from your IDE. All the necessary information to mimic my problem situation is written on the Form. I don't understand why this problem occur as I never faced such issue before! Eagerly waiting for your reply ... Thanks & Regards, Ruturaj. |
|
#2
|
|||
|
|||
|
Ok, so it looks like no one is interested in this topic! So, should I post my solution on this forum or not?! hmmm ...
|
|
#3
|
||||
|
||||
|
Yeah, this VB forum is pretty dead. I dont tend to get replies for any of my VB related questions, but they are all pretty hardcore, lol.
__________________
LozWare Website Directory Whooo! Free submissions, no recip needed. I'm a nice guy
Last edited by LozWare : June 24th, 2006 at 12:32 PM. |
|
#4
|
||||
|
||||
|
I am pretty sure that when you give focus to a window, you are giving focus to that entire thread. In otherwords, when you have multiple windows running on the same thread (like in your sample program), and you lose focus of them, then regain focus of one of the windows, then all of the other windows will come into focus too.
There may be simpler ways to resolve this, but the only thing that I can think of is making each form run on a seperate thread... or a seperate process if you dont want to run down the road of multithreading in VB. Last edited by LozWare : June 24th, 2006 at 11:47 AM. |
|
#5
|
||||
|
||||
|
Ok, I felt sorry for you, so I spent a few minutes compiling a multithreaded solution.
There are 2 processes: 1 that handles the main form, and 1 that handles the child forms. Each child form runs on a separate thread to one-another. The 2 processes communicate via ActiveX, so it's pretty straight-forward when it comes to transferring data between the forms. Read the captions on the ChildForm Window for a longer explanation. INSTRUCTIONS ON HOW TO RUN: 1) Open up the NewWindow.vbp project, and compile the EXE 2) Open up the MainApp.vbp project, and run it from your IDE. You don’t need to compile the MainApp project, but you can if you want. However, you MUST compile the NewWindow project, otherwise it won’t work properly. 3) Come back to this thread and give me some REP! :-) |
|
#6
|
|||
|
|||
|
Thanks for your reply and time you spent for me! I'm downloading your solution now.
|
|
#7
|
|||
|
|||
|
Great! It works fine. Thanks.
|
|
#8
|
||||
|
||||
|
That’s ok!
P.S. Welcome to the world of multithreading! There are more advantages to it than just independent form orders! |
|
#9
|
|||
|
|||
|
Yes, you are right! I just saw it and found very interesting. After your example, I wrote one simple module as a template for me to check how much I have understood Multithreading and I could make the program run fine. I tried to fill two Listboxes with 5000 items simultaniously in my multithreading.
However, when I tried to use the same function in AddressOf for creation of two different threads, the program failed. Also, I found that I can not pass param to function while using as AddressOf. So, can you tell me how to use same function with some ByVal or ByRef params passed to it? What I tried is ... wrote one single function with iListIndex As Integer as function argument. My concept was to pass 1 and create a thread to fill Listbox_1; then pass 2 and create a thread to fill Listbox_2. But This does not go hand in hand! I found that both the threads are filling same Listbox (Listbox_2) and Listbox_1 remained empty. It's interesting but really of very restricted use if separate function for each thread to handle is required! |
|
#10
|
||||
|
||||
|
Sorry, I have read your post over a few times, but Im not entirely sure what you mean. Could you post a sample project?
|
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > Problem with creating Multiple instances of Form in VB! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|