|
| 1 | +--- |
| 2 | +title: Resizing and Wrapping Text in ChatCardAction for RadChat |
| 3 | +description: Learn how to resize and wrap text in ChatCardAction buttons within RadChat cards in UI for WinForms. |
| 4 | +type: how-to |
| 5 | +page_title: How to Resize and Wrap Text for ChatCardAction in RadChat |
| 6 | +meta_title: How to Resize and Wrap Text for ChatCardAction in RadChat |
| 7 | +slug: chat-resize-wrap-text-cardaction |
| 8 | +tags: chat, ui-for-winforms, chatcardaction, itemformatting, textwrap, resizing |
| 9 | +res_type: kb |
| 10 | +ticketid: 1702233 |
| 11 | +--- |
| 12 | + |
| 13 | +## Environment |
| 14 | + |
| 15 | +|Product Version|Product|Author| |
| 16 | +|----|----|----| |
| 17 | +|2025.3.812|RadChat for WinForms|[Dinko Krastev](https://www.telerik.com/blogs/author/dinko-krastev)| |
| 18 | + |
| 19 | +## Description |
| 20 | + |
| 21 | +In the following tutorial, we will demonstrate how to wrap the text in ChatCardAction buttons within RadChat cards. Additionally, we will demonstrate how to increase the size of the entire chat card. |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | +This knowledge base article also answers the following questions: |
| 26 | +- How can I make ChatCardAction text wrap in RadChat? |
| 27 | +- How do I increase the size of RadChat cards? |
| 28 | +- How to customize the appearance of ChatCardAction buttons? |
| 29 | + |
| 30 | +## Solution |
| 31 | + |
| 32 | +To resize and wrap the text in ChatCardAction buttons and increase the size of the RadChat card, use the following approach: |
| 33 | + |
| 34 | +1. Handle the `ItemFormatting` event of RadChat. |
| 35 | +2. Target the `ChatImageCardElement` and its child elements representing the action buttons. |
| 36 | +3. Set the `TextWrap` property to enable text wrapping for the action buttons. |
| 37 | +4. Customize the size of the card by modifying its child elements. |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | +### Code Example |
| 42 | + |
| 43 | +Use this code to enable text wrapping for ChatCardAction buttons and resize the chat card: |
| 44 | + |
| 45 | +````C# |
| 46 | + |
| 47 | +private void RadChat1_ItemFormatting1(object sender, ChatItemElementEventArgs e) |
| 48 | +{ |
| 49 | + CardMessageItemElement cardMessageItemElement = e.ItemElement as CardMessageItemElement; |
| 50 | + if (cardMessageItemElement != null) |
| 51 | + { |
| 52 | + LightVisualElement bubble2 = e.ItemElement.MainMessageElement; |
| 53 | + if (e.ItemElement.MainMessageElement is ChatMessageBubbleElement bubbleElement) |
| 54 | + { |
| 55 | + ChatImageCardElement imageCard = bubbleElement.FindDescendant<ChatImageCardElement>(); |
| 56 | + if (imageCard != null) |
| 57 | + { |
| 58 | + imageCard.MaxSize = new Size(0,0); |
| 59 | + imageCard.Children[0].MinSize= new Size(280, 350); // this is the StackLayoutPanel holding the elements |
| 60 | + foreach (LightVisualElement lve in imageCard.Children[0].Children) |
| 61 | + { |
| 62 | + lve.TextWrap = true; |
| 63 | + } |
| 64 | + } |
| 65 | + } |
| 66 | + e.ItemElement.DrawFill = true; |
| 67 | + //e.ItemElement.BackColor = Color.LightBlue; |
| 68 | + e.ItemElement.TextAlignment = ContentAlignment.MiddleLeft; |
| 69 | + e.ItemElement.TextWrap = true; |
| 70 | + bubble2.TextWrap = true; |
| 71 | + bubble2.MaxSize = new Size(280, 350); |
| 72 | + bubble2.MinSize = new Size(280, 350); |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +```` |
| 77 | + |
| 78 | +### Key Steps |
| 79 | + |
| 80 | +1. Use the `FindDescendant` method to locate the `ChatImageCardElement`. |
| 81 | +2. Access its child elements to customize the `TextWrap` property of action buttons. |
| 82 | +3. Adjust the size of the `StackLayoutPanel` holding the card elements to increase the overall card size. |
| 83 | + |
| 84 | +## See Also |
| 85 | + |
| 86 | +* [RadChat Overview](https://docs.telerik.com/devtools/winforms/controls/chat/overview) |
| 87 | +* [Item Formatting Event](https://docs.telerik.com/devtools/winforms/controls/chat/customizing-appearance/accessing-and-customizing-elements) |
| 88 | + |
0 commit comments