상세 컨텐츠

본문 제목

[유저 컨트롤] 기본 지식 1편 - 데이터 입력

C#

by xarfox 2010. 9. 2. 10:43

본문

//예제 프로그램 및 사용 설명서//


// 원본 프로그램 //
 foreach (var c in list)
{
      // 현재 오브젝트 컨트롤이 현제 컨트롤중에 포함이 되어 있지 않으면 다음 데이터로 넘어가라
     string name = string.Format("_weatherInfoBox{0}", i);
      if (this.Controls.ContainsKey(name) == false)
      continue;

                    WeatherInfoBox w = this.Controls[name] as WeatherInfoBox;

// 투 두 썸싱 히어

       // 유저 컨트롤 객체에 데이터 세트 시킨다.  
       w.SetData(c.condition, c.low, c.high, c.day_of_week, bit);

                    ++i;
                }


// 유저 컨트롤 프로그램
        public void SetData(string weather, string lowtemp, string hightemp, string day, Image image)
        {
            _lblState.Text = weather;
            _lblHigh.Text = "최고 : " + hightemp + " °C";
            _lblLow.Text = "최저 : " + lowtemp + " °C";
            _gbDays.Text = day + "요일";
            _picImage.Image = image;
        }

유저 컨트롤은 원본 프로그램에 포함 되어 있는 상태에 있다.


namespace Google.Service
{
    partial class GoogleWeather
    {
        /// <summary>
        /// 필수 디자이너 변수입니다.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// 사용 중인 모든 리소스를 정리합니다.
        /// </summary>
        /// <param name="disposing">관리되는 리소스를 삭제해야 하면 true이고, 그렇지 않으면 false입니다.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form 디자이너에서 생성한 코드

        /// <summary>
        /// 디자이너 지원에 필요한 메서드입니다.
        /// 이 메서드의 내용을 코드 편집기로 수정하지 마십시오.
        /// </summary>
        private void InitializeComponent()
        {
           // 생성
            this._weatherInfoBox4 = new Google.Service.WeatherInfoBox();
            this._weatherInfoBox3 = new Google.Service.WeatherInfoBox();
            this._weatherInfoBox2 = new Google.Service.WeatherInfoBox();
            this._weatherInfoBox1 = new Google.Service.WeatherInfoBox();
            // 
            // 속성
            // _weatherInfoBox4
            //
            this._weatherInfoBox4.Location = new System.Drawing.Point(172, 269);
            this._weatherInfoBox4.Name = "_weatherInfoBox4";
            this._weatherInfoBox4.Size = new System.Drawing.Size(154, 98);
            this._weatherInfoBox4.TabIndex = 4;
            //
            // _weatherInfoBox3
            //
            this._weatherInfoBox3.Location = new System.Drawing.Point(12, 269);
            this._weatherInfoBox3.Name = "_weatherInfoBox3";
            this._weatherInfoBox3.Size = new System.Drawing.Size(154, 98);
            this._weatherInfoBox3.TabIndex = 4;
            //
            // _weatherInfoBox2
            //
            this._weatherInfoBox2.Location = new System.Drawing.Point(172, 165);
            this._weatherInfoBox2.Name = "_weatherInfoBox2";
            this._weatherInfoBox2.Size = new System.Drawing.Size(154, 98);
            this._weatherInfoBox2.TabIndex = 4;
            //
            // _weatherInfoBox1
            //
            this._weatherInfoBox1.Location = new System.Drawing.Point(12, 165);
            this._weatherInfoBox1.Name = "_weatherInfoBox1";
            this._weatherInfoBox1.Size = new System.Drawing.Size(154, 98);
            this._weatherInfoBox1.TabIndex = 4;
            //
            // GoogleWeather
            // 
            // 현재 폼에 컨트롤 등록
            this.Controls.Add(this._weatherInfoBox4);
            this.Controls.Add(this._weatherInfoBox3);
            this.Controls.Add(this._weatherInfoBox2);
            this.Controls.Add(this._weatherInfoBox1);
            }

        #endregion

        // 오브젝트 선언
        private WeatherInfoBox _weatherInfoBox1;
        private WeatherInfoBox _weatherInfoBox2;
        private WeatherInfoBox _weatherInfoBox3;
        private WeatherInfoBox _weatherInfoBox4;

  

    }
}

 

관련글 더보기