+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Falcom is better than SE. Change my mind.
    Join Date
    Jun 2006
    Posts
    17,291
    BG Level
    9

    Working with multiple forms in C#

    I'm trying to work on a multiform project where in my starter form (MainForm) I enter data, the data is processed by a class, and then that data is displayed on the second form (DisplayForm). I got everything but the display form to work so far. I can have it pop up, but when it does it doesn't display any information. It seems to be missing the DisplayForm_Load event.

    Here's what the code looks like for the DisplayForm if anyone wants to take a look and see what's wrong with it:
    Spoiler: show
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;

    namespace OOP
    {
    public partial class DisplayForm : Form
    {
    public string _displayStr;

    public string Display
    {
    set
    {
    _displayStr = value;
    }

    get
    {
    return _displayStr;
    }
    }

    public DisplayForm()
    {
    InitializeComponent();
    }

    private void DisplayForm_Load(object sender, EventArgs e)
    {
    displayLabel.Text = _displayStr;
    }
    }
    }

    I know I could probably fine tune it a bit, but right now I'm more concerned about getting the actual data to display on the form before I work with anything else code wise.

  2. #2
    Relic Weapons
    Join Date
    Oct 2006
    Posts
    335
    BG Level
    4

    Presuming you have a Label component called displayLabel placed on the DisplayForm Form, then the way this is written, the window would pop up with nothing in the label's text attribute, as you are setting displayLabel.Text to a blank string (the uninitialized _displayStr value) in DisplayForm_Load.

    Give _displayStr a default value and you should see it when DisplayForm appears (demonstrating that DisplayForm_Load is actually called).

    Edit: You'll need to include more information about how you're using DisplayForm from MainForm if you're setting DisplayForm.Display before calling DisplayForm.Show (and expecting a value set through DisplayForm.Display that's not appearing), but just this snippet alone looks like it's working properly on its own.

  3. #3
    Falcom is better than SE. Change my mind.
    Join Date
    Jun 2006
    Posts
    17,291
    BG Level
    9

    Found the problem, didn't have the load property set for DisplayForm.

Similar Threads

  1. Question with multiple file game ROMs
    By Taera in forum Tech
    Replies: 4
    Last Post: 2007-07-26, 01:19
  2. Replies: 10
    Last Post: 2007-07-03, 17:24
  3. Replies: 15
    Last Post: 2007-04-25, 18:53