简体   繁体   English

表单集中在某个位置时,我该如何调用函数?

[英]How do I call a function when a form is focused on?

I'm working in Visual Studio using Windows Form applications. 我正在使用Windows窗体应用程序在Visual Studio中工作。

I've got a Car Rental application that allows the user to update booking information from a SSMS database. 我有一个“汽车租赁”应用程序,该应用程序允许用户从SSMS数据库更新预订信息。 The main form displays all bookings after a certain date. 主表单显示特定日期之后的所有预订。 When the user updates a booking, I have to change the date being used in order to get the app to refill the list, showing the updated information. 当用户更新预订时,我必须更改使用日期,以使应用重新填充列表,并显示更新的信息。

The simplest way to have the app do this automatically is to have it refill the list every time the form is focused on. 让应用程序自动执行此操作的最简单方法是,每次关注表单时,它都会重新填充列表。 That is, when it becomes the active form. 也就是说,当它成为活动形式时。

How do I do this? 我该怎么做呢?

add the event handler in designer.cs file. 将事件处理程序添加到designer.cs文件中。 You can either use Activated or Shown event as per your design. 您可以根据设计使用Activated或Shown事件。

this.Activated += Form1_Activated;

Do the required stuff here 在这里做所需的东西

void Form1_Activated(object sender, System.EventArgs e)
{
    Method_To_Do_On_Form_Activated();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM