|
This is the normal behavoir of the AsyncCallBack class. However, you should not let this tread modify any of the forms controls. This is an Windows UI rule and if you violate it you will pay the price . If you need to modify the forms controls during the call back do the following in the call back function.
Private Sub MyFunct() 'This is your callback function.
If Me.InvokeRequired = True Then
Me.Invoke("Your Delegate here") 'You can create a delegate that matches the call back
'and pass that in. After the invoke the function will be recalled and you will
'end up in the else part of this block
Else
'Do your work here this code is now executing on the UI thread.
End If
End Sub
Forever Developing
|
|
|
|
|
Ok! I made that last question because i have and app that raises an event in a thread and the handler is in the main form. The context of the handler is the thread which fired the event but this isn't happening with the async. Callback, thus my confusion. When i raise and event and check out the name of the current thread it gives me the thread that fired the event, if i check the name with the callback the name isn't from the thread that executed the beginInvoke().But if you say that this is the normal procedure fine by me One less problem for me to handle. But just to know, in what thread is it running? Is it a thread from the thread pool?A system thread?Just out of curiosity...
PS:Ye, i know that is a mistake to modify the UI from another thread.I found out the hard way Thanks for your concerne.
|
|
|
|
|
OK, this is what I belive is happing. The AsyncCallback is creating a new thread to do the work. I am not sure where this tread comes from but I belive it is from the thread pool Dot Net creates on startup. When you call BeginInvoke that tread starts on the function you have told it to execute. When it is finished it will call your finshed call back.
Forever Developing
|
|
|
|
|
Thanks a bunch.
That was what i though.
|
|
|
|
|
Help!
We're getting ready to deploy and I'm trying to build a Launcher application that will run on non-.NET platforms (COM or Win32).
Is there any way to build or compile a VB .NET application to output COM or Win32 code, or do I have to re-write this thing in Visual Studio 6 or InstallShield?
We're shipping tomorrow! Please help!
|
|
|
|
|
This depends on the Level of the Visual Studio Dot Net you have installed. If you have the ability to create C++ applications then you can create byte code exe's "Win32" in C++. If you are asking if a VB.Net application can be compiled as byte code, the answer to that is NO. If you use VB 6.0 then you will get semi-byte code but you will still need the vb runtime. The vb 6 runtime is installed by default for Windows 2000 and greater.
For a very simple launch I would create a native C++ program.
For a more complicated on I would probably use InstallShield. However, I am not sure what you mean by Launcher since InstallShield is a installer application.
Best of Luck
Forever Developing
|
|
|
|
|
I've found numerous examples on doing interop by creating a NEW Excel file, but would like to open an existing Excel file from VB.NET and interop with that. I've tried "guessing" how to modify the examples, but with no luck. Can anyone point me to an example of how to open an existing Excel file in VB.NET so I can interop with it?
Thanks for any help on this...
Hal in AZ
|
|
|
|
|
hey hal,
try...
myExcel.Workbooks.Open(pathToFile)
hope this helps
-jim
|
|
|
|
|
Jim,
Worked fine. Thanks very much! Funny that out of 3 different books no one mentioned this.
Thanks again,
Hal
Hal in AZ
|
|
|
|
|
Hi!
I have a doubt about how to handle an event asynchronously.I have an event and a handler for that event, but after the raiseevent instruction the handler runs synchronously and my thread has to wait for the handler to terminate it's code.How can i treat this event asynchronously using the raisevent instruction? And what about delegates?Is it easier to perform with delegates?
|
|
|
|
|
I am not sure but I don't think you can accomplish this with RaiseEvent. However, you can use the
AsyncCallback class. Check your local help files for more information on how to use this class.
Best of Luck
Forever Developing
|
|
|
|
|
Hi,
Is there a way to add file names from a folder on the hard drive to a list box and only show two types of file extensions ie txt and dat files using vb6.
Thanks
|
|
|
|
|
Here you go.
1) You need to add a referance to the Microsoft Scripting Runtime.
2) Add a Command Button to the form
3) Add a ListBox to the form
4) Have Fun
'///BEGIN CODE///
Private Sub Command1_Click()
Dim fso As New FileSystemObject
Dim fld As Folder
Dim fi As File
Dim I As Long
Set fld = fso.GetFolder("C:\")
For Each fi In fld.Files
If MatchesExtension("txt", fi.Name) Then
List1.AddItem fi.Name
End If
Next
End Sub
'Takes a filename and a file extension to match
'Works in reverse on the file name looking for the last
'period character. Once found the string is then compared to the
'passed in sFileExtension parameter.
Private Function MatchesExtension(sFileExtension As String, sFileName As String) As Boolean
Dim sChar As String
Dim sTemp As String
Dim I As Long
MatchesExtension = False
For I = Len(sFileName) To 1 Step -1
sChar = Mid(sFileName, I, 1)
If sChar = "." Then
If sTemp = sFileExtension Then
MatchesExtension = True
Else
MatchesExtension = False
End If
Exit For
End If
sTemp = sTemp & sChar
Next I
End Function
'///END CODE///'
Forever Developing
|
|
|
|
|
Thank you so much for this code. One question. Does this only wory for txt files or can other extensions be used. The two file extensions i'm trying to display is .cdimage and .dvdimage
I tried changing the "txt" in the code you gave me but it did not work.
Any ideas.
Once again Thank you for the code
|
|
|
|
|
Sorry about that. There is a small bug. I tested it with txt files.
Here is the fix you need to make.
In the MatchesExtension Function change
sTemp = sTemp & sChar
TO
sTemp = sChar & sTemp
if you want to add different/more file types you can do some thing like this in the
commandbutton click event
For Each fi In fld.Files
If MatchesExtension("cdimage", fi.Name) Then
List1.AddItem fi.Name
End If
If MatchesExtension("dvdimage", fi.Name) Then
List1.AddItem fi.Name
End If
'Keep adding file extensions. by duplicating the code above
Next
Forever Developing
|
|
|
|
|
Thank you so much. You the man
I'm wondering if i could ask you one more thing.
I was trying to change your code so that I could get it to do the following.
i need to separate the file name eg 50678.cdimage. so that the 50678 goes into one text box and the .cdimage goes into another text box. would you be able to help on this.
Thanks
|
|
|
|
|
Thank you so much. You the man
I'm wondering if i could ask you one more thing.
I was trying to change your code so that I could get it to do the following.
i need to separate the file name eg 50678.cdimage. so that the 50678 goes into one text box and the .cdimage goes into another text box. would you be able to help on this.
Thanks
|
|
|
|
|
Thank you so much. You the man
I'm wondering if i could ask you one more thing.
I was trying to change your code so that I could get it to do the following.
i need to separate the file name eg 50678.cdimage. so that the 50678 goes into one text box and the .cdimage goes into another text box. would you be able to help on this.
Thanks
|
|
|
|
|
I am not sure what you are asking for here.
You want to enter a file name in a text box and have the name and extension split into to differnet text boxes?
Forever Developing
|
|
|
|
|
You hit the nail on the head. I was trying with your code but with no success. Is this possible. If you could help I would be so greatful. This will make the program i'm working on work perfectly.
|
|
|
|
|
Add a command button.
Name it cmdSplit called split
Add 3 text boxes.
Name the first one txtFileName
Name the second one txtFile
Name the third one txtExtension
Private Sub cmdSplit_Click()
SplitFileNameOnDot (txtFileName.Text)
End Sub
Private Function SplitFileNameOnDot(sFileName As String)
Dim sChar As String
Dim sTemp As String
Dim sName As String
Dim sExtension As String
Dim bGotExtension As Boolean
Dim I As Long
For I = Len(sFileName) To 1 Step -1
sChar = Mid(sFileName, I, 1)
If bGotExtension = False Then
sExtension = sChar & sExtension
Else
sName = sChar & sName
End If
If sChar = "." Then
bGotExtension = True
End If
Next I
txtExtension.Text = sExtension
txtFile.Text = sName
End Function
Forever Developing
|
|
|
|
|
This is absoutly brilliant. My code is now finished. With out the help you gave me I don't know what i would have done. Wish I was a brainy as you.
Thank you so much
|
|
|
|
|
Is there any way that I can use the drag,drop effect for my scrabble game Im developing I want to drag a picture and drop onto a label and then show the picture in the target control that was previously in the sender?? Is there a way been searching for ages for help let me know please.....thanx!!
|
|
|
|
|
Here's how to drag an image back and forth between a couple of picture boxes:
Protected Overrides Sub OnLoad(ByVal e As EventArgs)
PictureBox1.Image = Image.FromFile("MyImage.bmp")
PictureBox1.AllowDrop = True
PictureBox2.AllowDrop = True
End Sub
Private dragSource As PictureBox
Private Sub PictureBox_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) _
Handles PictureBox1.MouseMove, PictureBox2.MouseMove
'Initiate a drag if left mouse button is down
If e.Button = MouseButtons.Left Then
dragSource = CType(sender, PictureBox)
DoDragDrop(CType(sender, PictureBox).Image, DragDropEffects.Move)
End If
End Sub
Private Sub PictureBox_DragEnter(ByVal sender As Object, ByVal e As DragEventArgs) _
Handles PictureBox1.DragEnter, PictureBox2.DragEnter
If (Not dragSource Is Nothing) AndAlso (Not sender Is dragSource) Then
e.Effect = DragDropEffects.Move
End If
End Sub
Private Sub PictureBox_DragDrop(ByVal sender As Object, ByVal e As DragEventArgs) _
Handles PictureBox1.DragDrop, PictureBox2.DragDrop
If (Not dragSource Is Nothing) AndAlso (Not sender Is dragSource) Then
CType(sender, PictureBox).Image = dragSource.Image
dragSource.Image = Nothing
dragSource = Nothing
End If
End Sub
Hope this helps
Tom
|
|
|
|
|
hi all
i am currently working on winforms. i am facing a problem in resizing the window once it has been maximized.
Well i have a form with 2 buttons. one for maximising and the other for restoring the form to its original size/any specified size.
in the click event of the first button.. i set the forms's WindowState to FormWindowStae.Maximized. now when i click the second button i want to change the form size back to its original size before being maximized or to some size.i know i can restore the size of the form by using the restore button in the ControlMenu..i dont want to use it. i want to use the second button to do it. i tried setting new values to the Size property of the Form but is of no use.
can anyone please help me in finding as to how i can change the form's size once it has been maximized through code?
thanks and regards
|
|
|
|