Skip to main content

Message

Namespace: Wisej.Web.Ext.ChatControl

Assembly: Wisej.Web.Ext.ChatControl (4.1.0.0)

Represents a message in a ChatBox.

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​

Instance member Message()​

Creates a new, empty instance of Message.

Example:

var message = new Message
{
User = chatBox.User,
Content = "Good morning!"
};
chatBox.DataSource.Add(message);

Instance member Message(content, contentType, user)​

Creates a new instance of Message with the given content, content type and user.

NameTypeDescription
contentStringThe content of the message.
contentTypeStringThe message content type, for example "text/plain" or "text/html"; can be null.
userUserThe 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​

NameTypeDescriptionValue
BubbleVisibleBooleanReturns or sets whether the bubble background is visible.
IdStringReturns or sets the unique identifier for this message.
TimestampNullable<DateTime>Returns or sets the timestamp of the message.

Properties​

Instance member 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>.";

Instance member 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);

Instance member 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;

Instance member 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");

Instance member 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​

Instance member 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);

Protected member OnMessageControlAssigned(e)​

Invokes the MessageControlAssigned event. Fires when the Message.Control is assigned.

ParameterTypeDescription
eEventArgsThe event data.

Events​

Instance member 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​

NameDescription
LazyMessageA Message with a deferred result.