コード例 #1
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            int  port       = 0;
            bool canConvert = int.TryParse(textPort.Text, out port);

            if (canConvert == false)
            {
                MessageBox.Show("ポート番号に数値を入力してください");
                return;
            }

            try
            {
                server_ = new HandleServer();
                server_.start(port);
                server_.RecivedMessageEvent = (string name, string text) =>
                {
                    if (this.InvokeRequired)                    //別スレッドから呼び出されたとき Invokeして呼びなおす
                    {
                        this.Invoke(new Action(() => server_.RecivedMessageEvent(name, text)), null);
                        return;
                    }

                    textInfo.Text         += (name + " >> " + text + "\r\n");
                    textInfo.HideSelection = false;
                    textInfo.AppendText("\n");
                };

                server_.RecivedImageEvent = (string name, byte[] image) =>
                {
                    if (this.InvokeRequired)//別スレッドから呼び出されたとき Invokeして呼びなおす
                    {
                        this.Invoke(new Action(() => server_.RecivedImageEvent(name, image)), null);
                        return;
                    }

                    pictureBox2.SizeMode = PictureBoxSizeMode.Zoom;
                    Image img = Util.ByteArrayToImage(image);
                    pictureBox2.Image = img;
                };

                pintedImg_ = new Bitmap(pictureBox1.Width, pictureBox1.Height);
                isDrawing_ = false;
                ChagenButtonState();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: ayk24/PaintgameWithKinect
        private void btnStart_Click(object sender, EventArgs e)
        {
            int  port       = 0;
            bool canConvert = int.TryParse(textPort.Text, out port);

            using (System.IO.StreamReader file = new System.IO.StreamReader(@".\test.txt", System.Text.Encoding.GetEncoding("shift_jis")))
            {
                string        line      = "";
                List <string> themeList = new List <string>();
                String        theme     = "";

                while ((line = file.ReadLine()) != null)
                {
                    themeList.Add(line);
                }
                Random rnd       = new System.Random();
                int    intResult = rnd.Next(20);

                theme          = themeList[intResult];
                textInfo.Text += ("「" + theme + "」を描いてください\r\n");
                if (canConvert == false)
                {
                    MessageBox.Show("ポート番号に数値を入力してください");
                    return;
                }

                try
                {
                    server_ = new HandleServer();
                    server_.start(port);
                    server_.theme = theme;
                    server_.RecivedMessageEvent = (string name, string text) =>
                    {
                        if (this.InvokeRequired)//別スレッドから呼び出されたとき Invokeして呼びなおす
                        {
                            this.Invoke(new Action(() => server_.RecivedMessageEvent(name, text)), null);
                            return;
                        }

                        textInfo.Text += (name + " >> " + text + "\r\n");

                        if (text == server_.theme)
                        {
                            Correct();
                            textInfo.Text += (name + "さんが正解!答えは「" + server_.theme + "」\r\n");
                            rnd            = new System.Random();
                            intResult      = rnd.Next(10);

                            server_.theme  = themeList[intResult];
                            textInfo.Text += ("「" + server_.theme + "」を描いてください\r\n");
                        }

                        textInfo.HideSelection = false;
                        textInfo.AppendText("\n");
                    };

                    pintedImg_ = new Bitmap(pictureBox1.Width, pictureBox1.Height);
                    isDrawing_ = false;
                    ChagenButtonState();

                    foreach (var potentialSensor in KinectSensor.KinectSensors)
                    {
                        if (potentialSensor.Status == KinectStatus.Connected)
                        {
                            this.sensor = potentialSensor;
                            break;
                        }
                    }

                    if (null != this.sensor)
                    {
                        // Turn on the skeleton stream to receive skeleton frames
                        this.sensor.SkeletonStream.Enable();

                        // Add an event handler to be called whenever there is new color frame data
                        this.sensor.SkeletonFrameReady += this.SensorSkeletonFrameReady;

                        // Start the sensor!
                        try
                        {
                            this.sensor.Start();
                        }
                        catch (IOException)
                        {
                            this.sensor = null;
                        }
                    }
                }

                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }