![]() |
|
[.NET] [TuT] How to use all Dialogs in VB - Font, Color, Open & Save! - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [.NET] [TuT] How to use all Dialogs in VB - Font, Color, Open & Save! (/showthread.php?tid=247223) |
[TuT] How to use all Dialogs in VB - Font, Color, Open & Save! - Soul Collector - Jan 26, 2010 How to use Dialogs in VB! Written by 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 OpenFileDialogAs 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 OpenFileDialogThis 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 ThenSaveFile 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 SaveFileDialogOkay, 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 SaveFileDialogWell 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 StringSo 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 ThenFont 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 FontDialogNow 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 FontDialogThis 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 ThenColor 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 ColorDialogNow, I will explain how this works. Pretty simple & basic =) How this works? This will call Color Dialog: Code Dim color123 As New ColorDialogThis code will check if user checked color and clicked OK, thenbit will change color of text: Code If color123.ShowDialog = Windows.Forms.DialogResult.OK ThenWell that was all for today, more will be added really soon. I will edit post, because I need to go to school now. 😝 * - $weet - Jan 26, 2010 Well you wanted me to bump your thread AGAIN?? ... Go figure stop asking me to bump your fuckin threads. You only help when rep is involved and its just so fuckin annoying now. I message all the time with simple, one word answer questions and you ignore me up until the point where you make a new thread and need me to bump it. take you fake 172 rep and continue fool people to think your an "awesome guy". hope you liked my bump,lemme know if you feel like i am "hurting your image". * - Ex-Coder - Jan 26, 2010 Wow. That's easy. I never though that. Thanks mate ! * - KnobMoinster - Jan 26, 2010 another great tut man, vb.net just keeps getting easier by day. * - Carnival - Jan 26, 2010 You are the best tut writer I have ever seen on HF. Keep posting such great stuff. It helped me a lot. Thanx * - Widow's Peak - Jan 26, 2010 Thanks Soul. I'm loving all the vb.net help. * - Soul Collector - Jan 26, 2010 Thanks, glad you like it 🙂 More will be added really soon :) * - --([-S7N-])-- - Jan 26, 2010 Thanks Soul Collector. Helpful. I'm really confused about dialogs. * - Joey K - Jan 26, 2010 Great post man. I love your threads. I have bookmark'd them all. =] * - pubmaster - Jan 26, 2010 Great tut soul . Bravo Bravo ! * - Soul Collector - Jan 27, 2010 Glad you like it, thanks for comments :) * - Batch - Feb 25, 2010 If I was trying to right a text file by using the SaveFileDialog tut how would I go about adding contents to it? * - CustomiZer - Mar 12, 2010 An end if is missed in the end of the first code : CORRECTED : Code Dim OpenMe As New OpenFileDialog* - catchyanow - Mar 23, 2010 OMFG THANKS :D 👍👍👍👍👍👍👍👍👍👍 * - Soul Collector - Mar 24, 2010 (Mar 12, 2010 08:37 AM)icyberhack Wrote: An end if is missed in the end of the first code : My code is perfect. |