[TuT] How to use all Dialogs in VB - Font, Color, Open & Save! - Printable Version +- Support Forums (https://www.supportforums.net) +-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87) +--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18) +---- Forum: Visual Basic and the .NET Framework (https://www.supportforums.net/forumdisplay.php?fid=19) +---- Thread: [TuT] How to use all Dialogs in VB - Font, Color, Open & Save! (/showthread.php?tid=5629) Pages:
1
2
|
[TuT] How to use all Dialogs in VB - Font, Color, Open & Save! - BlackSpider - 04-06-2010 How to use Dialogs in VB! Written by BlackSpider/Soul Collector
Hello everyone. Well I decide to make thread about Windows dialogs in Visual Basic. It's really simple, but I see people still asking how to use them. Well in this tutorial we are going to learn how to use OpenFile Dialog, SaveFile Dialog, Font Dialog and ColorDialog. Basically we are going to make basic notepad with cool features. Well if you have any question please post here, and yea you can use for example some image browser or something like that. I will explain everything about dialogs so let's start. Please post comment's with feedback and your ideas. Thanks OpenFile Dialog Well you can add OpenFile dialog from toolbox or just use with Using or use it as String (which is better). So you will just need to add TextBox1 and Button1, just drag them from ToolBox. So now I will first teach you basic, double click Button1 and write following code: Code: Dim OpenMe As New OpenFileDialog As you can see, we don't need OpenFile Dialog, we will just use it as New OpenFileDialog which is much better & faster way. Now I will explain how this work. How this works? With this code you declare our OpenFileDialog: Code: Dim OpenMe As New OpenFileDialog This is filter of our OpenFileDialog, for this example I used only .exefiles. So OpenFileDialog can see only .exe files: Code: OpenMe.Filter = "Executable file(*.exe)|*.exe" This code check is OK button clicked, so if it is and file selected then add .exe file's pathbin textbox1. If it's something else then show error message and exit sub: Code: If OpenMe.ShowDialog = Windows.Forms.DialogResult.OK Then SaveFile Dialog For this Dialog we will use Textbox1 too, Button1 and Textbox2. Same as OpenFile Dialog but with second TextBox, we will use New code too because it's much easier and better. Alright let's start. Well for this example we will save text from TextBox2. This is code for saving: Code: Dim SaveMe As New SaveFileDialog Okay, I will exaplain now how this works, let's start. How this works? This code will call SaveFileDialog, same like OpenFileDialog's code: Code: Dim SaveMe As New SaveFileDialog Well this is different, we will need this because when we save file, we usually use "/File.txt" which save in same folder with program. In this case we replace the name of Variable with that code so it will save in folder which we choosed with SaveDialog: Code: Dim FileLink As String So this code will check if you clicked OK button and selected valid folder to save file it will link it. Well this won't really save file, this will just link it to some StreamWriter (example) so it will save it on that location: Code: If SaveMe.ShowDialog = Windows.Forms.DialogResult.OK Then Font Dialog Well this one can be really useful in some text editors. Just add Button1 and Textbox2 and that's all. Same like OpenFileDialog we will use New code too. Lets start, double click Button1 and write: Code: Dim Font12 As New FontDialog Now I will explain how this work. Really simple, but still maybe someone don't understand. :3 How this works? This code will call FontDialog: Code: Dim Font12 As New FontDialog This code will open FontDialog and if user clicked ok and selected font then change a font of Textbox1: Code: If Font12.ShowDialog = Windows.Forms.DialogResult.OK Then Color Dialog Ok for this dialog we need Button1 and Textbox1. I wont explain a lot about it, because It's actually same like any other dialog. So I will skip this tutorial, ok double click Button1 and write (P.S. This will change color of Text): Code: Dim color123 As New ColorDialog Now, I will explain how this works. Pretty simple & basic =) How this works? This will call Color Dialog: Code: Dim color123 As New ColorDialog This code will check if user checked color and clicked OK, thenbit will change color of text: Code: If color123.ShowDialog = Windows.Forms.DialogResult.OK Then Well that was all for today, more will be added really soon. I will edit post, because I need to go to school now. :tongue: RE: [TuT] How to use all Dialogs in VB - Font, Color, Open & Save! - shubhamm - 04-08-2010 Soul Collector THanks for this This will help me in my Programs RE: [TuT] How to use all Dialogs in VB - Font, Color, Open & Save! - RaZoR03 - 04-18-2010 Helped alot. Thanks RE: [TuT] How to use all Dialogs in VB - Font, Color, Open & Save! - macas5 - 05-03-2010 Many thanks to you! This helps me very much RE: [TuT] How to use all Dialogs in VB - Font, Color, Open & Save! - JesusOfSuburbia - 05-04-2010 Thank's very much....very usefull foor beginners! RE: [TuT] How to use all Dialogs in VB - Font, Color, Open & Save! - NathanE - 05-09-2010 thanks for this tutorial man... RE: [TuT] How to use all Dialogs in VB - Font, Color, Open & Save! - Julie - 05-10-2010 The SaveFileDialog code helped me, thanks RE: [TuT] How to use all Dialogs in VB - Font, Color, Open & Save! - //Pretextâ„¢ - 05-18-2010 Helped me man, Thanks a lot. RE: [TuT] How to use all Dialogs in VB - Font, Color, Open & Save! - Cybr - 05-28-2010 I love when tutorials actually explain the code, instead of a huge block of unexplained, confusing nonsense. RE: [TuT] How to use all Dialogs in VB - Font, Color, Open & Save! - Unrated - 05-28-2010 (05-28-2010, 05:52 PM)Cybr Wrote: I love when tutorials actually explain the code, instead of a huge block of unexplained, confusing nonsense. Same. I tend to understand when people do that. Then I can make my own crap. |