Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > .NET Framework > Forum > winApp C# pictruebox / Graphics.DrawLine ผมอยากได้ประมาณนี้ครับ แต่งงๆไม่รู้จะเขียนโค้ดยังไง



 

winApp C# pictruebox / Graphics.DrawLine ผมอยากได้ประมาณนี้ครับ แต่งงๆไม่รู้จะเขียนโค้ดยังไง

 



Topic : 131011



โพสกระทู้ ( 4,436 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook



อยากได้ประมาณนี้ครับ

555

55


พอ out control ก็ให้วงๆไว้แบบนี้



Tag : .NET, Win (Windows App), C#, VS 2012 (.NET 4.x)







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2018-05-09 17:10:23 By : lamaka.tor View : 914 Reply : 2
 

 

No. 1

Guest


เออคืดว่า บ่สันทัดเร่ื่องนี้ท่อได๋เด้อ เบิงเอาเองโลด 555 (สวนมากกะสิใช้แต่ Control DataVisualization Charting )
http://csharphelper.com/blog/2014/11/draw-a-labeled-line-graph-that-displays-value-tooltips-in-c/
http://csharphelper.com/blog/2015/06/graph-the-sine-cosine-and-tangent-functions-in-c/






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-05-10 09:12:17 By : ฺBundit
 


 

No. 2



โพสกระทู้ ( 4,436 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

ตอบความคิดเห็นที่ : 1 เขียนโดย : ฺBundit เมื่อวันที่ 2018-05-10 09:12:17
รายละเอียดของการตอบ ::
ขอบคุณมากครับ
เดี๋ยวลองดูก่อนนะครับ

โค้ดผมหลักๆจะมาณนี้ครับ (ใช้สำหรับทำ control chart เพื่อควบคุมงาน)
Code (C#)
namespace TORServices.FormsTor
{
 public class DataControlChart
    {
        public string _Man; public DateTime _date; public double _value;
        public DataControlChart(DateTime d, string m, double v)
        {
            _Man = m; _date = d; _value = v;
        }

    }

        public partial class controlChart : UserControl
    {
        /// <summary> 
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary> 
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Component Designer generated code

        /// <summary> 
        /// Required method for Designer support - do not modify 
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.pictureBox1 = new System.Windows.Forms.PictureBox();
            this.pictureBox2 = new System.Windows.Forms.PictureBox();
            this.panel1 = new System.Windows.Forms.Panel();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit();
            this.panel1.SuspendLayout();
            this.SuspendLayout();
            // 
            // pictureBox1
            // 
            this.pictureBox1.BackColor = System.Drawing.Color.Black;
            this.pictureBox1.Location = new System.Drawing.Point(0, 0);
            this.pictureBox1.Name = "pictureBox1";
            this.pictureBox1.Size = new System.Drawing.Size(621, 300);
            this.pictureBox1.TabIndex = 0;
            this.pictureBox1.TabStop = false;
            // 
            // pictureBox2
            // 
            this.pictureBox2.BackColor = System.Drawing.Color.Black;
            this.pictureBox2.Dock = System.Windows.Forms.DockStyle.Left;
            this.pictureBox2.Location = new System.Drawing.Point(0, 0);
            this.pictureBox2.Name = "pictureBox2";
            this.pictureBox2.Size = new System.Drawing.Size(129, 346);
            this.pictureBox2.TabIndex = 1;
            this.pictureBox2.TabStop = false;
            // 
            // panel1
            // 
            this.panel1.AutoScroll = true;
        
            this.panel1.Controls.Add(this.pictureBox1);

            this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.panel1.Location = new System.Drawing.Point(129, 0);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(747, 346);
            this.panel1.TabIndex = 1;
            
            // 
            // controlChart
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.Controls.Add(this.panel1);
            this.Controls.Add(this.pictureBox2);
            this.Name = "controlChart";
            this.Size = new System.Drawing.Size(876, 346);
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit();
            this.panel1.ResumeLayout(false);
            this.ResumeLayout(false);

        }

        #endregion



        // Set value 
        double _avg = 0;
        double _sd = 0;

        private PictureBox pictureBox1;
        private PictureBox pictureBox2;
        private Panel panel1;
        private int SizeColumn = 50;

        public controlChart()
        {
            InitializeComponent();
        }

        #region _Property
        private int _digi = 4;
        [System.ComponentModel.Browsable(true),
        System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Always),
        System.ComponentModel.Category("Behavior")]
        public int Decimal
        {
            get { return _digi; }
            set { _digi = value; RefreshChart(); }
        }
        [System.ComponentModel.Browsable(true)]
        [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Always)]
        [System.ComponentModel.Category("Behavior")]
        public double ValueMean
        {
            get { return _avg; }
            set { _avg = value; RefreshChart(); }
        }

        [System.ComponentModel.Browsable(true)]
        [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Always)]
        [System.ComponentModel.Category("Behavior")]
        public double ValueSD
        {
            get { return _sd; }
            set { _sd = value; RefreshChart(); }
        }
        #endregion
        public List<DataControlChart> dataControlChart;
        public void AddData(DataControlChart value)
        {
            if (dataControlChart == null) dataControlChart = new List<DataControlChart>();
            dataControlChart.Add((DataControlChart)value);
           // RefreshChart();
        }
        public void AddRangeData(List<DataControlChart> value)
        {
            if (dataControlChart == null) dataControlChart = new List<DataControlChart>();
            dataControlChart.AddRange((List<DataControlChart>)value);
          //  RefreshChart();
        }
        public void RemoveData(int item)
        {
            if (dataControlChart == null) return;
            dataControlChart.RemoveAt(item);
            RefreshChart();
        }
        public void RefreshChart()
        {
            if (dataControlChart == null || dataControlChart.Count < 1) return;

            // Set PictureBox
            pictureBox1.Image = null;
            pictureBox1.Invalidate();

            // Set value 
            double vUp3SD = _avg + (3 * _sd);
            double vUp2SD = _avg + (2 * _sd);
            double vDwn2SD = _avg - (2 * _sd);
            double vDwn3SD = _avg - (3 * _sd);

            int lntMain = Convert.ToInt32(pictureBox1.Height / 2);
            int lntUp3SD = lntMain - Convert.ToInt32(lntMain / 1.2);
            int lntUp2SD = lntMain - Convert.ToInt32(lntMain / 2);
            int lntDwn2SD = lntMain + Convert.ToInt32(lntMain / 2);
            int lntDwn3SD = lntMain + Convert.ToInt32(lntMain / 1.2);

            double ddd = (lntDwn3SD - lntUp3SD) / (vUp3SD - vDwn3SD);
            pictureBox1.Width= ((dataControlChart.Count + 2) * SizeColumn <= this.panel1.Width) ?
                       this.panel1.Width : (dataControlChart.Count + 2) * SizeColumn;
            this.pictureBox1.Height = this.panel1.Height - 20;
            this.pictureBox2.Height = this.panel1.Height - 20;
            Bitmap b = new Bitmap(pictureBox1.Width, this.pictureBox1.Height);
            Bitmap b1 = new Bitmap(pictureBox2.Size.Width, pictureBox2.Size.Height);
            using (Graphics g = Graphics.FromImage(b1))
            {
                g.Clear(pictureBox1.BackColor);
                g.FillRectangle(Brushes.Black, new Rectangle(0, 0, b.Width, b.Height));
                System.Drawing.Pen p;
                g.DrawString("     Main--" + _avg.ToString("N" + _digi), this.Font, Brushes.Azure, 5, lntMain - 5);
                g.DrawString(" Main - 2SD--" + vDwn2SD.ToString("N" + _digi), this.Font, Brushes.Azure, 5, lntDwn2SD - 5);
                g.DrawString(" Main + 2SD--" + vUp2SD.ToString("N" + _digi), this.Font, Brushes.Azure, 5, lntUp2SD - 5);
                g.DrawString("  Main -3SD--" + vDwn3SD.ToString("N" + _digi), this.Font, Brushes.Azure, 5, lntDwn3SD - 5);
                g.DrawString(" Main + 3SD--" + vUp3SD.ToString("N" + _digi), this.Font, Brushes.Azure, 5, lntUp3SD - 5);
            }
            pictureBox2.BackgroundImage = b1;
            using (Graphics g = Graphics.FromImage(b))
            {
                g.Clear(pictureBox1.BackColor);
                g.FillRectangle(Brushes.Black, new Rectangle(0, 0, b.Width, b.Height));
                System.Drawing.Pen p;

                g.DrawLine( new System.Drawing.Pen(Brushes.Pink, 3), 0, lntMain, b.Width, lntMain);
                g.DrawLine(new System.Drawing.Pen(Brushes.Yellow, 2), 0, lntDwn2SD, b.Width, lntDwn2SD);
                g.DrawLine(new System.Drawing.Pen(Brushes.Yellow, 2), 0, lntUp2SD, b.Width, lntUp2SD);
                g.DrawLine( new System.Drawing.Pen(Brushes.Red, 2), 0, lntDwn3SD, b.Width, lntDwn3SD);
                g.DrawLine(new System.Drawing.Pen(Brushes.Red, 2), 0, lntUp3SD, b.Width, lntUp3SD);

                int x1 = 0;
                int y1 = 0;
                int x2 = 0;
                int y2 = 0;
                x1 = 0;
                x2 = SizeColumn + Convert.ToInt32(SizeColumn / 2.2);
                y1 = lntMain;
                y2 = 0;
                p = new System.Drawing.Pen(Brushes.Blue, 5);
                p.EndCap = System.Drawing.Drawing2D.LineCap.RoundAnchor;
                p.StartCap = System.Drawing.Drawing2D.LineCap.RoundAnchor;
                double c = (lntDwn3SD - lntUp3SD) / (vUp3SD - vDwn3SD);
                if (dataControlChart != null && dataControlChart.Count > 0)
                {
                    for (int i = 0; i <= dataControlChart.Count - 1; i++)
                    {
                        if (i > 0)
                        {
                            x2 = x2 + SizeColumn;
                        }
                        if (!string.IsNullOrEmpty("" + dataControlChart[i]._value))
                        {
                            try
                            {
                                // MessageBox.Show(ddd +"\n "+ vUp3SD + "\n "+ (double)dataControlChart[i]._value + "\n"+ lntUp3SD);
                                y2 = (int)((ddd * (vUp3SD - (double)dataControlChart[i]._value)) + lntUp3SD);
                               // if(y2>pictureBox1.Height)
                                g.DrawLine(p, x1, y1, x2, y2);
                                g.DrawString(((double)dataControlChart[i]._value).ToString("N" + _digi) + Environment.NewLine +
                                    dataControlChart[i]._date.ToString("dd/MM/yyyy"),
                                    this.Font, Brushes.White, x2 + 5, y2);
                                x1 = x2;
                                y1 = y2;
                            }
                            catch { }
                        }
                    }
                }
            }
            pictureBox1.BackgroundImage = b;

        }

        private void controlChart_Resize(object sender, EventArgs e)
        {
            RefreshChart();
        }
        protected override void OnSizeChanged(EventArgs e)
        {
            base.OnSizeChanged(e);
            pictureBox1.Height = this.panel1.Height; 
        }
    }

}


ใช้งาน
Code (C#)
 private void Form1_Load(object sender, EventArgs e)
        {
            for (int i = 0; i < 100; i++)
            {
                double d =Convert.ToDouble(new Random().Next(250, 301))/Convert.ToDouble(10000);
                mainSDPanel1.Add(d);
                System.Threading.Thread.Sleep(50);
            }
                 
            mainSDPanel1.RefreshData();
        }


เผื่อท่านใดมองโค้ดแล้วดูว่าควรแก้ไขตรงไหนนะครับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-05-11 09:25:58 By : lamaka.tor
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : winApp C# pictruebox / Graphics.DrawLine ผมอยากได้ประมาณนี้ครับ แต่งงๆไม่รู้จะเขียนโค้ดยังไง
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 00
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่