Advertisement
Guest User

region service

a guest
Nov 18th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.96 KB | None | 0 0
  1.         private readonly IRegionService _regionService;
  2.             _regionService = new RegionService();
  3.             _regionService.DisplayUserControl += _regionService_DisplayUserControl;
  4.  
  5.         private void _regionService_DisplayUserControl(object sender, UserControl e)
  6.         {
  7.             CloseUserControl();
  8.             // Add new user control to content area
  9.             contentArea.Children.Add(e);
  10.         }
  11.  
  12.  private void LoadUserControl(string controlName)
  13.         {
  14.             _regionService.LoadUserControl(controlName);
  15. }
  16.  
  17.  public class RegionService : IRegionService
  18.     {
  19.         public event EventHandler<UserControl> DisplayUserControl;
  20.  
  21.  
  22.         public void LoadUserControl(string controlName)
  23.         {
  24.             Type ucType = null;
  25.             UserControl uc = null;
  26.  
  27.             //if (ShouldLoadUserControl(controlName))
  28.             //{
  29.                 // Create a Type from controlName parameter
  30.                 ucType = Type.GetType(controlName);
  31.                 if (ucType == null)
  32.                 {
  33.                     MessageBox.Show("The Control: " + controlName
  34.                                                     + " does not exist.");
  35.                 }
  36.                 else
  37.                 {
  38.                     // Close current user control in content area
  39.                     // NOTE: Optionally add current user control to a list
  40.                     //       so you can restore it when you close the newly added one
  41.                     //CloseUserControl();
  42.  
  43.                     // Create an instance of this control
  44.                     uc = (UserControl)Activator.CreateInstance(ucType);
  45.  
  46.                     // Display control in content area
  47.                     DisplayUserControl?.Invoke(this, uc);
  48.                 }
  49.             //}
  50.         }
  51.     }
  52.  
  53.  public interface IRegionService
  54.     {
  55.         event EventHandler<UserControl> DisplayUserControl;
  56.         void LoadUserControl(string controlName);
  57.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement