如何使用一个url String在Windows窗体中显示网页 [英] How can we display a Webpage in Windows Forms using one url String
问题描述
您好我开发了一个c#Windows窗体应用程序,它将连接到SQL并执行SQL查询,并仅在数据从上一个输出更改时才在消息框中显示输出数据。现在我在同一个Project中开发了一个新表单,并在新表单中添加了Web浏览器。所以我现在已经将SQL的输出值存储在2个变量中,即lati和longi。现在我将它们传递给我的新表格。
当我用url + lati + longi值执行我的浏览器时,它不返回任何输出。至少它也没有打开任何浏览器表单。
我在form2中尝试了以下内容: -
< span class =code-keyword>使用系统;
使用 System.Collections.Generic;
使用 System.ComponentModel;
使用 System.Data;
使用 System.Drawing;
使用 System.Linq;
使用 System.Text;
使用 System.Windows.Forms;
命名空间 LeakLocationFinder
{
public partial class 地图:表格
{
public string lati;
public string longi;
public MainForm lat,lon;
public Maps()
{
InitializeComponent();
}
私有 void Maps_Load(< span class =code-keyword> object sender,EventArgs e)
{
string url = https://www.google.co.in/maps/place/;
webBrowser1.Navigate(url + lati + , + longi);
}
}
}
我在表格1中有以下内容: -
使用系统;
使用 System.Collections.Generic;
使用 System.ComponentModel;
使用 System.Data;
使用 System.Drawing;
使用 System.Linq;
使用 System.Text;
使用 System.Windows.Forms;
使用 System.Data.SqlClient;
命名空间 LeakLocationFinder
{
public partial class MainForm:Form
{
public MainForm()
{
InitializeComponent();
}
public void MainForm_Load( object sender,EventArgs e)
{
String old_value = ;
while ( true )
{
String connetionString = null ;
SqlConnection conn;
SqlCommand cmd;
字符串 sql = null ;
SqlDataReader阅读器;
connetionString = server =(local); database = modelDb; user id = sa; PWD = Esi2008 *跨度>;
sql = DECLARE @var varchar(1000)=(SELECT TOP 1 Text FROM Alarms WHERE AlarmDefinitionId = 139 ORDER BY EventTime DESC)DECLARE @start_position int,@ end_position int SELECT @start_position = PATINDEX('%at%',@ var)SELECT @end_position = PATINDEX('%km%',@ var)DECLARE @VALUE VARCHAR(10) =(选择SUBSTRING(@ var,@ start_position + 5,5))选择Top 1 @ VALUE,RouteTable.Latitude,Routetable.Longitude,Alarms.ApplicationTime,RouteTable.StationName,RouteTable.SectionName FROM Alarms INNER JOIN Routetable ON Routetable.Location BETWEEN FLOOR(@VALUE)-1和CEILING(@VALUE)+1 WHERE AlarmDefinitionId = 139 ORDER BY EventTime DESC;
conn = new SqlConnection(connetionString);
尝试
{
conn.Open();
cmd = new SqlCommand(sql,conn);
reader = cmd.ExecuteReader();
while (reader.Read())
{
if (old_value.ToString()!= reader.GetValue( 0 )。ToString())
{
MessageBox.Show( 泄漏位置: - + + reader.GetValue( 0 )+ Environment.NewLine + 纬度: - + + reader.GetValue( 1 )+ Environment.NewLine + 经度: - + + reader.GetValue( 2 )+ Environment.NewLine + 泄漏发生时间: - + + reader.GetValue( 3 )+ Environment.NewLine + 站名: - + + reader.GetValue( 4 )+ Environment.NewLine + 部分名称: - + + reader.GetValue( 5 < /跨度>));
string lat = reader.GetValue( 1 )。ToString();
string lon = reader.GetValue( 2 )。ToString();
Maps form = new Maps();
{
string lati = lat;
string longi = lon;
};
}
其他
{
}
old_value = reader.GetValue( 0 跨度>)的ToString();
}
reader.Close();
cmd.Dispose();
conn.Close();
}
catch (例外)
{
MessageBox.Show( 无法打开连接...!);
}
System.Threading.Thread.Sleep( 5 * 1000 );
}
}
私有 void aboutToolStripMenuItem_Click( object sender,EventArgs e)
{
About_LeakLocationFinder formhelp = new About_LeakLocationFinder() ;
formhelp.Show();
}
private void exitToolStripMenuItem_Click( object sender,EventArgs e)
{
this .Close();
}
}
}
将使用url + lati值和longi执行url lati和longi之间的值会有一个逗号(,)。
请帮助
你必须打电话给form.Show()
Maps form = new Maps();
{
string lati = lat;
string longi = lon;
};
form.Show();
使用此代码
webBrowser1.Url = new Uri(url + lati + , + longi);
而不是
webBrowser1。导航(url + lati + , + longi);
Hi I have developed a c# Windows forms application, which will connect to SQL and execute an SQL Query and shows the output data in a Message Box only when the data got changed from the previous output. Now i have developed a new form in the same Project and added web browser to the new form. SO now i have stored the output values of SQL in 2 variables namely lati and longi. Now i have passed them to my new form.
And when i execute my browser with that "url + lati+ longi" valu its not returning any output. Atleast it is not opening any browser form also.
I have tried the following in form2:-
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace LeakLocationFinder
{
public partial class Maps : Form
{
public string lati;
public string longi;
public MainForm lat, lon;
public Maps()
{
InitializeComponent();
}
private void Maps_Load(object sender, EventArgs e)
{
string url = "https://www.google.co.in/maps/place/";
webBrowser1.Navigate(url + lati + "," + longi);
}
}
}
I have following in form 1:-
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace LeakLocationFinder
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
public void MainForm_Load(object sender, EventArgs e)
{
String old_value = "";
while (true)
{
String connetionString = null;
SqlConnection conn;
SqlCommand cmd;
String sql = null;
SqlDataReader reader;
connetionString = "server=(local);database=modelDb;user id=sa;pwd=Esi2008*";
sql = "DECLARE @var varchar(1000) = (SELECT TOP 1 Text FROM Alarms WHERE AlarmDefinitionId=139 ORDER BY EventTime DESC) DECLARE @start_position int, @end_position int SELECT @start_position = PATINDEX('% at%', @var) SELECT @end_position = PATINDEX('%kilometers%', @var) DECLARE @VALUE VARCHAR(10) = (Select SUBSTRING(@var, @start_position+5,5)) Select Top 1 @VALUE,RouteTable.Latitude,Routetable.Longitude,Alarms.ApplicationTime,RouteTable.StationName,RouteTable.SectionName FROM Alarms INNER JOIN Routetable ON Routetable.Location BETWEEN FLOOR(@VALUE)-1 AND CEILING(@VALUE)+1 WHERE AlarmDefinitionId=139 ORDER BY EventTime DESC";
conn = new SqlConnection(connetionString);
try
{
conn.Open();
cmd = new SqlCommand(sql, conn);
reader = cmd.ExecuteReader();
while (reader.Read())
{
if (old_value.ToString() != reader.GetValue(0).ToString())
{
MessageBox.Show("Leak Location:-" + " " + reader.GetValue(0) + Environment.NewLine + "Latitude:-" + " " + reader.GetValue(1) + Environment.NewLine + "Longitude:-" + " " + reader.GetValue(2) + Environment.NewLine + "Leak Occured Time:-" + " " + reader.GetValue(3) + Environment.NewLine + "Station Name:-" + " " + reader.GetValue(4) + Environment.NewLine + "Section Name:-" + " " + reader.GetValue(5));
string lat = reader.GetValue(1).ToString();
string lon = reader.GetValue(2).ToString();
Maps form = new Maps();
{
string lati = lat;
string longi = lon;
};
}
else
{
}
old_value = reader.GetValue(0).ToString();
}
reader.Close();
cmd.Dispose();
conn.Close();
}
catch (Exception)
{
MessageBox.Show("Cannot Open Connection...! ");
}
System.Threading.Thread.Sleep(5 * 1000);
}
}
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
About_LeakLocationFinder formhelp = new About_LeakLocationFinder();
formhelp.Show();
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
The url will be executed with url + lati value and longi value between lati and longi there will be a comma (",").
Please help
you have to callform.Show()
Maps form = new Maps(); { string lati = lat; string longi = lon; }; form.Show();
use this code
webBrowser1.Url = new Uri(url + lati + "," + longi);
instead of
webBrowser1.Navigate(url + lati + "," + longi);
这篇关于如何使用一个url String在Windows窗体中显示网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!