TransWikia.com

Cómo desarrollar un programa que cambie las entre las ventanas de Windows

Stack Overflow en español Asked by Andeman Cervantes on November 15, 2021

Pues bueno, de momento no tengo la idea de como empezar dicho código, pero pues con ayuda de un sensor de movimiento y el protocolo de comunicación serial de Visual estoy intentado crear algo como un detector, ya he hecho la comunicación y mi programa ya manda una variable (esto lo realice con anterioridad) pero no se como hacer que en caso que detecte, se haga un cambio de ventanas en Windows, alguien sabe si es posible en c# o me tengo que mover a otro lenguaje?
introducir la descripción de la imagen aquí

Aquí una imagen del form

El chiste es que en mi textbox de Distancia segura y distancia minima se coloque un valor y en el cuadro de arriba que es un picturebox se va cambiando el color a rojo en caso de que mi sensor lea un valor que se encuentre un sujeto próximo

Pen p, p1;
       int i, estado, j;
       Graphics g,g1;
       int d, x1 = 10, x2, x3,x4,x5,x6,x7,x8;
       int y1 = 10, y2, y3,y4,y5,y6,y7,y8;

       public Form1()
       {
           InitializeComponent();
       }

       private void timer1_Tick(object sender, EventArgs e)
       {
           if (estado == 1)
           {
               label3.Text = "";
               j++;
               label1.Text = Convert.ToString(j);
               g1.DrawLine(p, x1, y1, x1 + j, y1);
               x1 += j;

           }
           else if (estado == 2)
           {
               j++;
               label1.Text = Convert.ToString(j);
               label3.Text = "Girando";
               
           }
           else if (estado == 3)
           {
               label3.Text = "";
               j++;
               label1.Text = Convert.ToString(j);
               g1.DrawLine(p, x1, y1, x1, y1 + j );
               x2 = x1;
               y2 = y1 + j ;
               
           }
           else if (estado == 4)
           {
               
               j++;
               label1.Text = Convert.ToString(j);
               label3.Text = "Girando";
           }
           else if (estado == 5)
           {
               label3.Text = "";
               j++;
               label1.Text = Convert.ToString(j);
               g1.DrawLine(p, x2, y2, x2 - j , y2);
               x3 = x2 - j;
               y3 = y2;
               
           }
           else if (estado == 6)
           {
               j++;
               label1.Text = Convert.ToString(j);
               label3.Text = "Girando";
           }
           else if (estado == 7)
           {
               label3.Text = "";
               j++;
               label1.Text = Convert.ToString(j);
               g1.DrawLine(p, x3, y3, x3, y3 - j);
               x1 = x3;
               y1 = y3 - j ;
           }
           else if (estado == 8)
           {
               j++;
               label1.Text = Convert.ToString(j);
               label3.Text = "Girando";
           }
           

       }

       private void Form1_Load(object sender, EventArgs e)
       {
           g = Pdibujo.CreateGraphics();
           g1 = pictureBox1.CreateGraphics();
           b1 = new SolidBrush(Color.Red);
           b2 = new SolidBrush(Color.Yellow);
           b3 = new SolidBrush(Color.Green);
           p1 = new Pen(Color.Blue);
           p = new Pen(Color.Black);
           timer1.Enabled = true;
           Tdistancia.Text = "60";
           SerialPort.PortName = "COM12";
           SerialPort.BaudRate = 9600;
           SerialPort.Open();
           a1 = 16;
           a2 = 6;
       }

       private void SerialPort_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
       {
           Byte z;

           if (SerialPort.BytesToRead > 0)
           {
               z = (byte)SerialPort.ReadByte();
               Delegado Escribir = new Delegado(this.vLoadData);
               this.Invoke(Escribir, z);
           }
       }
       
       delegate void Delegado(Byte z);
       void vLoadData(Byte z)
       {
           int Ddis;
           
           Ddis = Convert.ToInt16(z);
           distancia = Ddis;
           Tdistancia.Text = Convert.ToString(Ddis);
       }

       private void Form1_FormClosing(object sender, FormClosingEventArgs e)
       {
           SerialPort.Close();
       }

       private void Benviar_Click(object sender, EventArgs e)
       {
           String s1, s2;
           int.TryParse(Td1.Text, out d1);
           int.TryParse(Td2.Text, out d2);
           a1 = d1;
           a2 = d2;
           s1 = Convert.ToString(Convert.ToChar(d1));
           s2 = Convert.ToString(Convert.ToChar(d2));

           SerialPort.Write(s1);
           SerialPort.Write(s2);
       }
       
       Brush b1, b2, b3;
       int d1, d2, a1, a2,distancia;
       private void Tdistancia_TextChanged(object sender, EventArgs e)
       {
           int.TryParse(Tdistancia.Text, out d);
           if (d > 15 && i == 0)
           {
               i = 1;
               estado = 1;
               label2.Text = Convert.ToString(i);
               j = 0;
               
           }

           else if (d < 15 && i == 1)
           {
               i = 2;
               estado = 2;
               label2.Text = Convert.ToString(i);
               j = 0;
               

           }
           else if (d > 15 && i == 2)
           {
               i = 3;
               estado = 3;
               label2.Text = Convert.ToString(i);
               j = 0;
               
           }
           else if (d < 15 && i == 3)
           {
               i = 4;
               estado = 4;
               label2.Text = Convert.ToString(i);
               
               j = 0;
               
           }
           else if (d > 15 && i == 4)
           {
               i = 5;
               estado = 5;
               label2.Text = Convert.ToString(i);
               
               j = 0;

           }
           else if (d < 15 && i == 5)
           {
               i = 6;
               estado = 6;
               label2.Text = Convert.ToString(i);
               
               j = 0;

           }
           else if (d > 15 && i == 6)
           {
               i = 7;
               estado = 7;
               label2.Text = Convert.ToString(i);
               
               j = 0;

           }
           else if (d > 15 && i == 7)
           {
               i = 8;
               estado = 8;
               label2.Text = Convert.ToString(i);
               i = 0;
               j = 0;

           }

           g.Clear(Color.White);
           if (distancia > a1)
           {
               g.FillRectangle(b3, 0, 0, distancia * 10, 50);
           }
           else if (distancia <= a1 && distancia > a2)
           {
               g.FillRectangle(b2, 0, 0, distancia * 10, 50);
           }
           else if (distancia <= a2)
           {
               g.FillRectangle(b1, 0, 0, distancia * 10, 50);
           }
       }

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP