Lỗi không hiện lên showdialog trên visual studio 2023
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support. Show Tutorial: Add code to the picture viewer Windows Forms app in Visual Studio
In this articleApplies to: Visual Studio Visual Studio for Mac Visual Studio CodeIn this series of three tutorials, you'll create a Windows Forms application that loads a picture and displays it. The Visual Studio Integrated Design Environment (IDE) provides the tools you need to create the app. To learn more, see Welcome to the Visual Studio IDE. Controls use C# or Visual Basic code to take the actions associated with them. In this third tutorial, you learn how to:
PrerequisitesThis tutorial builds on the previous tutorials, Create a picture viewer application and Add UI controls to the picture viewer. If you haven't done those tutorials, go through them first. Add event handlers for your controlsIn this section, add event handlers for the controls that you added in the second tutorial, Add controls to a picture viewer application. Your application calls an event handler when an action takes place, such as selecting a button.
Methods, including event handlers, can have any name that you want. When you add an event handler with the IDE, it creates a name based on the control's name and the event being handled. For example, the Click event for a button named showButton is called
9 or
0. If you want to change a code variable name, right-click the variable in the code and then choose Refactor > Rename. All instances of that variable in the code are renamed. For more information, see Rename refactoring. Write code to open a dialog boxThe Show a picture button uses the OpenFileDialog component to display a picture file. This procedure adds the code used to call that component. The Visual Studio IDE offers a powerful tool called IntelliSense. As you type, IntelliSense suggests possible code.
It's the best practice to always comment your code. Code comments make it easier to understand and maintain your code in the future. Write code for the other controlsIf you run your application now, you can select Show a picture. Picture Viewer opens the Open File dialog box, where you can select a picture to display. In this section, add the code for the other event handlers.
Run your applicationYou can run your application at any time, while you're writing it. After you add the code in the previous section, the Picture Viewer is complete. As in the previous tutorials, use one of the following methods to run your application:
A window with the title Picture Viewer appears. Test all the controls.
Next stepsCongratulations! You've completed this series of tutorials. You've done these programming and design tasks in the Visual Studio IDE: |