How to fire the Save/Open and Cancel button of a Open/SaveFileDialog?
How to fire the Save/Open and Cancel button of a Open/SaveFileDialog?
Click on it :D:D:D. No no, firing events is a thing I'm looking for... In VB6 we could do this by SendMessage Windows API, but now??
I am not at my machine now, but I am sure you can easily RaiseEvent in VB.NET and also you can easily send message. Will post the code soon.
Please skip if this is too remedial but I don't know what you know...
As far as I have been taught you don't fire the events of common dialogs, you run them and examine what they return like so:
VB Code:
Dim myStream As Stream Dim openFileDialog1 As New OpenFileDialog() openFileDialog1.InitialDirectory = "c:\" openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" openFileDialog1.FilterIndex = 2 openFileDialog1.RestoreDirectory = True [b]If openFileDialog1.ShowDialog() = DialogResult.OK Then[/b] myStream = openFileDialog1.OpenFile() If Not (myStream Is Nothing) Then ' Insert code to read the stream here. myStream.Close() End If End If
What the above code does is first set up the objects used (particularly the OpenFileDialog) and then, where the bold is, it shows the OpenFileDialog and examines the return from it, which is expected to be a member of the DialogResult enumeration, one of which is OK (others are Cancel, Yes, No, etc). Note that the code that actually reads the file is absolutely nothing to do with the OpenFileDialog itself.
it's working fine now! thank you.