【发布时间】:2014-03-08 11:28:24
【问题描述】:
我正在使用连接到 Internet 的服务参考,如果连接失败,我想在消息框中显示消息。如何在具有 void 返回类型的类的成员函数中调用消息框?这是类的成员函数:
public void ReverseGeocodePoint()
{
try{
string results = "";
string key = "abc";
ReverseGeocodeRequest reverseGeocodeRequest = new ReverseGeocodeRequest();
// Set the credentials using a valid Bing Maps key
reverseGeocodeRequest.Credentials = new GeocodeService.Credentials();
reverseGeocodeRequest.Credentials.ApplicationId = key;
// Set the point to use to find a matching address
GeocodeService.Location point = new GeocodeService.Location();
point.Latitude = latitude;
point.Longitude = longitude;
reverseGeocodeRequest.Location = point;
// Make the reverse geocode request
GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
//This will connect to the server
GeocodeResponse geocodeResponse = geocodeService.ReverseGeocode(reverseGeocodeRequest);
if (geocodeResponse.Results.Length > 0)
results = geocodeResponse.Results[0].DisplayName;
else
results = "No Results found";
address = results;
}} catch{ //here I want to show a msgbox but the problem is, this is not the form class}
【问题讨论】:
-
发布代码有助于更好地理解您的问题。
-
您需要向我们展示您的代码。你拥有的东西和你试图写的东西都不起作用。
标签: c# winforms exception exception-handling