Principales respuestas
Llamar a otro formulario

Pregunta
-
Buenas tardes
tengo el siguiente erro
Tengo un formulario normal que llama a otro formulario y ese le devuelve una fecha en el PROgram configuro para que solo se ejecute ese formulario y perfecto funciona la fecha lo devuelve; pero al agregar al formulario principal es decir si ejecuto toda la aplicación y a no obtengo resultado
Esta es la pantalla sola
Este es el codigo desde el PROGRAM
static class Program { /// <summary> /// Punto de entrada principal para la aplicación. /// </summary> /// public static String usuario = ""; // es la que nos lleva el nombre del usuario registrado public static String nivel = ""; public static DateTime fecha; [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("es-ES"); //Añadido por Ruben Cultura Español Application.Run(new frm_acceso());
Asi lo tengo en el Formulario que llama al otro
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using MySql.Data; using MySql.Data.MySqlClient; using System.Data.Sql; using System.Data.SqlClient; using System.IO; namespace APLICACIONMPNAV.formularios { public partial class frm_contenedores : Form, IForm // Se agrega Iform que e sun formulario para rellenar datos de otro formulario { #region IForm Members public void ChangeTextBoxText(string text) { if (variable == 1) { txtfechareserva.Text = text; } if (variable == 2) { txtconf_fechareserva.Text = text; } if (variable == 3) { txtconf_fechaentrega.Text = text; } if (variable == 4) { txtconf_fechaembarque.Text = text; } if (variable == 5) { txtconf_fechaenviadoc.Text = text; } if (variable == 6) { txtconf_fechaprevistallega.Text = text; } if (variable == 7) { txtconf_fechallegaespana.Text = text; } if (variable == 8) { txtconf_fechaentregamp.Text = text; } } #endregion private void pictureBox1_Click(object sender, EventArgs e) { variable = 1; calendario c = new calendario(); c.Show(this); }
Esta es mi clase
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace APLICACIONMPNAV { public interface IForm { void ChangeTextBoxText(string text); } }
Y este es el formulario hijo
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace APLICACIONMPNAV.formularios { public partial class calendario : Form // public partial class calendario : Form { public calendario() { InitializeComponent(); } DateTime fecha; private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e) { } private void button1_Click(object sender, EventArgs e) { fecha = monthCalendar1.SelectionStart; IForm formInterface = this.Owner as IForm; if (formInterface != null) formInterface.ChangeTextBoxText(Convert.ToString(fecha)); this.Close(); } } }
Pero asi me devuelve con null en el owner
por que puede ser
saludos
ruben
Respuestas
-
En teoría debería funcionar. Haz una prueba, en lugar de abrirlo así:
calendario c = new calendario();
c.Show(this);
ábrelo así:
calendario c = new calendario();
c.Owner = this;
c.Show();Se supone que debería dar lo mismo, pero pruébalo a ver si se nota alguna diferencia en el comportamiento.
- Propuesto como respuesta Jorge TurradoMVP lunes, 5 de noviembre de 2018 19:51
- Marcado como respuesta Ruben Lezcano martes, 6 de noviembre de 2018 8:37
Todas las respuestas
-
En teoría debería funcionar. Haz una prueba, en lugar de abrirlo así:
calendario c = new calendario();
c.Show(this);
ábrelo así:
calendario c = new calendario();
c.Owner = this;
c.Show();Se supone que debería dar lo mismo, pero pruébalo a ver si se nota alguna diferencia en el comportamiento.
- Propuesto como respuesta Jorge TurradoMVP lunes, 5 de noviembre de 2018 19:51
- Marcado como respuesta Ruben Lezcano martes, 6 de noviembre de 2018 8:37
-