Back to Devexpress

RepositoryItemHyperLinkEdit.Caption Property

windowsforms-devexpress-dot-xtraeditors-dot-repository-dot-repositoryitemhyperlinkedit.md

latest4.9 KB
Original Source

RepositoryItemHyperLinkEdit.Caption Property

Gets or sets the caption string displayed in the edit box.

Namespace : DevExpress.XtraEditors.Repository

Assembly : DevExpress.XtraEditors.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
[DefaultValue("")]
[DXCategory("Appearance")]
public virtual string Caption { get; set; }
vb
<DXCategory("Appearance")>
<DefaultValue("")>
Public Overridable Property Caption As String

Property Value

TypeDefaultDescription
StringString.Empty

A string value specifying the hyperlink editor’s caption.

|

Remarks

By default, the Caption property value is an empty string. In this instance, the editor displays the textual representation of the edit value in the edit box. The edit value specifies the command of the hyperlink editor. The command is obtained from the edit value by calling the ToString method. See the BaseEdit.Text property to get the hyperlink command.

In some cases, it may be useful to display a different text instead of the command. For instance, you may not specify want to specify any command, but handle the RepositoryItemHyperLinkEdit.OpenLink event to perform your own processing when the user activates hyperlink functionality. Setting Caption to a non-empty string enables you to override the default representation of the hyperlink command displayed in the edit box.

Example

The following example shows how to implement hyperlink functionality by handling the HyperLinkEdit.OpenLink event. The hyperlink command is not required by this example.

Instead we handle the HyperLinkEdit.OpenLink event, which occurs before activating the hyperlink, and then run a custom command. In this example, we open Explorer displaying the path for the current executable file. The OpenLinkEventArgs.Handled property of the event parameter is set to true. This disables subsequent default processing.

To specify the display text for the editor, the RepositoryItemHyperLinkEdit.Caption property is set to a specific string (“Show Startup Directory”). If RepositoryItemHyperLinkEdit.Caption contains a non-empty string, the editor will always display this value in the edit box. This allows you to store specific data in the edit value while representing them using the RepositoryItemHyperLinkEdit.Caption string.

The following image shows a hyperlink editor with a customized caption and Explorer activated by the editor:

csharp
hyperLinkEdit1.Properties.Caption = "Show Startup Directory";
// ...
void hyperLinkEdit1_OpenLink(object sender, DevExpress.XtraEditors.Controls.OpenLinkEventArgs e) {
    System.Diagnostics.Process process = new System.Diagnostics.Process();
    process.StartInfo.FileName = Application.StartupPath;
    process.StartInfo.Verb = "explore";
    process.StartInfo.WindowStyle = (sender as HyperLinkEdit).Properties.BrowserWindowStyle;
    process.Start();
    e.Handled = true;
}
vb
Me.HyperLinkEdit1.Properties.Caption = "Show Startup Directory"
'...
Private Sub HyperLinkEdit1_OpenLink(ByVal sender As System.Object, _
  ByVal e As DevExpress.XtraEditors.Controls.OpenLinkEventArgs) _
  Handles HyperLinkEdit1.OpenLink
    Dim process As New System.Diagnostics.Process()
    process.StartInfo.FileName = Application.StartupPath
    process.StartInfo.Verb = "explore"
    process.StartInfo.WindowStyle = (TryCast(sender, HyperLinkEdit)).Properties.BrowserWindowStyle
    process.Start()
    e.Handled = True
End Sub

See Also

Text

OpenLink

RepositoryItemHyperLinkEdit Class

RepositoryItemHyperLinkEdit Members

DevExpress.XtraEditors.Repository Namespace