|
Hey i am trying to dynamically create a form in background worker but the after the run the application the form appears as 'not responding?
Please advise
Can we create a form in background worker thread and update the controls in the same thread?
Here is how i am doing it...
Private Sub DoJob(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs)
Dim f As New System.Windows.Forms.Form
Dim label1 As New System.Windows.Forms.TextBox
f.Size = New System.Drawing.Size(487, 416)
f.Name = "Form6"
f.Text = "Form6"
f.Location = New System.Drawing.Point(0, 0)
label1.Name = "text1"
label1.Size = New System.Drawing.Size(100, 20)
label1.Location = New System.Drawing.Point(54, 37)
f.BackColor = Color.Gray
f.Activate()
f.Controls.Add(label1)
f.Show()
End Sub
After I run it can see form6 ,but in not i responsive state.What am I doing wrong here?
|
|
|
|
|
Hi,
This is a threading issue. Try to move your code from DoWork to a new sub e.g.
1.
Private Sub CreateNewForm()
Dim f As New System.Windows.Forms.Form
Dim label1 As New System.Windows.Forms.TextBox
f.Size = New System.Drawing.Size(487, 416)
f.Name = "Form6"
f.Text = "Form6"
f.Location = New System.Drawing.Point(0, 0)
label1.Name = "text1"
label1.Size = New System.Drawing.Size(100, 20)
label1.Location = New System.Drawing.Point(54, 37)
f.BackColor = Color.Gray
f.Activate()
f.Controls.Add(label1)
f.Show()
End Sub
2.
At the member level add:
Private Delegate Sub delCreateNewForm()
3.
In the DoWork sub invoke the CreateNewForm sub:
Private Sub DoJob(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs)
Dim d As New delCreateNewForm(AddressOf CreateNewForm)
Me.Invoke(d)
End Sub
Hope this helps
|
|
|
|
|
hey thanks for the help it is working.
So now i will be generating many of the same form this way by using a list of background workers.So will each form be running in its own thread?
Also how can i update the form's gui from the DoWork sub?
|
|
|
|
|
Sohaib_A wrote: So now i will be generating many of the same form this way by using a list of background workers.So will each form be running in its own thread?
No, they won't. Perhaps you didn't get the implied answer: You can't create a window in a background thread, you have to use Invoke to create the window in the GUI thread. (It might be possible to create a window from a thread, but then the thread would have to run a message pump just as the GUI thread does. That would be pointless as you already have a message pump.)
Sohaib_A wrote: Also how can i update the form's gui from the DoWork sub?
The same way; you use Invoke to run the code in the GUI thread.
Alternatively, you put updates in a synchronised queue, and have a timer in the GUI thread read updates from the queue and display them.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Got a reply from Gucha, but its not heklping - same syntax error - could you be simpler? How do you mean"overwriting Text1"? Could you write a ample code?
This table is key to solving other querrie/
Thanks
Am trying to create a simple VB form which can act as a names database... so far the code I have written is thus:
Private Sub Command_Change()
Text1=Text2&""&Text3""&Text4
End Sub
Private Sub Text_Change()
Text2=Lastname
End Sub
Private Sub Text_Change()
Text3=Firstname
End Sub
Private Sub Text_Change()
Text4=Middlename
End Sub
Am getting syntax error reports on text 1.
the original problem was:
Assume the full name of a person in the order of "lastname, firstname, middlename" is text1. Write a VB Progran that will break the fukll name into three components and display he lastname, firstname and middlename in text2, text3, text4 respectively.
Write a program that will capitalize the first letter in a textbox, and make others o be lower case
Write a program that will capitalize the first letter of each word in a textbox, and mke others o be lower case
H
|
|
|
|
|
oburaochola wrote: Got a reply from Gucha
Then reply to Guffa and don't start a new thread.
|
|
|
|
|
Private Sub Command_Change()
Text1=Text2&""&Text3""&Text4
End Sub
Learn to use the spacebar, it adds readability to your code. This is your original "Command_Change" with extra spaces. Can you see your typo that caused the "Syntax Error"?
Text2 & "" & Text3 "" & Text4
I'll give you a hint; Syntax Errors occur when the computer cannot understand what the code is supposed to do. That's usually a typo. In your case, it's right after "Text3". You probably meant this;
Private Sub Command_Change()
Text1 = Text2 & "" & Text3 & "" & Text4
End Sub
Enjoy
I are troll
|
|
|
|
|
Am trying to create a simple VB form which can act as a names database... so far the code I have written is thus:
Private Sub Command_Change()
Text1=Text2&""&Text3""&Text4
End Sub
Private Sub Text_Change()
Text2=Lastname
End Sub
Private Sub Text_Change()
Text3=Firstname
End Sub
Private Sub Text_Change()
Text4=Middlename
End Sub
Am getting syntax error reports on text 1.
the original problem was:
Assume the full name of a person in the order of "lastname, firstname, middlename" is text1. Write a VB Progran that will break the fukll name into three components and display he lastname, firstname and middlename in text2, text3, text4 respectively.
Write a program that will capitalize the first letter in a textbox, and make others o be lower case
Write a program that will capitalize the first letter of each word in a textbox, and mke others o be lower case
H
|
|
|
|
|
When you ask about a homework assignment, you should clairly state this in your question. Assume that your teacher also knows about internet...
You can't assign a string to a TextBox variable. You should use the Text property of the TextBox controls, i.e. Text1.Text instead of just Text1 .
You have got the assignment statement backwards. What's on the right side is assigned to the variable on the left side, so instead of getting the value from Text1 and put in Text2, Text3 and Text4 you are concatenating the values and overwriting the value in Text1.
To split up a string you should look at the Split method in the String class.
For the other assignments, look at the Substring method and the ToUpper method.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hello Guffa,
Thanks for your response. This is not a home woerk, but am self tutoring... I dont seem to understand your explanation... could you pleas write a sample code based on your explanation?
Also some codes I see in old tutorials start with
and not as the other one, Could you explain the diffrence?
I
|
|
|
|
|
Ok, here are some examples:
Assigning a string to a textbox:
Text2.Text = "Hello"
Splitting a string:
Dim sentence As String = "This is just a test"<br />
Dim words As String() = sentence.Split(" "C)
The array words now contains five strings; "This", "is", "just", "a" and "test".
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hi,
I have a project containing a .exe and .dll project.
I want to show a form to the user from the dll.
How would I do this?
I am using VB.NET 2008.
|
|
|
|
|
Add it as a reference in your project, create its object and use it.
The word "politics" describes the process so well: "Poli" in Latin meaning "many" and "tics" meaning "bloodsucking creatures."
|
|
|
|
|
In the .dll create a public method like "ShowSetupForm" to show the form as desired (IE: normal, dialog, etc). From the .exe, instantiate the object and then call the public method to launch the form.
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
Hi,
I have inserted an image from an existing file which I want to close. I have tried using dispose() command (shown below); however it gives an error. Could some one suggest what would be the command to close the file after the image has been displaced?
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
'Temperature button pressed
Dim iImage As Image
iImage = Image.FromFile("C:\Aman\ZedGraph\temp.jpeg")
'PictureBox1.Image = Image.FromFile("C:\Aman\ZedGraph\temp.jpeg")
PictureBox1.Image = iImage
iImage.Dispose()
End Sub
Thanks
Aman
|
|
|
|
|
The problem is you're using Image.FromFile to load the image. This will lock the file for the lifetime of the Image object.
Instead, you want to do this:
Dim pic As Bitmap
Using fs As New FileStream("C:\Aman\ZeqGraph\temp.jpeg", FileMode.Open, FileAccess.Read)
pic = New Bitmap(fs)
End Using
PictureBox1.Image = pic
|
|
|
|
|
Wasn't this just asked? LOL.
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
Yep, Jan 2 by TheComputerMan.
Amazing, noone ever actually reads the forums...
|
|
|
|
|
Thanks very much Dave, it works now.
|
|
|
|
|
I have never used SQL, and am trying to learn.
I have downloaded the SQL Server 2008 Express with Advanced Items.
(Boy that took quite some time to download(Several attempts) and then to configure and install!)
I purchased the SQL Server for Dummies.
Here is where I am running into trouble. It, (The Book) talks of the Management studio, but this appears not to be part of the download.
(Am I doing something wrong?)
Also, Is there a recommended site showing how to use SQL within VB directly? (Need to create one, add items, create links between data etc).
It is important to remember that I know NOTHING about SQL, and need to start from first priciples and be walked through each stage with my hand held.
Recommendations and help please!
------------------------------------
"The greatest tragedy in mankind's entire history may be the hijacking of morality by religion"
Arthur C Clarke
|
|
|
|
|
Dalek Dave wrote: Here is where I am running into trouble. It, (The Book) talks of the Management studio, but this appears not to be part of the download.
(Am I doing something wrong?)
I don't believe that it is. It comes with the other editions tho'.
Dalek Dave wrote: Also, Is there a recommended site showing how to use SQL within VB directly? (Need to create one, add items, create links between data etc).
There are a multitude of ways of using SQL in VB. If you simply want to just get started the the most basic is to create a SqlConnection , a SqlCommand and have it ExecuteReader to get a SqlDataReader back or ExecuteNonQuery if you are not selecting anything. There are many tutorials on this. Look up ADO.NET, and you should also get examples by looking up the highlighted terms in the MSDN Library.
Finally, if you help with your connection strings, try http://www.connectionstrings.com/[^]
Hopefully this will give you some pointers as to where to look.
|
|
|
|
|
Dalek Dave wrote: I have downloaded the SQL Server 2008 Express with Advanced Items
Dalek Dave wrote: It, (The Book) talks of the Management studio, but this appears not to be part of the download
According to this[^] (which is what I assume you downloaded) it does have something called "Management Studio Basic" which I would guess is in your Start->Programs menu somewhere. I would guess that this will give you enough for the basic operations to manage SQL Server Express.
|
|
|
|
|
Hi DD!
Management studio is a separate download. Go here[^]
Hope this helps.
[Mod]
But see discussion below before deciding.
[/Mod] Last modified: 2hrs 27mins after originally posted --
Honi soit qui mal y pongs - Evil to he who thinks it stinks
|
|
|
|
|
That's the wrong version of SQL Server. Dalek Dave has SQL Server 2008 express. If he uses that then there will be features he cannot use because the tools don't match the database engine. Also, there are issues with mismatched tools and installation order.
|
|
|
|
|
Thanks for that. I wasn't aware of any issues re installation order.
It is the Management Studio that I use and it seems to work OK with SQLExpress 2005 and SQLExpress 2008. As to missing features, I cannot comment as this is the first version of the manager that I have used in earnest, although I had the manager for 2005 installed previously.
When I downloaded it I chose that one because it did not have a version number in the name, i.e. it was not labelled SQLExpress Manager 2005, or whatever.
When I installed it it complained because I had 2005 Manager installed, so I uninstalled 2005 version and it installed OK. As I said earlier it looks to me as though it works fine, although I am no expert, as you can probably tell.
Honi soit qui mal y pongs - Evil to he who thinks it stinks
|
|
|
|