954,510 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Writing to text property of a label

Hey folks.

I'm tying to carry out a simply task of writing a variable double value to a label on my form. The label is called 'lblTotalSeats'. Here's my code below:

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 ABCDEFG
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
        }

        private void TotalSeats()
        {
            double totalSeats = 240;
            string numberOfSeats = totalSeats.ToString();
            lblTotalSeats.Text = numberOfSeats;
        }
    }
}


My code doesn't throw up any errors when I run it but the value of 240 doesn't display on my label 'lblTotalSeats'.

Any suggestions what I'm doing wrong? I've tried varying it so the method is called "private string TotalSeats(out numberOfSeats) but to no avail too.

I know it's quite simple but as a beginner and a new student to GUI programming, I'm struggling.

Thanks

scrivomcdivo
Newbie Poster
13 posts since Jan 2011
Reputation Points: 11
Solved Threads: 0
 

You have to call that function somewhere in the program. I'll leave it up to you to figure that one out.

pseudorandom21
Practically a Posting Shark
890 posts since Jan 2011
Reputation Points: 216
Solved Threads: 111
 

Thanks PseudoRandom. I knew it was something obvious. I'd moved the code for the TotalSeats method to the MainForm_Load method but knew that that was wrong. Your pointer has sorted out a problem I've been trying to tackle for over an hour!

Thank you

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 Assignment_3
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            TotalSeats();
        }

        private void TotalSeats()
        {
            double totalSeats = 240;
            string numberOfSeats = totalSeats.ToString();
            lblTotalSeats.Text = numberOfSeats;
        }
    }
}
scrivomcdivo
Newbie Poster
13 posts since Jan 2011
Reputation Points: 11
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: