如何在 windows 表单上的 C# 中将文本框值添加到超链接?

How to add text box value to hyperlink in C# on windows form?

我需要创建一个超链接,从文本框中获取输入并显示网页。 文本框值是动态生成的。生成的网页取决于分机框值。有人可以帮助我

提前致谢

最低限度,因为您没有指定您期望的行为,但它可能对您有用或给您带来麻烦。还要查看 MSDN

中的 LinkLabel 控件说明
using System.Diagnostics;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            linkLabel.Text = "Click to search!";
            linkLabel.LinkClicked += LinkLabel_LinkClicked;
        }

        private void LinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            string googleSearch = @"https://www.google.com/?q=";
            Process.Start(googleSearch + textBox.Text);
        }
    }
}

要检查它,只需添加 TextBox,将其命名为 textBox 并将 LinkLabel 命名为 linkLabel。当您在文本框中输入内容并单击标签时 google 将在您的默认浏览器中开始使用该短语进行搜索。

对于 WPF, 在 xaml 代码中,

        <Hyperlink RequestNavigate="Hyperlink_RequestNavigate" NavigateUri="https://www.google.de/search?q=">LINK

        </Hyperlink>
    </TextBlock>

在xaml.cs

中实现Hyperlink_RequestNavigate功能
private void Hyperlink_RequestNavigate(object sender,   System.Windows.Navigation.RequestNavigateEventArgs e)
        {
            Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri+textBox.Text));
            e.Handled = true;
        }

//textbox.Text 包含要附加的文本