1# Event Monopolization 2 3You can configure a component to monopolize events – built-in events and custom gesture events,<br> 4so that if the component first responds to an event in a window, it will be the only component that responds to the event. 5 6> **NOTE** 7> 8> This feature is supported since API version 11. Updates will be marked with a superscript to indicate their earliest API version. 9 10## monopolizeEvents 11 12monopolizeEvents(monopolize: boolean) 13 14Sets whether the component monopolizes events. 15 16**Atomic service API**: This API can be used in atomic services since API version 12. 17 18**System capability**: SystemCapability.ArkUI.ArkUI.Full 19 20**Parameters** 21 22 23| Name | Type| Mandatory| Description | 24| ----------- | -------- | ------------------------ | ------------------------ | 25| monopolize | boolean | Yes| Whether the component monopolizes events.<br>Default value: **false**<br>**NOTE**<br>1. If a component is monopolizing events after a finger is pressed on it, and another finger is pressed before the first finger is lifted, the component continues to monopolize events while interacting with the second finger. The same case applies to a third and more fingers.<br>2. If a component is bound through [parallelGesture](ts-gesture-settings.md) to a gesture, for example, [pan gesture](ts-basic-gestures-pangesture.md), that can also be triggered by its child component, and the child component is configured to monopolize events, then the parent will not respond to the gesture after the child component has responded to it.| 26 27## Example 28 29```ts 30// xxx.ets 31@Entry 32@Component 33struct Index { 34 @State message: string = 'set monopolizeEvents false' 35 @State messageOut: string = ' ' 36 @State messageInner: string = ' ' 37 @State monopolize: boolean = false 38 39 build() { 40 Column() { 41 Text(this.message) 42 .fontSize(22) 43 .margin(10) 44 Text(this.messageOut) 45 .fontSize(22) 46 .margin(10) 47 Text(this.messageInner) 48 .fontSize(22) 49 .margin(10) 50 Button('clean') 51 .fontSize(22) 52 .margin(10) 53 // Change the value of the column's monopolizeEvents attribute through the button's click event. 54 .onClick(()=>{ 55 this.messageOut = " " 56 this.messageInner = " " 57 }) 58 Button('change monopolizeEvents') 59 .fontSize(22) 60 .margin(10) 61 // Change the value of the column's monopolizeEvents attribute through the button's click event. 62 .onClick(()=>{ 63 this.monopolize = !this.monopolize 64 if (!this.monopolize) { 65 this.message = "set monopolizeEvents false" 66 } else { 67 this.message = "set monopolizeEvents true" 68 } 69 }) 70 Column() { 71 Column(){} 72 // When this.monopolize is true, clicking the inner column triggers only a touch event on it, but not on the outer column. 73 // When this.monopolize is false, clicking the inner column triggers a touch event on it and the outer column. 74 .monopolizeEvents(this.monopolize) 75 .width('100%') 76 .height('40%') 77 .backgroundColor(Color.Blue) 78 // Bind the inner column to the touch event. 79 .onTouch((event:TouchEvent)=>{ 80 if (event.type == TouchType.Down) { 81 console.log("inner column touch down") 82 this.messageInner = "inner column touch down" 83 } 84 }) 85 } 86 .backgroundColor(Color.Gray) 87 .height('100%') 88 .width('100%') 89 // Bind the outer column to the touch event. 90 .onTouch((event)=>{ 91 if (event.type == TouchType.Down) { 92 console.log("outside column touch down") 93 this.messageOut = "inner column touch down" 94 } 95 }) 96 } 97 .height('100%') 98 } 99} 100``` 101 102