我的问题如下:我尝试通过 WebBrowser 打开条形码在线生成器并获取条形码图像。这是我的代码:
/// <summary>
/// Main form of barcode server
/// </summary>
public partial class MainForm : Form
{
#region Constants
private const String BarCodeSite = "http://www.abarcode.net/online.aspx?barcode=EAN13";//"http://barcode.tec-it.com/en#";
#endregion
/// <summary>
/// Main form constructor
/// </summary>
public MainForm()
{
InitializeComponent();
}
/// <summary>
/// This event occured after form load
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MainForm_Load(object sender, EventArgs e)
{
webBrowser.Navigate(new Uri(BarCodeSite));
}
/// <summary>
/// Occurs when form is closing.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
{
try
{
barcodeServer.Abort();
}
catch (Exception ex)
{
// do nothing
}
}
private void button1_Click(object sender, EventArgs e)
{
var code = textBox1.Text;
var editText = webBrowser.Document.GetElementById("ValueToEncode");
editText.SetAttribute("Value", code.Trim(new char[] { '\0' }));
webBrowser.Document.GetElementById("Label13").InvokeMember("click");
}
}
我执行什么操作: 1. 运行我的项目 2. 在选项中选择图像缩放 250% 3. 粘贴到 textBox1 控制代码 8414034620202 4. 执行单击 button1
预期结果:文本字段输入条码,根据输入的条码更新图像 实际结果:文本字段输入条码,但图像未更新。我不明白为什么我的图像没有更新。我做错了吗?
注意:Id“ValueToEncode”属于文本字段 Id“Label13”属于带有文本“要编码的数据:”的文本标签 我使用过的网站: http ://www.abarcode.net/online.aspx?barcode=EAN13