2011-06-23 17 views
0

複数のWeather APIを使用しています。 GoogleのAPIについては、3日の予告を読み込むためにrtryuingしています。これは、どのようにそれを現在のルックスです: EDIT:この問題は実行時にコントロールを追加すると動作しない

private void LoadForecast(WeatherSet set) 
     { 
      RemoveControls(); 

      form = new forecastView(7, 159, 1, set); 
      form1 = new forecastView(161, 159, 2, set); 
      form2 = new forecastView(7, 254, 3, set); 

      this.Controls.Add(form); 
      this.Controls.Add(form1); 
      this.Controls.Add(form2); 
     } 




using System.Windows.Forms; 
using WeatherVaneGoogleWrapper.Forecast; 
using WeatherVaneGoogleWrapper.Weather; 

namespace WeatherVane 
{ 
    public partial class forecastView : UserControl 
    { 
     public forecastView() 
     { 
      InitializeComponent(); 
     } 

     public forecastView(int x, int y, int index,WeatherSet set) 
     { 
      InitializeComponent(); 

      label7.Text = string.Format("High:{0}", set.Forecast[index].High); 
      label8.Text = string.Format("Low: {0}", set.Forecast[index].Low); 
      pictureBox3.Load(string.Format("http://www.google.com/{0}", set.Forecast[index].Icon)); 
      groupBox1.Text = set.Forecast[index].DayOfTheWeek; 
      label9.Text = string.Format("Conditions: {0}", set.Forecast[index].Condition); 
      this.Location = new System.Drawing.Point(x, y); 
     } 
    } 
} 

解決されているそれは私が自分自身を言うならば、ここでそれをしようとしたが、単に取得することはできませんどのように私はtworking非常に良くあります:

private void LoadCurrentWeatherData(string loc) 
      { 

       WeatherSet set = WeatherService.Response(GoogleWeatherRequest.RequestData(new WeatherService(loc))); 

       LowLabelOne.Text = string.Format("Current Temp: {0}{1}", set.Current.TemperatureFahrenheit, "°"); 
       groupBox1.Text = string.Format("Current Conditions for {0}", set.Information.City); 
       HumidityLabel.Text = set.Current.Humidity; 
       windConditionsLabel.Text = string.Format("Wind Conditions: {0}", set.Current.Wind); 
       label3.Text = string.Format("Condition: {0}", set.Current.Condition); 
       pictureBox1.Load(string.Format("http://www.google.com/{0}", set.Current.Icon)); 

       LoadForecastControls(set); 

       dateTimeLabel.Text = string.Format("Last Check: {0} {1}", Convert.ToDateTime(set.Information.CurrentDateTime).ToShortDateString(), 
        Convert.ToDateTime(set.Information.CurrentDateTime).ToShortTimeString()); 

       set = null; 
      } 

      private void LoadForecastControls(WeatherSet set) 
      { 
       RemoveControls(); 

       form = new forecastView(12, 136, 1, set); 
       form1 = new forecastView(155, 136, 2, set); 
       form2 = new forecastView(12, 218, 3, set); 

       this.Controls.Add(form); 
       this.Controls.Add(form1); 
       this.Controls.Add(form2); 
      } 

      private void RemoveControls() 
      { 
       this.Controls.Remove(form); 
       this.Controls.Remove(form1); 
       this.Controls.Remove(form2); 
      } 

Can someone help? 

答えて

0
\

私のWebフォームは錆びていますが、私はUserControlsを新規に作成してそのように追加することはできないと思います。私はあなたがPage.LoadControl()を使用する必要があると信じています。

var form = Page.LoadControl(typeof(forecastView), new { 12, 136, 1, set }); 

Page.Controls.Add(form); 
+0

MVCでも同様に機能しますか? – PsychoCoder

+0

MVCでは、.ASCXパーシャルは同じファイル拡張子を共有しますが、UserControlではまったく同じではありません。 WebFormsとMVCの両方で同じアプローチを使用できるとは思いません。 –

関連する問題