Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Controls / October 2005

Tip: Looking for answers? Try searching our database.

Insert Files into RichTextBox Control

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Microsoft - 29 Sep 2005 13:12 GMT
Hello all,
I'm working on a WinForms app and I need to provide my users with the
ability to insert files into the RichTextBox control.  I have successfully
implemented the drag & drop as well as being able to Paste a document  into
the control.  However, I can't seem to find a way to allow the users to
navigat to a file they would like to insert and insert that file.

Richard Michaels
rmichaels@eatonvance.com

Signature

Richard A. Michaels
Eaton Vance
IT - Software Development Services
rmichaels@eatonvance.com

brian - 27 Oct 2005 04:10 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.