Welcome Guest.   Make a donation to an author on the site August 29, 2014, 03:02:34 AM  *

Please login or register.
Or did you miss your validation email?


Login with username and password (forgot your password?)
Why not become a lifetime supporting member of the site with a one-time donation of any amount? Your donation entitles you to a ton of additional benefits, including access to exclusive discounts and downloads, the ability to enter monthly free software drawings, and a single non-expiring license key for all of our programs.


You must sign up here before you can post and access some areas of the site. Registration is totally free and confidential.
 
The N.A.N.Y. Challenge 2010! Download 24 custom programs!
   
   Forum Home   Thread Marks Chat! Downloads Search Login Register  
Pages: [1]   Go Down
  Reply  |  New Topic  |  Print  
Author Topic: Tutorial: Visual C# For Beginners - Part 3 (With Pretty Pictures!!!)  (Read 2583 times)
Stephen66515
Animated Giffer in Chief
Honorary Member
**
Posts: 2,449



see users location on a map View Profile Give some DonationCredits to this forum member
« on: May 28, 2011, 08:11:13 PM »

Welcome To Part 3:

I'm sure that if you have completed Parts 1 & 2 then you are keen to continue with your project, so lets get cracking with that File Menu!

For this, you are going to need to add the following items:

  • openFileDialog
  • saveFileDialog
  • printDialog
  • printDocument



To add these to your project, click and drag them onto the bottom menu bar


Now you have added them all you will have something that looks like this:


Brilliant!

Now...Remembering what you learned in Part 2 you need to go ahead and click the "File" button and then double click the "Open" button

Add:

Formatted for C# with the GeSHI Syntax Highlighter [copy or print]
  1. string OFile = "";
  2.  
  3.            openFileDialog1.InitialDirectory = "C:";
  4.            openFileDialog1.Title = "Open a Text File";
  5.            openFileDialog1.FileName = "";
  6.            openFileDialog1.Filter = "Text Files|*.txt|Word Documents|*.doc";
  7.            if (openFileDialog1.ShowDialog() != DialogResult.Cancel)
  8.            {
  9.                OFile = openFileDialog1.FileName;
  10.                richTextBox1.LoadFile(OFile, RichTextBoxStreamType.PlainText);
  11.            }
Which should give you:

 
Formatted for C# with the GeSHI Syntax Highlighter [copy or print]
  1. private void openToolStripMenuItem_Click(object sender, EventArgs e)
  2.        {
  3.            string OFile = "";
  4.  
  5.            openFileDialog1.InitialDirectory = "C:";
  6.            openFileDialog1.Title = "Open a Text File";
  7.            openFileDialog1.FileName = "";
  8.            openFileDialog1.Filter = "Text Files|*.txt|Word Documents|*.doc";
  9.            if (openFileDialog1.ShowDialog() != DialogResult.Cancel)
  10.            {
  11.                OFile = openFileDialog1.FileName;
  12.                richTextBox1.LoadFile(OFile, RichTextBoxStreamType.PlainText);
  13.            }
  14.        }

Now you want to go back and double click "Save"

Add:

Formatted for C# with the GeSHI Syntax Highlighter [copy or print]
  1. string SFile = "";
  2.  
  3.            openFileDialog1.InitialDirectory = "C:";
  4.            openFileDialog1.Title = "Save Your Notes!";
  5.            openFileDialog1.FileName = "";
  6.            openFileDialog1.Filter = "Text Files|*.txt|Word Documents|*.doc";
  7.            if (openFileDialog1.ShowDialog() != DialogResult.Cancel)
  8.            {
  9.                SFile = saveFileDialog1.FileName;
  10.                richTextBox1.SaveFile(SFile, RichTextBoxStreamType.PlainText);
  11.            }

Which gives you:

Formatted for C# with the GeSHI Syntax Highlighter [copy or print]
  1. private void saveToolStripMenuItem_Click(object sender, EventArgs e)
  2.        {
  3.            string SFile = "";
  4.  
  5.            openFileDialog1.InitialDirectory = "C:";
  6.            openFileDialog1.Title = "Save Your Notes!";
  7.            openFileDialog1.FileName = "";
  8.            openFileDialog1.Filter = "Text Files|*.txt|Word Documents|*.doc";
  9.            if (openFileDialog1.ShowDialog() != DialogResult.Cancel)
  10.            {
  11.                SFile = saveFileDialog1.FileName;
  12.                richTextBox1.SaveFile(SFile, RichTextBoxStreamType.PlainText);
  13.            }
  14.        }

Now for the "Print" option:

Add:

Formatted for C# with the GeSHI Syntax Highlighter [copy or print]
  1. printDialog1.Document = printDocument1;
  2.            if (printDialog1.ShowDialog() == DialogResult.OK)
  3.            {
  4.                printDocument1.Print();
  5.            }

Which gives you:

Formatted for C# with the GeSHI Syntax Highlighter [copy or print]
  1.       private void printToolStripMenuItem_Click(object sender, EventArgs e)
  2.        {
  3.            printDialog1.Document = printDocument1;
  4.            if (printDialog1.ShowDialog() == DialogResult.OK)
  5.            {
  6.                printDocument1.Print();
  7.            }
  8.        }


Now we are going to extend our "Exit" button.  Go to the designer, click "File", double click "Exit" and delete 'Application.Exit();'

Add the following code in its place:

Formatted for C# with the GeSHI Syntax Highlighter [copy or print]
  1.           if (MessageBox.Show("Are you sure you want to quit?", "Exit", MessageBoxButtons.OKCancel) == DialogResult.OK)
  2.            {
  3.                Application.Exit();
  4.            }

Which gives you the following:

Formatted for C# with the GeSHI Syntax Highlighter [copy or print]
  1.       private void exitToolStripMenuItem_Click(object sender, EventArgs e)
  2.        {
  3.            if (MessageBox.Show("Are you sure you want to quit?", "Exit", MessageBoxButtons.OKCancel) == DialogResult.OK)
  4.            {
  5.                Application.Exit();
  6.            }
  7.        }

Awesome!!!!!

Save your project and go play with it!  You can even run a print from it if you own a printer!!!



Thats all for this tutorial.

In the next we will add code for "Save As" and "Print Preview".

We will also make a start with our Tools Menu!  Even adding things like Fonts and Colours!!!


* 4.png (16.78 KB, 652x591 - viewed 162 times.)
« Last Edit: May 29, 2011, 10:48:01 AM by Stephen66515 » Logged

No trees were harmed during the creation of this message.  Millions of electrons, however, were terribly inconvenienced

"Think left and think right and think low and think high. Oh, the things you can think up if only you try!" - Dr. Seuss
Fuppiz
Participant
*
Posts: 1

View Profile Give some DonationCredits to this forum member
« Reply #1 on: June 05, 2012, 01:43:02 PM »

Hello,

i was looking around to find some tutorials about c# and i saw your post. i read some of your tutorials. i understood mainly what what some stuff but i think you sould make  explication. like what eatch part of the code mean and what is mainly hapening in the program. well its a good job you are doing here you gave me some ideas so tnx smiley
Logged
Stephen66515
Animated Giffer in Chief
Honorary Member
**
Posts: 2,449



see users location on a map View Profile Give some DonationCredits to this forum member
« Reply #2 on: June 05, 2012, 01:53:55 PM »

Hello,

i was looking around to find some tutorials about c# and i saw your post. i read some of your tutorials. i understood mainly what what some stuff but i think you sould make  explication. like what eatch part of the code mean and what is mainly hapening in the program. well its a good job you are doing here you gave me some ideas so tnx smiley

If you need any specific peices of code explaining, feel free to ask...

To be perfectly honest...I completely forgot about these lol, I have moved on to Delphi programming lately but am more than willing to continue helping people with this smiley

Thanks for the good feedback smiley

-Stephen
Logged

No trees were harmed during the creation of this message.  Millions of electrons, however, were terribly inconvenienced

"Think left and think right and think low and think high. Oh, the things you can think up if only you try!" - Dr. Seuss
Pages: [1]   Go Up
  Reply  |  New Topic  |  Print  
 
Jump to:  
   Forum Home   Thread Marks Chat! Downloads Search Login Register  

DonationCoder.com | About Us
DonationCoder.com Forum | Powered by SMF
[ Page time: 0.088s | Server load: 0.11 ]