Hipervínculo
Contents
[
Hide
]
Este artículo muestra cómo agregar, acceder, eliminar y actualizar hipervínculos en formas usando Aspose.Slides for .NET.
Agregar un hipervínculo
Cree una forma rectangular con un hipervínculo que apunta a un sitio web externo.
static void AddHyperlink()
{
using var presentation = new Presentation();
var slide = presentation.Slides[0];
var shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 50, 150, 50);
shape.TextFrame.Text = "Aspose";
var textPortion = shape.TextFrame.Paragraphs[0].Portions[0];
textPortion.PortionFormat.HyperlinkClick = new Hyperlink("https://www.aspose.com");
}
Acceder a un hipervínculo
Lea la información del hipervínculo a partir de la porción de texto de una forma.
static void AccessHyperlink()
{
using var presentation = new Presentation();
var slide = presentation.Slides[0];
var shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 50, 150, 50);
shape.TextFrame.Text = "Aspose";
var textPortion = shape.TextFrame.Paragraphs[0].Portions[0];
textPortion.PortionFormat.HyperlinkClick = new Hyperlink("https://www.aspose.com");
var hyperlink = shape.TextFrame.Paragraphs[0].Portions[0].PortionFormat.HyperlinkClick;
}
Eliminar un hipervínculo
Elimine el hipervínculo del texto de una forma.
static void RemoveHyperlink()
{
using var presentation = new Presentation();
var slide = presentation.Slides[0];
var shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 50, 150, 50);
shape.TextFrame.Text = "Aspose";
var textPortion = shape.TextFrame.Paragraphs[0].Portions[0];
textPortion.PortionFormat.HyperlinkClick = new Hyperlink("https://www.aspose.com");
textPortion.PortionFormat.HyperlinkClick = null;
}
Actualizar un hipervínculo
Cambie el destino de un hipervínculo existente. Utilice HyperlinkManager para modificar el texto que ya contiene un hipervínculo, lo que imita cómo PowerPoint actualiza los hipervínculos de forma segura.
static void UpdateHyperlink()
{
using var presentation = new Presentation();
var slide = presentation.Slides[0];
var shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 50, 150, 50);
shape.TextFrame.Text = "Aspose";
var textPortion = shape.TextFrame.Paragraphs[0].Portions[0];
textPortion.PortionFormat.HyperlinkClick = new Hyperlink("https://old.example.com");
// Cambiar un hipervínculo dentro de texto existente debe hacerse mediante
// HyperlinkManager en lugar de establecer la propiedad directamente.
// Esto imita cómo PowerPoint actualiza los hipervínculos de forma segura.
textPortion.PortionFormat.HyperlinkManager.SetExternalHyperlinkClick("https://new.example.com");
}