Usuario
Como tener siempre el mismo %

Pregunta
-
Buenas tengo este problema
no se como mantener siempre el mismo % de tamaño soble el formulario
es decir si 371 es 100%
300 es 80.86253369272237
como aplico el porcentaje a un picture mara que mantega la relacion
Medida.Height = (100 / Me.Height) * 300
Todas las respuestas
-
-
Dim Rojo1 As Integer = (Medida.Height * 15) / 100 Dim Amarillo1 As Integer = (Medida.Height * 35) / 100 Dim verde As Integer = (Medida.Height * 50) / 100 Dim Amarillo2 As Integer = (Medida.Height * 35) / 100 Dim Rojo2 As Integer = (Medida.Height * 15) / 100 'MsgBox(Rojo1 + Amarillo1 + verde + Amarillo2 + Rojo2) '' ''Dim lap2 As Pen = New nPen(Brushes.Blue, 1) Dim Colorojo As Pen = New Pen(Brushes.Red, grosor) Dim Colorojo2 As Pen = New Pen(Brushes.Red, grosor) Dim ColoAmarillo As Pen = New Pen(Brushes.Yellow, grosor) Dim ColoAmarillo2 As Pen = New Pen(Brushes.Yellow, grosor) Dim Coloverde As Pen = New Pen(Brushes.Green, grosor) Dim ColoNegro As Pen = New Pen(Brushes.Black, grosor) Medida.CreateGraphics.DrawLine(Colorojo, Centrar, 0, Centrar, Rojo1) Medida.CreateGraphics.DrawLine(ColoAmarillo, Centrar, Rojo1, Centrar, Amarillo1) Medida.CreateGraphics.DrawLine(Coloverde, Centrar, Rojo1 + Amarillo1, Centrar, verde)
No puedo hacer que me pinte las lineas una detras de otra por porcentaje
-
Buenas JETET
No entiendo la pregunta, ya estas pintando las líneas con valores dinámicos no? Cual seria el resultado esperado? Supongo que el problema lo estas teniendo en la línea recta no?
Atte
No olvides votar si mi comentario te ha ayudado y marcarlo como respuesta si ha sido la solución!
-
Gracias por responde
el problema lo tengo aqui, no soy capaz de unir las lineas
la verde tiene que tener un 50% del total
las amarillas un 35%
y las rojas 15%
la verde tiene que quedar en el centro
despues las amarillas, y despues las rojas
como se ve en el circulo
Dim Rojo1 As Integer = (Medida.Height * 15) / 100 Dim Amarillo1 As Integer = (Medida.Height * 35) / 100 Dim verde As Integer = (Medida.Height * 50) / 100 Dim Amarillo2 As Integer = (Medida.Height * 35) / 100 Dim Rojo2 As Integer = (Medida.Height * 15) / 100
-
-
Creo que lo resolví, el tema es que heigth mide de abajo hacia arriba hay que descontarle a medida que dibuja una nueva línea, otra cosa los porcentajes obviamente no deben superar el 100, prueba y me dices
Dim r1 As Integer = 5 'valores para cargar mediate variable si es necesario Dim a1 As Integer = 20 'valores para cargar mediate variable si es necesario Dim v1 As Integer = 50 'valores para cargar mediate variable si es necesario Dim a2 As Integer = 20 'valores para cargar mediate variable si es necesario Dim r2 As Integer = 5 'valores para cargar mediate variable si es necesario 'Falta condición para verificar que los porcentajes no superen los 100 Dim Rojo1 As Integer = Medida.Height - ((Medida.Height * r1) / 100) 'Para dibujar de abajo hacia arriba Dim Amarillo1 As Integer = Rojo1 - ((Medida.Height * a1) / 100) Dim verde As Integer = Amarillo1 - ((Medida.Height * v1) / 100) Dim Amarillo2 As Integer = verde - ((Medida.Height * a2) / 100) Dim Rojo2 As Integer = Amarillo2 - ((Medida.Height * r2) / 100) Dim HeigH As Integer = Medida.Height 'Los valores de la nueva línea se dibujan a partir de la última Medida.CreateGraphics.DrawLine(Colorojo, 5, HeigH, 5, Rojo1) Medida.CreateGraphics.DrawLine(ColoAmarillo, 5, Rojo1, 5, Amarillo1) Medida.CreateGraphics.DrawLine(Coloverde, 5, Amarillo1, 5, verde) Medida.CreateGraphics.DrawLine(ColoAmarillo2, 5, verde, 5, Amarillo2) Medida.CreateGraphics.DrawLine(Colorojo, 5, Amarillo2, 5, Rojo2)
Fue un dolor de cabeza, pongo variables para cargar en caso de que tengas que ingresar nuevos porcentaje, estos los puse al azar tu los colocas como correspondan
me dices si te funciona Saludos
- Editado Marcelo PF jueves, 24 de agosto de 2017 20:20
- Propuesto como respuesta Jorge TurradoMVP jueves, 24 de agosto de 2017 20:24
- Votado como útil Jorge TurradoMVP lunes, 28 de agosto de 2017 8:49
-
-
Solo modifica los porsentajes en
Dim r1 As Integer = 10 'valores para cargar mediate variable si es necesario Dim a1 As Integer = 15 'valores para cargar mediate variable si es necesario Dim v1 As Integer = 50 'valores para cargar mediate variable si es necesario Dim a2 As Integer = 15 'valores para cargar mediate variable si es necesario Dim r2 As Integer = 10 'valores para cargar mediate variable si es necesario
tendría que funcionar
- Editado Marcelo PF jueves, 24 de agosto de 2017 20:51
-
Lo tengo que poner de esta manera para que me pinte las lineas en el picture
Medida.Refresh() Medida.BackColor = Color.Black Dim media As Decimal = Medida.Height / 100 Dim Rojo1 As Integer = media * 10 Dim Amarillo1 As Integer = media * 15 Dim verde As Integer = media * 50 Dim Amarillo2 As Integer = media * 15 Dim Rojo2 As Integer = media * 10 'MsgBox(Rojo1 + Amarillo1 + verde + Amarillo2 + Rojo2) '' ''Dim lap2 As Pen = New nPen(Brushes.Blue, 1) Dim Colorojo As Pen = New Pen(Brushes.Red, grosor) Dim Colorojo2 As Pen = New Pen(Brushes.Red, grosor) Dim ColoAmarillo As Pen = New Pen(Brushes.Yellow, grosor) Dim ColoAmarillo2 As Pen = New Pen(Brushes.Yellow, grosor) Dim Coloverde As Pen = New Pen(Brushes.Green, grosor) Dim ColoNegro As Pen = New Pen(Brushes.Black, grosor) Medida.CreateGraphics.DrawLine(Colorojo, Centrar, 0, Centrar, Rojo1) Medida.CreateGraphics.DrawLine(ColoAmarillo, Centrar, Rojo1, Centrar, Amarillo1 + Rojo1) Medida.CreateGraphics.DrawLine(Coloverde, Centrar, Amarillo1 + Rojo1, Centrar, Amarillo1 + Rojo1 + verde) Medida.CreateGraphics.DrawLine(ColoAmarillo2, Centrar, Amarillo1 + Rojo1 + verde, Centrar, Amarillo1 + Rojo1 + verde + Amarillo2) Medida.CreateGraphics.DrawLine(Colorojo, Centrar, Amarillo1 + Rojo1 + verde + Amarillo2, Centrar, Amarillo1 + Rojo1 + verde + Amarillo2 + Rojo2)
pero creo que las lineas amarilla y roja de abajo son algo mas chicas
-
Esto lo tengo en un button compiando tu código
Dim graf As Graphics = Me.CreateGraphics() Medida.BorderStyle = BorderStyle.None Dim grosor As Integer = 10 Medida.Width = grosor Medida.Height = 300 Dim i As Integer = 20 Dim d As Integer = 10 Dim b As Double = 100 '1096 Dim j As Integer = 0 Dim lap As Pen = New Pen(Brushes.Red) Medida.BackColor = Color.Black '' ''Dim lap2 As Pen = New Pen(Brushes.Blue, 1) Dim Colorojo As Pen = New Pen(Brushes.Red, grosor) Dim Colorojo2 As Pen = New Pen(Brushes.Red, grosor) Dim ColoAmarillo As Pen = New Pen(Brushes.Yellow, grosor) Dim ColoAmarillo2 As Pen = New Pen(Brushes.Yellow, grosor) Dim Coloverde As Pen = New Pen(Brushes.Green, grosor) Dim ColoNegro As Pen = New Pen(Brushes.Black, grosor) Dim r1 As Integer = 10 'valores para cargar mediate variable si es necesario Dim a1 As Integer = 15 'valores para cargar mediate variable si es necesario Dim v1 As Integer = 50 'valores para cargar mediate variable si es necesario Dim a2 As Integer = 15 'valores para cargar mediate variable si es necesario Dim r2 As Integer = 10 'valores para cargar mediate variable si es necesario 'Falta condición para verificar que los porcentajes no superen los 100 Dim Rojo1 As Integer = Medida.Height - ((Medida.Height * r1) / 100) 'Para dibujar de abajo hacia arriba Dim Amarillo1 As Integer = (Rojo1) - ((Medida.Height * a1) / 100) Dim verde As Integer = (Amarillo1) - ((Medida.Height * v1) / 100) Dim Amarillo2 As Integer = (verde) - ((Medida.Height * a2) / 100) Dim Rojo2 As Integer = (Amarillo2) - ((Medida.Height * r2) / 100) Dim HeigH As Integer = Medida.Height 'Los valores de la nueva línea se dibujan a partir de la última Medida.CreateGraphics.DrawLine(Colorojo, 5, HeigH, 5, Rojo1) Medida.CreateGraphics.DrawLine(ColoAmarillo, 5, Rojo1, 5, Amarillo1) Medida.CreateGraphics.DrawLine(Coloverde, 5, Amarillo1, 5, verde) Medida.CreateGraphics.DrawLine(ColoAmarillo2, 5, verde, 5, Amarillo2) Medida.CreateGraphics.DrawLine(Colorojo, 5, Amarillo2, 5, Rojo2) 'Medida.CreateGraphics.DrawLine(ColoNegro, 0, 150, 0, 155) 'CreateGraphics.DrawLine(Colorojo, 0, 0, 0, 50) 'CreateGraphics.DrawLine(ColoAmarillo, 0, 50, 0, 75) 'CreateGraphics.DrawLine(Coloverde, 0, 75, 0, 225) 'CreateGraphics.DrawLine(ColoAmarillo2, 0, 250, 0, 225) 'CreateGraphics.DrawLine(Colorojo, 0, 300, 0, 250) 'CreateGraphics.DrawLine(ColoNegro, 0, 150, 0, 155) End Sub
Si lo crees necesario cambia la cooredenada "5" por tu variabla "Centrar" no devería traer problemas
- Editado Marcelo PF jueves, 24 de agosto de 2017 21:15
- Marcado como respuesta JETET viernes, 25 de agosto de 2017 7:13
- Desmarcado como respuesta JETET viernes, 25 de agosto de 2017 7:16
-
Gracias marcelo todo ok pero todo lo calculo sobre el componente si cambio el tamaño de barra1
Medida.Height = (Me.Height * 80) / 100
cuando achico el componente los porcentajes de los colores no son los mismos
En la foto se puede apreciar que los colores de abajo son mas chicos
Gracias
- Editado JETET viernes, 25 de agosto de 2017 7:22
-
Si, si, yo lo hice igual solo que lo coloquel en el evento resize del Form, si colocas todo el código, cada vez que el form cambie de tamaño volverá a repintarce, para ello justo antes de pintar el picture medida colocas Medida.refresh() creo que ya lo tenías así.
Dim Rojo1 As Integer = Medida.Height - ((Medida.Height * r1) / 100) 'Para dibujar de abajo hacia arriba Dim Amarillo1 As Integer = (Rojo1) - ((Medida.Height * a1) / 100) Dim verde As Integer = (Amarillo1) - ((Medida.Height * v1) / 100) Dim Amarillo2 As Integer = (verde) - ((Medida.Height * a2) / 100) Dim Rojo2 As Integer = (Amarillo2) - ((Medida.Height * r2) / 100) Dim HeigH As Integer = Medida.Height 'Los valores de la nueva línea se dibujan a partir de la última Medida.Refresh() 'Aqui colocar tanto sea mediante button o en el evento resize del Form1 Medida.CreateGraphics.DrawLine(Colorojo, 5, HeigH, 5, Rojo1) Medida.CreateGraphics.DrawLine(ColoAmarillo, 5, Rojo1, 5, Amarillo1) Medida.CreateGraphics.DrawLine(Coloverde, 5, Amarillo1, 5, verde) Medida.CreateGraphics.DrawLine(ColoAmarillo2, 5, verde, 5, Amarillo2) Medida.CreateGraphics.DrawLine(Colorojo, 5, Amarillo2, 5, Rojo2)
No se si tiene el evento resize el componente que lo contiene , devería ser sobre él que actue el códogio
- Editado Marcelo PF viernes, 25 de agosto de 2017 9:28
-
Asi lo tengo y nada mira la imagen no se ajusta nada
Imports System.Drawing Imports System.Drawing.Drawing2D Public Class Barra Public alto As Integer = 0 Public bajo As Integer = 0 Private Sub Barra_Load(sender As Object, e As EventArgs) Handles Me.Load End Sub Private Sub Barra_MouseEnter(sender As Object, e As EventArgs) Handles Me.MouseEnter End Sub Private Sub Barra_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint Dim graf As Graphics = Me.CreateGraphics() 'Dim a As New GraphicsPath() Medida.BorderStyle = BorderStyle.Fixed3D 'Medida.Location = New Point(58, 58) Dim grosor As Double = 8 Dim Centrar As Integer = 4 'Medida.Visible = True Medida.Width = 8 Medida.Height = (Me.Height * 80) / 100 'MsgBox(Medida.Height) '' '' CREA LAS LINEAS ' ''Dim blackPen As New Pen(Color.Black, 1) ' ''graf.DrawLine(blackPen, 0, 10, 200, 10) ' ''For aa = Medida.Location.Y To 300 ' '' Dim point1 As Pen = New Pen(Brushes.Red, 2) ' '' graf.DrawLine(blackPen, Medida.Location.X, aa, Medida.Location.X - 10, aa) ' '' aa += 5 ' ''Next '' '' CREA LAS LINEAS Medida.Refresh() Medida.BackColor = Color.Black Dim r1 As Integer = 10 'valores para cargar mediate variable si es necesario Dim a1 As Integer = 15 'valores para cargar mediate variable si es necesario Dim v1 As Integer = 50 'valores para cargar mediate variable si es necesario Dim a2 As Integer = 15 'valores para cargar mediate variable si es necesario Dim r2 As Integer = 10 'valores para cargar mediate variable si es necesario Dim Rojo1 As Integer = Medida.Height - ((Medida.Height * r1) / 100) 'Para dibujar de abajo hacia arriba Dim Amarillo1 As Integer = (Rojo1) - ((Medida.Height * a1) / 100) Dim verde As Integer = (Amarillo1) - ((Medida.Height * v1) / 100) Dim Amarillo2 As Integer = (verde) - ((Medida.Height * a2) / 100) Dim Rojo2 As Integer = (Amarillo2) - ((Medida.Height * r2) / 100) Dim HeigH As Integer = Medida.Height 'Falta condición para verificar que los porcentajes no superen los 100 Dim Colorojo As Pen = New Pen(Brushes.Red, grosor) Dim Colorojo2 As Pen = New Pen(Brushes.Red, grosor) Dim ColoAmarillo As Pen = New Pen(Brushes.Yellow, grosor) Dim ColoAmarillo2 As Pen = New Pen(Brushes.Yellow, grosor) Dim Coloverde As Pen = New Pen(Brushes.Green, grosor) Dim ColoNegro As Pen = New Pen(Brushes.Black, grosor) Medida.CreateGraphics.DrawLine(Colorojo, Centrar, HeigH, Centrar, Rojo1) Medida.CreateGraphics.DrawLine(ColoAmarillo, Centrar, Rojo1, Centrar, Amarillo1) Medida.CreateGraphics.DrawLine(Coloverde, Centrar, Amarillo1, Centrar, verde) Medida.CreateGraphics.DrawLine(ColoAmarillo2, Centrar, verde, Centrar, Amarillo2) Medida.CreateGraphics.DrawLine(Colorojo, Centrar, Amarillo2, Centrar, Rojo2) '' ''Medida.CreateGraphics.DrawLine(ColoNegro, Centrar, 150, 0, 155) Label1.Location = New Point(Medida.Location.X - ((Label1.Width / 2) - 3), Medida.Location.Y - 20) Label2.Location = New Point(Medida.Location.X - (Label2.Width - 8), 100) Label3.Location = New Point(Medida.Location.X + 1, 100) 'Label2.Visible = False 'Label3.Visible = False Label1.Visible = False End Sub Private Sub Barra_Resize(sender As Object, e As EventArgs) Handles Me.Resize Dim graf As Graphics = Me.CreateGraphics() Medida.BorderStyle = BorderStyle.Fixed3D Dim grosor As Double = 8 Dim Centrar As Integer = 4 Medida.Width = 8 Medida.Height = (Me.Height * 80) / 100 Medida.Refresh() Medida.BackColor = Color.Black Dim r1 As Integer = 10 'valores para cargar mediate variable si es necesario Dim a1 As Integer = 15 'valores para cargar mediate variable si es necesario Dim v1 As Integer = 50 'valores para cargar mediate variable si es necesario Dim a2 As Integer = 15 'valores para cargar mediate variable si es necesario Dim r2 As Integer = 10 'valores para cargar mediate variable si es necesario Dim Rojo1 As Integer = Medida.Height - ((Medida.Height * r1) / 100) 'Para dibujar de abajo hacia arriba Dim Amarillo1 As Integer = (Rojo1) - ((Medida.Height * a1) / 100) Dim verde As Integer = (Amarillo1) - ((Medida.Height * v1) / 100) Dim Amarillo2 As Integer = (verde) - ((Medida.Height * a2) / 100) Dim Rojo2 As Integer = (Amarillo2) - ((Medida.Height * r2) / 100) Dim HeigH As Integer = Medida.Height 'Los valores de la nueva línea se dibujan a partir de la última Medida.Refresh() 'Aqui colocar tanto sea mediante button o en el evento resize del Form1 Dim Colorojo As Pen = New Pen(Brushes.Red, grosor) Dim Colorojo2 As Pen = New Pen(Brushes.Red, grosor) Dim ColoAmarillo As Pen = New Pen(Brushes.Yellow, grosor) Dim ColoAmarillo2 As Pen = New Pen(Brushes.Yellow, grosor) Dim Coloverde As Pen = New Pen(Brushes.Green, grosor) Dim ColoNegro As Pen = New Pen(Brushes.Black, grosor) Medida.CreateGraphics.DrawLine(Colorojo, 5, HeigH, 5, Rojo1) Medida.CreateGraphics.DrawLine(ColoAmarillo, 5, Rojo1, 5, Amarillo1) Medida.CreateGraphics.DrawLine(Coloverde, 5, Amarillo1, 5, verde) Medida.CreateGraphics.DrawLine(ColoAmarillo2, 5, verde, 5, Amarillo2) Medida.CreateGraphics.DrawLine(Colorojo, 5, Amarillo2, 5, Rojo2) End Sub
-
Bueno amigo como ves insisto con tu problema, ahora viendo tu imagen veo donde está el control que contiene a Medida, por lo tanto encontré una manera para que se distribuya , no hace falta redimensionar los colores mediante el porcentaje, sino que utilizo la propiedad anchor de Medida
Luego acomodo Medida en el contenedor, en mi caso el form, tu en el control
Para la tarea ocupo el evento ResizeEnd en vez del Resize o sea cuando se termina de formar, y el evento que utilizamos Paint del control
Hata acá bien, cual es el problema de la diferencia que veíamos sin pintar, los integer, ya que redondean la cantidad, por tal cuando el resultado de algún porcentaje no da entero redondea y nos queda ese pirex sin pintar, el parche o la solución es otorgarle al úlitmo trazo (Rojo2) el valor 0, por ahora no le encuentro otra solución ya que double o short no acepta para configurar un Pen, al código le agregué un mgsBox para que cada vez que resize veas los valores de cada color, cuando el valor de Rojo2 termina en 0 todo bien cuando no se nota una leve diferencia de tamaño (1 pirex) en él.
Private Sub Form1_ResizeEnd(sender As Object, e As EventArgs) Handles Me.ResizeEnd Dim graf As Graphics = Me.CreateGraphics() Medida.BorderStyle = BorderStyle.None Dim grosor As Integer = 10 Medida.Width = grosor 'Medida.Height = 300 Dim i As Integer = 20 Dim d As Integer = 10 Dim b As Double = 100 '1096 Dim j As Integer = 0 Dim lap As Pen = New Pen(Brushes.Red) Medida.BackColor = Color.Black '' ''Dim lap2 As Pen = New Pen(Brushes.Blue, 1) Dim Colorojo As Pen = New Pen(Brushes.Red, grosor) Dim Colorojo2 As Pen = New Pen(Brushes.Red, grosor) Dim ColoAmarillo As Pen = New Pen(Brushes.Yellow, grosor) Dim ColoAmarillo2 As Pen = New Pen(Brushes.Yellow, grosor) Dim Coloverde As Pen = New Pen(Brushes.Green, grosor) Dim ColoNegro As Pen = New Pen(Brushes.Black, grosor) Dim r1 As Integer = 10 'valores para cargar mediate variable si es necesario Dim a1 As Integer = 15 'valores para cargar mediate variable si es necesario Dim v1 As Integer = 50 'valores para cargar mediate variable si es necesario Dim a2 As Integer = 15 'valores para cargar mediate variable si es necesario Dim r2 As Integer = 10 'valores para cargar mediate variable si es necesario 'Falta condición para verificar que los porcentajes no superen los 100 Dim Rojo1 As Integer = Medida.Height - ((Medida.Height * r1) / 100) 'Para dibujar de abajo hacia arriba Dim Amarillo1 As Integer = (Rojo1) - ((Medida.Height * a1) / 100) Dim verde As Integer = (Amarillo1) - ((Medida.Height * v1) / 100) Dim Amarillo2 As Integer = (verde) - ((Medida.Height * a2) / 100) Dim Rojo2 As Integer = (Amarillo2) - (((Medida.Height * r2) / 100)) Dim HeigH As Integer = Medida.Height 'Los valores de la nueva línea se dibujan a partir de la última Medida.Refresh() Medida.CreateGraphics.DrawLine(Colorojo, 5, HeigH, 5, Rojo1) Medida.CreateGraphics.DrawLine(ColoAmarillo, 5, Rojo1, 5, Amarillo1) Medida.CreateGraphics.DrawLine(Coloverde, 5, Amarillo1, 5, verde) Medida.CreateGraphics.DrawLine(ColoAmarillo2, 5, verde, 5, Amarillo2) Medida.CreateGraphics.DrawLine(Colorojo, 5, Amarillo2, 5, 0) MsgBox("Rojo: " & Medida.Height - Rojo1 & " Am1: " & Rojo1 - Amarillo1 & " Verde: " & Amarillo1 - verde & " Am2: " & verde - Amarillo2 & " Rojo2 " & Amarillo2 - Rojo2 & vbNewLine &"Rojo: " & Rojo1 & " Am1: " & Amarillo1 & " Verde: " & verde & " Am2: " & Amarillo2 & " Rojo2 " & Rojo2) End Sub Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint Medida.BorderStyle = BorderStyle.None Dim grosor As Integer = 10 Medida.Width = grosor Dim i As Integer = 20 Dim d As Integer = 10 Dim b As Double = 100 '1096 Dim j As Integer = 0 Dim lap As Pen = New Pen(Brushes.Red) Medida.BackColor = Color.Black Dim Colorojo As Pen = New Pen(Brushes.Red, grosor) Dim Colorojo2 As Pen = New Pen(Brushes.Red, grosor) Dim ColoAmarillo As Pen = New Pen(Brushes.Yellow, grosor) Dim ColoAmarillo2 As Pen = New Pen(Brushes.Yellow, grosor) Dim Coloverde As Pen = New Pen(Brushes.Green, grosor) Dim ColoNegro As Pen = New Pen(Brushes.Black, grosor) Dim r1 As Integer = 10 'valores para cargar mediate variable si es necesario Dim a1 As Integer = 15 'valores para cargar mediate variable si es necesario Dim v1 As Integer = 50 'valores para cargar mediate variable si es necesario Dim a2 As Integer = 15 'valores para cargar mediate variable si es necesario Dim r2 As Integer = 10 'valores para cargar mediate variable si es necesario 'Falta condición para verificar que los porcentajes no superen los 100 Dim Rojo1 As Integer = Medida.Height - ((Medida.Height * r1) / 100) 'Para dibujar de abajo hacia arriba Dim Amarillo1 As Integer = (Rojo1) - ((Medida.Height * a1) / 100) Dim verde As Integer = (Amarillo1) - ((Medida.Height * v1) / 100) Dim Amarillo2 As Integer = (verde) - ((Medida.Height * a2) / 100) Dim Rojo2 As Integer = (Amarillo2) - ((Medida.Height * r2) / 100) Dim HeigH As Integer = Medida.Height 'Los valores de la nueva línea se dibujan a partir de la última Medida.Refresh() Medida.CreateGraphics.DrawLine(Colorojo, 5, HeigH, 5, Rojo1) Medida.CreateGraphics.DrawLine(ColoAmarillo, 5, Rojo1, 5, Amarillo1) Medida.CreateGraphics.DrawLine(Coloverde, 5, Amarillo1, 5, verde) Medida.CreateGraphics.DrawLine(ColoAmarillo2, 5, verde, 5, Amarillo2) Medida.CreateGraphics.DrawLine(Colorojo, 5, Amarillo2, 5, 0) 'Medida.CreateGraphics.DrawLine(ColoNegro, 0, 150, 0, 155) 'CreateGraphics.DrawLine(Colorojo, 0, 0, 0, 50) 'CreateGraphics.DrawLine(ColoAmarillo, 0, 50, 0, 75) 'CreateGraphics.DrawLine(Coloverde, 0, 75, 0, 225) 'CreateGraphics.DrawLine(ColoAmarillo2, 0, 250, 0, 225) 'CreateGraphics.DrawLine(Colorojo, 0, 300, 0, 250) 'CreateGraphics.DrawLine(ColoNegro, 0, 150, 0,) End Sub
Saludos
- Editado Marcelo PF sábado, 26 de agosto de 2017 5:22
-
-
-
yo lo hice en C# pero no es un codigo complejo como para no poder pasar a VB.NET
public class Graficardor : Control { protected override void OnPaint(PaintEventArgs e) { e.Graphics.FillRectangle(SystemBrushes.Control, new Rectangle(0, 0, this.Width, this.Height)); int pointA = (int)Math.Ceiling((this.Height * 10F) / 100F), pointB = (int)Math.Ceiling((this.Height * 15F) / 100F), pointC = (int)Math.Ceiling((this.Height * 50F) / 100F), pointD = (int)Math.Ceiling((this.Height * 15F) / 100F), pointE = (int)Math.Ceiling((this.Height * 10F) / 100F); e.Graphics.FillRectangle(Brushes.Red, new Rectangle((this.Width / 2) - 5, 0, 10, pointA)); e.Graphics.FillRectangle(Brushes.Yellow, new Rectangle((this.Width / 2) - 5, pointA - 1, 10, pointB)); e.Graphics.FillRectangle(Brushes.Green, new Rectangle((this.Width / 2) - 5, (pointA + pointB) - 1, 10, pointC)); e.Graphics.FillRectangle(Brushes.Yellow, new Rectangle((this.Width / 2) - 5, (pointA + pointB + pointC) - 1, 10, pointD)); e.Graphics.FillRectangle(Brushes.Red, new Rectangle((this.Width / 2) - 5, (pointA + pointB + pointC + pointD) - 1, 10, pointE)); } }
Marvin E. Pineda
ComboBoxMultiColumns
-
Base cero, es todo el problema de la diferencia de 1
Marvin E. Pineda
ComboBoxMultiColumns
si no captan la idea de base cero me avisan para explicarles.
Salu2,
Marvin E. Pineda
ComboBoxMultiColumns
-
Buenos días, Marvin saludos, consulta donde colocas para que aplique, no logro hacerlo. Coloque las instrucciones en el Paint del Form1 y no es el resultado buscado, gracias por la ayuda.
JET, saludos, no puede encontrar un metodo ResizeEnd en un class como lo tienes tú pero lo volví a colocar en el evento Resize y funciona igual
Atentos a la colaboración de Marvin, me parece buen camino
Saludos
En el evento Resize
- Propuesto como respuesta Jorge TurradoMVP lunes, 28 de agosto de 2017 8:50
- Votado como útil Jorge TurradoMVP lunes, 28 de agosto de 2017 8:50
-
Este seria el control en VB.NET aunque le hice algunos cambios para obtener siempre el mismo alto con el mismo % en varios casos ya que por efecto de pixeles no se puede pintar 0.6 de pixel que seria lo ideal para estos casos.
Ejemplo:
si el control tiene un alto de 44
para la siguiente table se obtiene
(44 * 10) / 100 = 4.4
(44 * 15) / 100 = 6.6
(44 * 50) / 100 = 22
(44 * 15) / 100 = 6.6
(44 * 10) / 100 = 4.4
si sumas los resultados te darán 44, pero!!!.. como lo estamos pasando a enteros, el resultado podría ser diferente (4,7,22,7,4 = 44), para este número todo bien, el problema viene con los impares
ejemplo con 47, el resultado sera (5,7,24,7,5 = 48).. aquí el alto a pintar es mayor al alto del control, por ende tenemos que validar el resultado y volver a re-calcular para obtener un resultado igual o menor en todo caso para que siempre se pinten los mismos tamaños para los mismo porcentajes.
así que este seria el código en VB.NET
Option Strict On Public Class Graficador Inherits Control Private Function CalcularPuntos(height As Integer) As Integer() Dim puntos(5) As Integer puntos(0) = CInt((height * 10.0F) / 100.0F) puntos(1) = CInt((height * 15.0F) / 100.0F) puntos(2) = CInt((height * 50.0F) / 100.0F) puntos(3) = CInt((height * 15.0F) / 100.0F) puntos(4) = CInt((height * 10.0F) / 100.0F) Console.WriteLine("") Console.WriteLine(height) Dim checkHeight As Integer For Each punto As Integer In puntos Console.WriteLine(punto) checkHeight += punto Next Console.WriteLine(checkHeight) If checkHeight > Me.Height Then puntos = CalcularPuntos(height - 1) End If Return puntos End Function Protected Overrides Sub OnPaint(e As System.Windows.Forms.PaintEventArgs) Using brush As SolidBrush = New SolidBrush(Me.BackColor) e.Graphics.FillRectangle(brush, New Rectangle(0, 0, Me.Width, Me.Height)) End Using Dim y As Integer = 0 Dim puntos() As Integer = CalcularPuntos(Me.Height) Dim colores(5) As Brush colores(0) = Brushes.Red colores(1) = Brushes.Yellow colores(2) = Brushes.Green colores(3) = Brushes.Yellow colores(4) = Brushes.Red For punto As Integer = 0 To 4 e.Graphics.FillRectangle(colores(punto), New Rectangle(CInt((Me.Width / 2)) - 5, y, 10, puntos(punto))) y += puntos(punto) Next End Sub End Class
Salu2,
Marvin E. Pineda
ComboBoxMultiColumns
- Editado Marvin E. Pineda domingo, 27 de agosto de 2017 16:43
- Propuesto como respuesta Jorge TurradoMVP lunes, 28 de agosto de 2017 8:50