Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private readonly IRegionService _regionService;
- _regionService = new RegionService();
- _regionService.DisplayUserControl += _regionService_DisplayUserControl;
- private void _regionService_DisplayUserControl(object sender, UserControl e)
- {
- CloseUserControl();
- // Add new user control to content area
- contentArea.Children.Add(e);
- }
- private void LoadUserControl(string controlName)
- {
- _regionService.LoadUserControl(controlName);
- }
- public class RegionService : IRegionService
- {
- public event EventHandler<UserControl> DisplayUserControl;
- public void LoadUserControl(string controlName)
- {
- Type ucType = null;
- UserControl uc = null;
- //if (ShouldLoadUserControl(controlName))
- //{
- // Create a Type from controlName parameter
- ucType = Type.GetType(controlName);
- if (ucType == null)
- {
- MessageBox.Show("The Control: " + controlName
- + " does not exist.");
- }
- else
- {
- // Close current user control in content area
- // NOTE: Optionally add current user control to a list
- // so you can restore it when you close the newly added one
- //CloseUserControl();
- // Create an instance of this control
- uc = (UserControl)Activator.CreateInstance(ucType);
- // Display control in content area
- DisplayUserControl?.Invoke(this, uc);
- }
- //}
- }
- }
- public interface IRegionService
- {
- event EventHandler<UserControl> DisplayUserControl;
- void LoadUserControl(string controlName);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement