【问题标题】:How to set width of the text in System.Windows.Forms.WebBrowser?如何在 System.Windows.Forms.WebBrowser 中设置文本的宽度?
【发布时间】:2011-12-30 00:33:51
【问题描述】:

我目前正在使用控件 System.Windows.Forms.WebBrowser 在 Windows 应用程序中创建所见即所得的编辑器。 基本上我需要的是文本不超过控件的宽度,即我不想使用水平滚动条。

有可能吗?

[更新]

这是我正在运行的那一刻的代码:

 Reconocimiento.Navigate("about:blank"); //this is my object System.Windows.Forms.WebBrowser
 Reconocimiento.Document.OpenNew(false);
 string html = "<html><head><style type=\"text/css\">body {width: 400px;}</style></head><body></body></html>";
 Reconocimiento.Document.Write(html);
 recon = (Reconocimiento.Document.DomDocument) as IHTMLDocument2;
 recon.designMode = "On"; //What we just did was make our web browser editable!

【问题讨论】:

  • 你用它来输入这个问题。你看到水平滚动条了吗?
  • 你有没有看表单设计器看看有什么尺寸然后修改它。
  • Hans: touche,他们在 Stackoverflow 的表现如何。现在冷:我在想我应该激活垂直而不是水平,并改变不会发生的控件的宽度
  • 也许我可以使用这个question,但无法使用方法createStyleSheet
  • 盛:如你所见,上面是我使用的代码,我没有使用iframe

标签: c# winforms webbrowser-control


【解决方案1】:

您可以使用 css 的分词属性。

创建一个包含以下内容的文件并将其保存为 C:\default.html(或某些应用程序路径)

<html>    
  <body style='word-break: break-all'>
  <body>
</html>

在您的代码中,不要导航到 about:blank,而是调用

Reconocimiento.Navigate(new Uri("file:///C:/default.html"));

【讨论】:

    猜你喜欢
    • 2015-10-04
    • 2021-10-26
    • 1970-01-01
    • 2012-06-02
    • 1970-01-01
    • 2013-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多