
Signature
Richard A. Michaels
Eaton Vance
IT - Software Development Services
rmichaels@eatonvance.com
Assuming your using Visual Studio.NET....
1. Drag a simple button control onto your workspace - label it "Browse..."
2. Drag a special control from the toolbox called "openFileDialog" onto your
form - it doesn't have a visual representation like a button, but Visual
Studio will show it for you in a "tray" down in the lower area of your
screen. It will have a default name of "openFileDialog1" - just leave it
there for now.
3. Double-Click the "Browse.." button you created in step 1, which will
launch you into code view, inside of an onclick event handler for that button.
4. Now, inside of the event handler for the browse button, you will write
code which will reference the openFileDialog1 object.
- specify the filter you want to use:
openFileDialog1.Filter = "Text Files (*.txt) | *.txt | All Files (*.*) | *.*";
- specify the title you want user to see in the dialog box that you will
create:
openFileDialog1.Title = "Select a file to load:";
- optionally, you can set a default file location to begin the dialog
browser within
openFileDialog1.FileName = "C:\\Program Files\\someText.txt";
5. Also, within the same event handler, you will finally add code that will
actually launch the dialog box. After the user interacts with the dialog box
and clicks ok, you will want to access the openFileDialog1.FileName property
again (as it will now have changed to whatever the user specified). Use that
FileName property to load up your richTextBox. In the following code, I
actually launch the dialog box within the "if" conditional clause, and
evaluate the result:
if(openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
richTextBox1.Load(openFileDialog1.FileName);
}
> Hello all,
> I'm working on a WinForms app and I need to provide my users with the
[quoted text clipped - 5 lines]
> Richard Michaels
> rmichaels@eatonvance.com
Richard A Michaels - 27 Oct 2005 13:34 GMT
Brian,
Your solution doesn't solve my issue.
I've implemented drag and drop with the RichText control and that works
fine. However, if you look at applications such as Outlook, you can drag
and drop and insert attachments. It's the inserting of the file which I'm
seeking to do. The LoadFile method of the RichTextBox control will
overwrite anything that is in the control. This is not the desired
functionality I'm seeking.
Richard
> Assuming your using Visual Studio.NET....
>
[quoted text clipped - 51 lines]
>> Richard Michaels
>> rmichaels@eatonvance.com