Message
Namespace: Wisej.Web.Ext.ChatControl
Assembly: Wisej.Web.Ext.ChatControl (4.1.0.0)
Represents a message in a ChatBox.
- C#
- VB.NET
public class Message
Public Class Message
Messages are displayed by adding them to DataSource. When a message is added without a User or Timestamp, the ChatBox assigns its own User and the current time. The control that displays the message is created when the message is added: handle RenderMessageControl to supply a custom control, otherwise an AutoSizeLabel showing Content is used.
Example:
var message = new Message("Hello, how can I help you?")
{
User = new User("bot", "Assistant"),
Timestamp = DateTime.Now
};
chatBox.DataSource.Add(message);
Constructors
Message()
Creates a new, empty instance of Message.
Example:
var message = new Message
{
User = chatBox.User,
Content = "Good morning!"
};
chatBox.DataSource.Add(message);
Message(content, contentType, user)
Creates a new instance of Message with the given content, content type and user.
| Name | Type | Description |
|---|---|---|
| content | String | The content of the message. |
| contentType | String | The message content type, for example "text/plain" or "text/html"; can be null. |
| user | User | The user associated with the message. When null, the ChatBox assigns its own User when the message is added. |
Example:
var alice = new User("1", "Alice");
var message = new Message("Hi everyone!", "text/plain", alice);
chatBox.DataSource.Add(message);
Fields
| Name | Type | Description | Value |
|---|---|---|---|
| BubbleVisible | Boolean | Returns or sets whether the bubble background is visible. | |
| Id | String | Returns or sets the unique identifier for this message. | |
| Timestamp | Nullable<DateTime> | Returns or sets the timestamp of the message. |
Properties
Content
String: Returns or sets the content of the message.
Value: The message text. The default AutoSizeLabel control allows HTML content.
Example:
var message = new Message();
message.Content = "Your order has <b>shipped</b>.";
ContentType
String: Returns or sets the content type of the message.
Value: An application-defined string, for example "text/plain" or "image/png"; the default is null.
The ChatBox doesn't interpret this value. Use it in the RenderMessageControl or FormatMessage handlers to decide how to render or format the message.
Example:
var message = new Message("https://example.com/cat.png", "image");
chatBox.DataSource.Add(message);
Control
Control: Returns or sets the control rendered in the chat box for this message.
Value: The control displaying the message, by default an AutoSizeLabel. It is null until the message has been added to a ChatBox.
The MessageControlAssigned event is fired when the control is assigned.
Example:
chatBox.DataSource.Add(message);
if (message.Control != null)
message.Control.ForeColor = Color.White;
User
User: Returns or sets the user associated with the message.
Value: The User that sent the message. When null, the ChatBox assigns its own User when the message is added.
Example:
var message = new Message("Hello");
message.User = new User("2", "Bob");
UserData
String: Returns or sets custom user data associated with the message.
Value: An application-defined string; the default is null.
Example:
var message = new Message("Order #1234 confirmed.");
message.UserData = "order:1234";
Methods
Clone()
Creates a copy of the current message.
Returns: Message. A new Message with the same Id, User, Content, UserData, Timestamp and ContentType.
The clone gets its own new Control (an AutoSizeLabel displaying Content) and does not share the original's control. BubbleVisible is not copied. Derived classes can override this method to copy additional state.
Example:
var original = new Message("Forward me", null, new User("1", "Alice"));
var copy = original.Clone();
otherChatBox.DataSource.Add(copy);
OnMessageControlAssigned(e)
Invokes the MessageControlAssigned event. Fires when the Message.Control is assigned.
| Parameter | Type | Description |
|---|---|---|
| e | EventArgs | The event data. |
Events
MessageControlAssigned
EventHandler Fired when the Control is assigned.
The event is fired each time the control is requested for display, after Control has been set, so handlers can safely customize the control.
Example:
var message = new Message("Important!");
message.MessageControlAssigned += (s, e) =>
{
((Message)s).Control.Font = new Font("Arial", 14, FontStyle.Bold);
};
chatBox.DataSource.Add(message);
Inherited By
| Name | Description |
|---|---|
| LazyMessage | A Message with a deferred result. |