Posted
Filed under .NET/C#
C# HashTable을 이용하여 국가를 검색하면 그 국가에 해당하는 꽃 이름이
꽃 이름을 통하여 검색하면 해당되는 국가가 나타나도록...
 
flower.cs
 class flower
    {
        private string fl;
        public string Flower
        {
            get
            {
                return fl;
            }
            set
            {
                fl = value;
            }
        }
    }

world.cs
 class world
    {
        private string wl;
        public string World
        {
            get
            {
                return wl;
            }
            set
            {
                wl = value;
            }
        }
    }

form.cs
public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        flower fl = new flower();
        world wl = new world();
        
        Hashtable flower = new Hashtable();
        Hashtable world = new Hashtable();

        private void button1_Click(object sender, EventArgs e)
        {
            object o = textBox1.Text;
            textBox2.Text = flower[textBox1.Text].ToString();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            fl.Flower = textBox1.Text;
            wl.World = textBox2.Text;

            flower.Add(fl.Flower, wl.World);
            world.Add(wl.World, fl.Flower);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            object o = textBox2.Text;
            textBox1.Text = world[textBox2.Text].ToString();
        }
    }
2010/01/03 20:52 2010/01/03 20:52
Posted
Filed under .NET/C#
C# 시리얼 통신 소스입니다.
소스가 너무 허접하여(?) 공개하기가 뭐시기 하여 올리지 않았는데...

 찾으시는 분이 많아서.. 
뭐, 혼자 하드에 썩어두면 뭐하나 싶기도 하고..
사실적으로, 따지면 귀차니즘도 있고 해서

그냥 블로그에 올립니다.
필요 하린 분은 다운로드 해 가세요..!!
2009/12/30 22:48 2009/12/30 22:48
Posted
Filed under .NET/C#
using System;
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.Diagnostics;
using System.Windows.Forms.DataVisualization.Charting;
using System.Threading;

namespace CPUUsage
{
    public partial class Form1 : Form
    {
        private Thread addDataRunner;
        public delegate void AddDataDelegate();
        public AddDataDelegate addDataDel;
        public double state;

        PerformanceCounter p;
        public Form1()
        {
            InitializeComponent();
        }

        private void btnShow_Click(object sender, EventArgs e)
        {
            p = new PerformanceCounter();
            p.CategoryName = "Processor";
            p.CounterName = "% Processor Time";
            p.InstanceName = "_Total";
 
            addDataRunner.Start();
        }


        private void Form1_Load(object sender, EventArgs e)
        {
            //Thread
            ThreadStart addDataThreadStart = new ThreadStart(AddDataThreadLoop);
            addDataRunner = new Thread(addDataThreadStart);

            addDataDel += new AddDataDelegate(AddData);


            chart1.ChartAreas[0].AxisX.Minimum = 0;
            chart1.ChartAreas[0].AxisX.Maximum = 60;

            chart1.ChartAreas[0].AxisY.Minimum = 0;
            chart1.ChartAreas[0].AxisY.Maximum = 100;

            chart1.Series.Clear();

            Series newSeries = new Series("CPU Usage");
            newSeries.ChartType = SeriesChartType.Spline;
            newSeries.BorderWidth = 2;
            newSeries.Color = Color.Orange;
            newSeries.XValueType = ChartValueType.Double;
            chart1.Series.Add(newSeries);
        }

        private void AddDataThreadLoop()
        {
            while (true)
            {
                chart1.Invoke(addDataDel);

                Thread.Sleep(1000);
            }
        }

        public void AddData()
        {
            foreach (Series ptSeries in chart1.Series)
            {
                AddNewPoint(ptSeries);
            }
        }
        public void AddNewPoint(Series ptSeries)
        {
            float usage = p.NextValue();

            ptSeries.Points.AddXY(state, usage);
            lbUsage.Text = ((int)usage).ToString()+"%";
            lbPoint.Text = string.Format("{0}{1}", state.ToString()," sec");

            if (state % 60 == 0)
            {
                chart1.ChartAreas[0].AxisX.Minimum = state;
                chart1.ChartAreas[0].AxisX.Maximum = state+60;
            }
            
            state++;
            
            chart1.Invalidate();
        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            addDataRunner.Abort();
        }

    }
}

C#으로 CPU사용량 측정 프로그램 소스 코드입니다.
chart는 MS chart를 이용하였습니다.(MS chart를 이용하시려면 .net Framework 3.5 sp1, mschart관련 컴포넌트가 필요합니다..)

2009/09/18 17:04 2009/09/18 17:04