LogoLogo
WinForms to WebPowerBuilder to .NETPowerBuilder to Java
  • WebMAP Documentation | Mobilize.Net
  • WinForms
    • Introduction
    • Getting Started
    • Conversion Process
    • Post-Conversion
    • Extend or Modify the Converted Application
      • NoWebMap Forms Winforms
        • How to add a new Form
        • Adding the created form to the migrated App
        • Interacting with the application data
        • Call the custom API
        • Interaction between the no webmap added Form and the WebMap components
      • Adding a component
      • Adding a component dynamically
      • Add a new control model
      • Switching CSS theme
      • Adding new window
      • Conversion Configuration
        • WebMAP configuration file
        • Stub Filter
      • Adding Non-WebMap Angular Forms
      • Adding FrontEnd Handler to a ToolStripMenuItem
      • Changing ToolStripButton icons
      • Adding new items to existing toolbar
      • Adding FrontEnd element properties and JS listeners
      • Adding FrontEnd output handlers
      • Access FrontEnd components
      • Create custom components based on existing WebMap Component
      • Override FrontEnd methods
    • Assessment Mode
    • Errors and Troubleshooting
      • How to resolve broken reference problems with VBUC
    • Portability
    • Glossary
    • Release Notes
    • Internal Demos
    • Known Issues
    • WinForms DCP
  • WebForms
    • Introduction
    • Overview
    • Desktop Compatibility Platform (DCP)
      • Pages and Master Pages
      • GridView and DataList data synchronization
      • HTTP objects
    • Post-Conversion
    • Extend or Modify the Converted Application
      • Adding FrontEnd validator
      • Adding Page
      • Adding MasterPage
    • Designer classes on WebForms Conversion Tool
    • Errors and Troubleshooting
      • How fix Solution when have been added website from filesystem without project file
    • Release Notes
  • PowerBuilder to .Net
    • Introduction
    • Getting Started
      • Conversion Tool
    • Desktop Compatibility Platform (DCP)
      • Data Manager
    • Reports
      • Report Rendering in Modernized Code
      • ReportWatcher Service Configuration
      • Data Manager to RDL Conversion
      • Reporting Service Internals
      • Troubleshooting
  • PowerBuilder to Java
    • Introduction
    • Getting started
    • Post-Conversion
      • Setup PBJava Environment
      • Architecture
      • App Start
    • Glossary
    • Errors
    • Glossary
    • FAQ
      • How to create a new Control
      • How to create a new Screen
      • What is the Mobilize.WebMAP.CoreServices.All?
      • What is the DesignerAttribute?
      • What is the InterceptedAttribute?
      • What is the InterceptedAttribute?
      • What is the ObservableAttribute?
      • What is the Mobilize.Weaving.WebMAPExtensions.All?
  • General
    • FrontEnd
      • Documentation
        • Webforms Angular Components
          • Web Components
            • Base Components
              • BaseValidator Component
            • KendoUI Components
              • CompareValidator
              • CustomValidator
              • RegularExpressionValidator
              • RequiredFieldValidator
              • ValidationSummary
          • Directives
          • AJAX Web Components
            • AjaxCalendar
            • AjaxModalPopupExtender
          • Ajax Interaction Services
        • Client Core
          • WebMap's Client Core
        • Angular Client
          • Introduction
          • WebMap Service
          • WebMap Interceptor Service
        • Base Components
          • Introduction
          • Components
            • Container
            • Control
            • ControlContainer
            • FormsContainer
            • Loading
            • Stub
        • Winforms Angular Components
          • Web Components
            • Base Components
              • Control Component
              • Form Container
              • Grid Component
              • Style
            • KendoUI Components
              • AdoDataControl
              • Button
              • C1TrueDBGrid
              • CheckBox
              • CheckedListBox
              • ComboBox
              • ContextMenuStrip
              • DataGridView
              • DataGridViewFlex
              • DateTimePicker
              • FileDialog
              • GroupBox
              • Label
              • ListBox
              • ListView
              • MaskedTextBox
              • MessageBox
              • NumericUpDown
              • Panel
              • PictureBox
              • PrintDialog
              • ProgressBar
              • RadioButton
              • RichTextBox
              • StatusStrip
              • Stup
              • TabControl
              • TabPage
              • TextBox
              • Timer
              • ToolStrip
              • TreeView
              • WebBrowser
              • Window
            • JQuery Web Components
          • WebMap FrontEnd Architecture
          • Migrated Structure
          • Setup
            • Front-End setup and compilation
            • Components Manual
            • Browser Support
            • Unit Test Manual
            • Development Process
            • Setup AOT/JIT Compilation
          • Decorators
            • Server Event
          • Conventions
            • Application Structure and NgModules
            • Coding
            • Components
            • Data Service
            • Directives
            • Lifecycle hooks
            • Names
            • Services
        • PowerBuilder Kendo Components
          • Base Components
            • base-component
            • column-control
            • controlcontainer
          • Data Manager Componets
            • base-data-manager
            • data-manager-control
            • data-manager-control-base
            • dw-checkbox
            • dw-column
            • dw-complexNumericMaskComponent
            • dw-compute
            • dw-date-time-edit-mask
            • dw-dropdowndatawindow
            • dw-edit
            • dw-edit-mask
            • dw-radio-button
            • dw-simple-numeric-edit-mask
            • dw-string-edit-mask
            • dw-time-edit-mask
          • Window Components
            • basemask
            • graphics
            • w-checkbox
            • w-command-button
            • w-complex-numeric-mask
            • w-date-time-edit-mask
            • w-dropdownlistbox
            • w-group-box
            • w-line
            • w-listbox
            • w-maskedtextbox
            • w-mdiclient
            • w-menu
            • w-multiline
            • w-picture
            • w-picture
            • w-radiobutton
            • w-rectangle
            • w-simple-numeric-edit-mask
            • w-single-line-edit
            • w-statictext
            • w-string-edit-mask
            • w-time-edit-mask
            • w-toolbar
            • w-toolbaritem
            • w-user-object
            • w-window
          • Services
            • DmInteractionService
          • DataManagerEvents
          • FocusManager guide
      • Api Documentation
        • WebMap Silverlight
        • WfNetC1Components
        • WebFormsComponents
      • Guides
        • Setup NPM package registry in the workspace
        • How to Setup WebMap Applications To Run Over SubDomains or WebApplications In IIS
        • Deploy several WebMap Apps in the same Server
        • Update to Angular 16
        • Appearance
          • How to change the CSS
          • How to override the style for a component
        • Component maintenance
          • How link WebMap package to the migrated Application
          • How to resolve broken reference problems with VBUC
          • How to test a local WebMap Components package
          • How to add a new component in a migrated application
          • How to update a component
          • Dynamic Control Support
          • How to add new set of component with a different provider
          • How to test your component in the playground
          • Tools
        • WMLogger
          • How to use the WMLogger's instance
          • How to change log's level
          • How to add log tags
        • Integration test
        • Setup WebMap Applications to Run Front-End And Back-End In Separates Sites
          • Setup WebMap Applications To Run Front-End And Back-End In Separates Sites in Production (IIS)
        • Setup Migrated WebMap Applications To Run Front-end & Back-end In Separates Sites (Only development)
        • Initial Set Up
          • Software to Install
          • Necessary Repositories
      • Errors
      • Version Notes
        • Client Core
        • Angular Client
        • Web Base Components
        • Winforms Angular Components
        • PowerBuilder Kendo Components
      • Licenses
        • Client Core
        • Angular Client
        • Base Components
        • PB Kendo Components
        • WFNet Kendo Components
        • WebForms Components
        • WFNet Access Components
        • WFNet Janus Components
        • WFNet C1 Components
        • Silverlight wms-framework
        • Silverlight i-components
    • BackEnd
      • WebMAP From Scratch
      • Setup
      • DCP: Desktop Compatibly Platform
        • Overview
        • Library Bundles
          • Bundle Library
            • Create an Observable Object
          • Bundle DTO
            • DTO: Data Transfer Objects
              • Creating a DTO
            • Mappers
              • Create Mappers
            • Observable Wrappers
              • Create an Observable Wrapper
            • API/Controllers
      • Architecture
      • Weaving on WebMAP
      • Glossary
      • FAQ
        • How to create a new Control
        • How to create a new Screen
        • What is the Mobilize.WebMAP.CoreServices.All?
        • What is the DesignerAttribute?
        • What is the InterceptedAttribute?
        • What is the Mobilize.Extensions.Logging.RollingFile?
        • What is the ObservableAttribute?
        • What is the Mobilize.Weaving.WebMAPExtensions.All?
      • Licenses
        • PBNet DCP
        • WebFormsDCP
        • WFNet DCP
        • CoreServices
        • CoreServicesCommon
    • Request and Response
  • SCALABILITY
    • Introduction
    • Microservices
    • Containerizing a WebMap .Net Application with Docker
    • Vertical scalability
Powered by GitBook
On this page

Was this helpful?

  1. WinForms
  2. Extend or Modify the Converted Application

Adding FrontEnd Handler to a ToolStripMenuItem

The following section will guide you through this case scenario, in which you would need to add a click handler for a ToolStripItem that is implemented in the FrontEnd code (instead of triggering a request to the BackEnd).

Let's assume that the developer already has a migrated webmap app, where there is a form named Form1, it has a BindingNavigator control named bindingNavigator1 which has a ToolStripItem named newlyAddedButton.

The following file is named "form1.component.html".

<div *ngIf="model">
    <wm-window [model]="model" id="Form1" class="MigratedApp_Form1">
        <ng-template let-model>
            <div class="Form1">
                <wm-bindingnavigator #bindingNavigator1 id="bindingNavigator1" [model]="model.bindingNavigator1" class="bindingNavigator1" tabindex="1"></wm-bindingnavigator>
            </div>
        </ng-template>
    </wm-window>
</div>

To accomplish this requirement, the modifications must be done in the form1.component.ts file (showed below).

import { Component, ChangeDetectorRef, ElementRef
, Output, Renderer2, ViewEncapsulation} from "@angular/core";
import { EventData, dataTransfer} from "@mobilize/base-components";
import { FormComponent} from "@mobilize/winforms-components";
import { WebMapService} from "@mobilize/angularclient";
@Component({
   selector : "form1",
   styleUrls : ["./form1.component.css"],
   templateUrl : "./form1.component.html",
   encapsulation : ViewEncapsulation.None
})
@dataTransfer(["Form1"])
export class Form1Component extends FormComponent {
   protected webServices : WebMapService;
   constructor (wmservice : WebMapService,
   changeDetector : ChangeDetectorRef,render2 : Renderer2,elem : ElementRef) {
      super(wmservice,changeDetector,render2,elem);
   }
}
import { Component, ChangeDetectorRef, ElementRef
, Output, Renderer2, ViewEncapsulation, ViewChild} from "@angular/core";
import { EventData, dataTransfer} from "@mobilize/base-components";
import { FormComponent} from "@mobilize/winforms-components";
import { WebMapService} from "@mobilize/angularclient";
@Component({
   selector : "form1",
   styleUrls : ["./form1.component.css"],
   templateUrl : "./form1.component.html",
   encapsulation : ViewEncapsulation.None
})
@dataTransfer(["Form1"])
export class Form1Component extends FormComponent {
   protected webServices : WebMapService;
   constructor (wmservice : WebMapService,
   changeDetector : ChangeDetectorRef,render2 : Renderer2,elem : ElementRef) {
      super(wmservice,changeDetector,render2,elem);
   }
   
  @ViewChild("bindingNavigator1", { static: false })
  bindingNav: any;
}

2. Bind the AfterViewInit lifecycle hook in the Form1Component in order to add the logic needed to bind the click of the ToolsStripItem element.

import { Component, ChangeDetectorRef, ElementRef
, Output, Renderer2, ViewEncapsulation, ViewChild, AfterViewInit} from "@angular/core";
import { EventData, dataTransfer} from "@mobilize/base-components";
import { FormComponent} from "@mobilize/winforms-components";
import { WebMapService} from "@mobilize/angularclient";
@Component({
   selector : "form1",
   styleUrls : ["./form1.component.css"],
   templateUrl : "./form1.component.html",
   encapsulation : ViewEncapsulation.None
})
@dataTransfer(["Form1"])
export class Form1Component extends FormComponent implements AfterViewInit {
   protected webServices : WebMapService;
   constructor (wmservice : WebMapService,
   changeDetector : ChangeDetectorRef,render2 : Renderer2,elem : ElementRef) {
      super(wmservice,changeDetector,render2,elem);
   }
   
  @ViewChild("bindingNavigator1", { static: false })
  bindingNav: any;
  
  ngAfterViewInit(): void {
   // logic to bind the toolstripitem goes here.
 }
}

The logic goes in the AfterViewInit method because when this lifecycle hook is executed the variable used to reference the BindingNavigator control is defined with the reference to the actual BindingNavigator.

3. Add the following code on the Form1Component's ngAfterViewInit method.

 @ViewChild("bindingNavigator1", { static: false })
 bindingNav: any;
 newItemClickSub: Subscription;

 ngAfterViewInit(): void {
  this.newItemClickSub = this.bindFrontEndClickHandler('newlyAddedButton', (e) => alert('item clicked!'));
 }
 
 bindFrontEndClickHandler(itemName: string, handler: any) : Subscription {
  if (this.bindingNav) {
    const itemModel = this.bindingNav.items.filter(
      (x) => x.Name === itemName
    );
    if (itemModel.length > 0) {
      const itemComponent =
        this.bindingNav.webComponents.componentsCollection[
          itemModel[0].id
        ];
      return itemComponent.Click.subscribe(handler);
    }
  }
 }

The following is the final code.

import { Component, ChangeDetectorRef, ElementRef
, Renderer2, ViewEncapsulation, ViewChild, OnDestroy, AfterViewInit} from "@angular/core";
import { dataTransfer} from "@mobilize/base-components";
import { FormComponent} from "@mobilize/winforms-components";
import { WebMapService} from "@mobilize/angularclient";
import { Subscription } from "rxjs/internal/Subscription";
@Component({
   selector : "form1",
   styleUrls : ["./form1.component.css"],
   templateUrl : "./form1.component.html",
   encapsulation : ViewEncapsulation.None
})
@dataTransfer(["Form1"])
export class Form1Component extends FormComponent implements AfterViewInit, OnDestroy {
   constructor (private wmservice : WebMapService,
   changeDetector : ChangeDetectorRef,render2 : Renderer2,elem : ElementRef) {
      super(wmservice,changeDetector,render2,elem);
   }

   @ViewChild("bindingNavigator1", { static: false })
  bindingNav: any;
  newItemClickSub: Subscription;

  ngAfterViewInit(): void {
   this.newItemClickSub = this.bindFrontEndClickHandler('newlyAddedButton', (e) => alert('item clicked!'));
 }

 bindFrontEndClickHandler(itemName: string, handler: any) : Subscription {
  if (this.bindingNav) {
    const itemModel = this.bindingNav.items.filter(
      (x) => x.Name === itemName
    );
    if (itemModel.length > 0) {
      const itemComponent =
        this.bindingNav.webComponents.componentsCollection[
          itemModel[0].id
        ];
      return itemComponent.Click.subscribe(handler);
    }
  }
 }

 ngOnDestroy(): void {
   this.newItemClickSub?.unsubscribe();
 }
}
<div *ngIf="model">
    <wm-window [model]="model" id="Form1" class="AddingNotWebMapForm_Form1">
        <ng-template let-model>
            <div class="Form1">
                <wm-bindingnavigator #bindingNavigator1 id="bindingNavigator1" [model]="model.bindingNavigator1" class="bindingNavigator1" tabindex="1"></wm-bindingnavigator>
            </div>
        </ng-template>
    </wm-window>
</div>
using Mobilize.WebMap.Common.Attributes;
using Mobilize.Web.Extensions;

namespace AddingNotWebMapForm
{
    partial class Form1
    {

      /// <summary>
      /// Required designer variable.
      /// </summary>
      [Intercepted]
      private Mobilize.Web.Controls.Interfaces.IContainer components { get; set; } = null;

      /// <summary>
      /// Clean up any resources being used.
      /// </summary>
      /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>

      protected override void Dispose(bool disposing)
      {
          if (disposing && (components != null))
         {
             components.Dispose();
         }
         base.Dispose(disposing);
     }

      [Mobilize.WebMap.Common.Attributes.Designer]

      #region Windows Form Designer generated code

      /// <summary>
      /// Required method for Designer support - do not modify
      /// the contents of this method with the code editor.
      /// </summary>
      private
         void InitializeComponent()
      {
          this.components = new Mobilize.Web.ControlCollection();
          System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
          this.bindingNavigator1 = new Mobilize.Web.BindingNavigator(this.components);
          this.toolStripButton1 = new Mobilize.Web.ToolStripButton();
            this.newlyAddedButton = new Mobilize.Web.ToolStripButton();
            this.button1 = new Mobilize.Web.Button();
          this.bindingNavigator1.SuspendLayout();
          this.SuspendLayout();
          // 
          // bindingNavigator1
          // 
          this.bindingNavigator1.Items.AddRange(new Mobilize.Web.ToolStripItem[] {
            this.toolStripButton1,
          this.newlyAddedButton});
            this.bindingNavigator1.Location = new System.Drawing.Point(0, 0);
            this.bindingNavigator1.Name = "bindingNavigator1";
            this.bindingNavigator1.Size = new System.Drawing.Size(294, 25);
            this.bindingNavigator1.TabIndex = 0;
            this.bindingNavigator1.Text = "bindingNavigator1";
         // 
         // toolStripButton1
         // 
         this.toolStripButton1.DisplayStyle = Mobilize.Web.ToolStripItemDisplayStyle.Image;
         this.toolStripButton1.Image = "assets/images/AddingNotWebMapForm.Resources.clock.png";
         this.toolStripButton1.Properties().ImageTransparentColor = System.Drawing.Color.Magenta;
         this.toolStripButton1.Name = "toolStripButton1";
         this.toolStripButton1.Size = new System.Drawing.Size(23, 22);
         this.toolStripButton1.Text = "toolStripButton1";
         this.toolStripButton1.Click += new System.EventHandler(this.toolStripButton1_Click);
            // 
            // toolStripButton1
            // 
            this.newlyAddedButton.DisplayStyle = Mobilize.Web.ToolStripItemDisplayStyle.Image;
            this.newlyAddedButton.Image = "assets/images/help_16x16.png";
            this.newlyAddedButton.Properties().ImageTransparentColor = System.Drawing.Color.Magenta;
            this.newlyAddedButton.Name = "newlyAddedButton";
            this.newlyAddedButton.Size = new System.Drawing.Size(23, 22);
            this.newlyAddedButton.Text = "newlyAddedButton";
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(100, 58);
         this.button1.Name = "button1";
         this.button1.Size = new System.Drawing.Size(75, 23);
         this.button1.TabIndex = 1;
         this.button1.Text = "button1";
         this.button1.UseVisualStyleBackColor = true;
         this.button1.Click += new System.EventHandler(this.button1_Click);
         this.Properties().AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
         this.Properties().AutoScaleMode = Stub._System.Windows.Forms.AutoScaleMode.Font;
         this.ClientSize = new System.Drawing.Size(294, 91);
         this.Controls.Add(this.button1);
         this.Controls.Add(this.bindingNavigator1);
         this.Name = "Form1";
         this.Text = "Form1";
         this.bindingNavigator1.ResumeLayout(false);
         this.bindingNavigator1.PerformLayout();
         this.ResumeLayout(false);
         this.PerformLayout();

     }

     #endregion

      [Intercepted]

      private Mobilize.Web.BindingNavigator bindingNavigator1 { get; set; }

      [Intercepted]
      private Mobilize.Web.Button button1 { get; set; }

      [Intercepted]
      private Mobilize.Web.ToolStripButton toolStripButton1 { get; set; }

      [Intercepted]
      private Mobilize.Web.ToolStripButton newlyAddedButton { get; set; }
    }
}

Once you compile the application (both Backend and FrontEnd projects), you will be able to run the app.

PreviousAdding Non-WebMap Angular FormsNextChanging ToolStripButton icons

Last updated 1 year ago

Was this helpful?

Add a ViewChild () variable in the Form1Component to reference the BindingNavigator control.

https://angular.io/api/core/ViewChild
FrontEnd click handler executed