본문 바로가기

프로그래밍/C#

C# Grid 그리기?...라기보단 차트모양으로 선그리기..^^;

반응형

        public void Drawgrid(System.Windows.Forms.Panel panel, int xstart, int ystart, int Yquantity, int Xquantity)
        {
            int height = panel.Height;
            int width = panel.Width;
            m_BaseRGBbmp = new Bitmap(width, height);
            Graphics grp = Graphics.FromImage(m_BaseRGBbmp);
            Pen p = new Pen(Color.FromArgb(80,100,100,100));

            float dx = 1.0f * width / Xquantity;
            float dy = 1.0f * height / Yquantity;

            List<PointF> vecxp = new List<PointF>();// 가로축 그리기
            List<PointF> vecyp = new List<PointF>();// 세로축 그리기

            //X=0축 그리기
            vecxp.Add(new PointF(xstart - 3, height - ystart));
            vecxp.Add(new PointF(width, height - ystart));//
            grp.DrawLines(Pens.Black, vecxp.ToArray());

            for (int i = 0; i < Yquantity+1;i++ )//
            {
                vecxp.Clear();
                vecxp.Add(new PointF(xstart, height - i * dy));
                vecxp.Add(new PointF(width, height - i * dy));
                grp.DrawLines(p, vecxp.ToArray());
            }
           
            vecyp.Add(new PointF(xstart, height - ystart));
            vecyp.Add(new PointF(xstart, 0));
            grp.DrawLines(Pens.Black, vecyp.ToArray());
            for (int i = 0; i < Xquantity; i++)
            {
                if (i % 10 == 0)
                {
                    vecyp.Clear();
                    vecyp.Add(new PointF(xstart + i * dx, height - ystart));
                    vecyp.Add(new PointF(xstart + i * dx, 0));
                    Trace.WriteLine(xstart + i * dx +":"+Convert.ToString(350 +i * 0.5) );
                    grp.DrawLines(p, vecyp.ToArray());
                }
            }

            panel.BackgroundImage = (Image)m_BaseRGBbmp;

        }

반응형