我在 GUI 中呈现一些文本并尝试重新识别 URL。我还需要在执行点击事件时在浏览器中打开 URL。我在下面附上了模型代码片段。我的问题是如何使这些文本成为有效的 URL,以及如何使它们响应点击事件。还有一件事,由于某些要求,我无法更改以下代码片段的结构。
namespace Model
{
public partial class ParentView : Form
{
public ParentView()
{
InitializeComponent();
}
private void ParentView_Paint(object sender, PaintEventArgs e)
{
GraphicsState state = e.Graphics.Save();
GraphicsRenderer renderer = new GraphicsRenderer(e.Graphics);
renderer.RenderAsImage();
e.Graphics.Restore(state);
e.Graphics.DrawRectangle(new Pen(Brushes.Black), 0, 0, 300, 300);
//I believe need to do something here
}
}
public class GraphicsRenderer
{
Graphics PageGraphics;
public GraphicsRenderer(Graphics g)
{
PageGraphics = g;
}
public void RenderAsImage()
{
Point currentLocation = new Point(0, 0);
PageGraphics.TranslateTransform(20, 40);
PageGraphics.DrawString("www.google.com", new Font("Arial", 12, FontStyle.Regular, GraphicsUnit.Point), Brushes.Black, currentLocation);
PageGraphics.TranslateTransform(20, -40);
PageGraphics.DrawString("www.stackoverflow.com", new Font("Arial", 12, FontStyle.Regular, GraphicsUnit.Point), Brushes.Black, currentLocation);
currentLocation = new Point(50, 60);
PageGraphics.DrawString("www.stackoverflow.com", new Font("Arial", 12, FontStyle.Regular, GraphicsUnit.Point), Brushes.Black, currentLocation);
}
}
}
谢谢, Mkn