Create a Custom MessageBox - C#, Visual Basic (VB.NET) & WinForms / Modern Flat UI

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello today i am going to show you how to create a custom message box as some have been asking me to do for a long time well basically this custom message box does everything a standard message box does for example it has a caption text buttons and returns the value selected by the user in the dialog box for that you have these top five constructors to display a message box depending on the needs of the case for example show a message box with only text by default it has an ok and close button in the following case it displays a message box with the specified text and caption similarly by default it displays an ok button it should be mentioned that the size of the message box depends on the size of the text in the next method the message box displays a specified text caption and buttons foreign [Music] it is also possible to set an icon just like you do in a native message box but in this case the color of the message box depends on the type of icon finally there is the option to set the default button for the message box for example set the first button as the default button however in the above cases the first button will always be the default button so this method allows to change the order of the default selected button this allows the user to execute the click event simply by pressing the enter key without the need to use the mouse somehow that speeds up user actions all right that's it for the introduction now let's move on to the code well i don't have a lot of time lately i'm very busy so i'm not going to do the coding from scratch since it would take a long time and here i already have the whole project done however it is not complicated at all it's really simple and easy to understand i will also leave a link in the video description for the project download okay first we create this form for the message box we added a panel for the title bar a close button a label for the caption and text a picture box for the icon panels for the sections and three buttons before continuing i want to show you the standard windows message box class here you simply have 21 overloads of the show method this method returns a dialog result each method has different parameters to show a message box it is generally used until the default button is set in itself there are 11 different methods to display a message box the rest is repeated to set the object that owns the message box this class only contains static methods to show a message box the user interface is a native form of the operating system so it is not possible to inherit and customize which is why it is necessary to create a form for the custom message box and recreate all the options and functions of a native message box all right the code does the following it defines fields for the primary color and border size of the form the primary color property allows you to set the border and title bar color of the message box it has five constructors that allows you to present the message box in different ways basically how to display it as set in the show method you can add more constructors if you need to set more display options well the following private methods are also defined for example the method of setting the message box buttons here you simply set the location a text and dialog result for each button as set in the constructor [Music] the method of setting the default button here the button specified in this forms constructor is selected the method of setting the message box icon the icons are in the project resources for each type of button a different colors set for the message box there is also the set size method this method allows you to set the appropriate size of the message box based on the size of the text and finally a method to set some properties of the form controls [Music] each constructor defines how the message box should be displayed for example setting the specified text and setting the default values for the message box if it is not specified [Music] [Applause] all right that's it for the dialogue user interface then we have this class this component takes care of instantiating and displaying the custom message box it's basically a copy of the standard messagebox class the main function of this class is to display the message box without the need to instantiate the form for that it defines static methods and returns a dialog result as shown in the following example as many of you know we can save the message box dialog resulter and do some functions or tasks based on the action selected by the user however it is optional we can just display a message box [Music] we can also replace without any inconvenience with a native message box [Music] every time you bring me clothes [Music] or you can replace an existing standard message box with this custom message box [Music] [Laughter] [Music] additionally you can change the accent color and border size of the message box however the accent color of the message box changes based on the specified icon type well that's all in this video i hope you liked it i wish you a merry christmas and a happy new year until next time [Music]
Info
Channel: RJ Code Advance EN
Views: 31,843
Rating: undefined out of 5
Keywords: Windows Form, C#, VB, .NET, Software, HTML, Modern Forms, software, computer, technology, design of modern user interfaces, visual basic, php, java, design flat login, software development, web programming, information systems development, JavaScript, Visual Basic, Software Patterns, Architecture Patterns, Design Patterns, Language Patterns, Software Engineering, Systems, Web pages, mvc, layers, objects, POO, object-oriented programming, mysql, mariadb, .Net Framework, Custom Controls, SQL
Id: XWM0VnTXksY
Channel Id: undefined
Length: 8min 8sec (488 seconds)
Published: Tue Dec 21 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.