In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how C # Winform refreshes windows. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
When writing a program, you sometimes encounter a new window, fill in some information and then refresh the original window. For example, add a new administrator to the new window, click OK to submit, and then refresh the list of administrators in the original window. It sounds simple as long as you call the function that binds the administrator list, but it is not possible to call that function in the new window, but you can pass the delegate. The code is as follows:
C # Winform refresh window step 1
Original form:
Using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using PAT.DataAccess; using System.Collections; namespace PAT.WinForm {public partial class RoleManage: Form {public delegate void UpdateComoboxAsyscHandler () / / as the delegate to update the role list asynchronously, / / * uses the empty parameter list and is defined as / / public / / the function to update the list, that is, the function private void UpdateComobox () {WinFormControlBuilder.Instance.BindRoles (comboBoxRoles) to be bound by the delegate defined above } private void buttonAddRole_Click (object sender, EventArgs e) {/ / AddRole is the window for adding new roles, where the newly written delegate is passed in AddRole addRole = new AddRole (new UpdateComoboxAsyscHandler (UpdateComobox)); addRole.Show ();}
C # Winform refresh window step 2
New form:
Using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using PAT.DataAccess; using System.Threading; namespace PAT.WinForm {public partial class AddRole: Form {public AddRole () {InitializeComponent ();} private RoleManage.UpdateComoboxAsyscHandler UpdateComoboxAsyscHandler / / write a new constructor with arguments to the previously written delegate public AddRole (RoleManage.UpdateComoboxAsyscHandler _ updateComoboxAsyscHandler) {InitializeComponent (); this.UpdateComoboxAsyscHandler = _ updateComoboxAsyscHandler / / delegate assignment} private void buttonSubmit_Click (object sender, EventArgs e) {/ update database operation / / Accunt_Role account_Role = new Accunt_Role (); account_Role.RoleName = textBoxRoleName.Text PatDataContext.Accunt_Roles.InsertOnSubmit (account_Role); patDataContext.SubmitChanges (); UpdateComoboxAsyscHandler (); / / call the delegate to update the original list MessageBox.Show ("role added successfully!") ; this.Dispose (); / / close window}
Examples of effects are as follows:
After clicking OK, it will be displayed in the start window list:
This makes it possible to add new roles to the new window, close the new window and refresh the list of roles in the original window.
Thank you for reading! This is the end of the article on "how to refresh the window of C# Winform". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.