?
Solved

C# Simple GUI FORM question - having things appear on button clicks in the same window

Posted on 2007-08-01
9
Medium Priority
?
245 Views
Last Modified: 2012-05-05
C# Simple GUI FORM question - having things appear on button clicks.

I can create a simple GUI app by selecting winodws application in C# 2005 express - what I want to do is click a "start" button - when I click the button a text field appears along with an "ok" button but still in the same window as the start button was - then someone types their name into the text field clicks ok AND then still in the same field and appearing for the first time is a message "Hi there <name>". I am new to C# and can't believe it is that hard but this would enlighten me - does anyone have this (or could whip up) very app?

Thanks! Karl66
0
Comment
Question by:Karl66
  • 5
  • 3
9 Comments
 
LVL 1

Accepted Solution

by:
itsbth earned 750 total points
ID: 19613422
First, create:
The start button, and set the name to startbtn.
A textbox, set the name to txtbox, and visible to false.
The ok button, set the name to okbtn and visible to false.
A label, set the name to greeting and visible to false.

Doubleclick on the start button.

You should now be in code view.

Write:
txtbox.Visible = true; // Show the text box...
okbtn.Visible = true; // And the OK button.

Go back to designer view and double-click the OK button.

Write:
greeting.Text = "Hi there " + txtbox.Text; // Set the label to Hi there + the name from the text box.
greeting.Visible = true; // Show the message.

I hope this helps.
0
 

Author Comment

by:Karl66
ID: 19614101
Thanks it is a start I will do it tomorrow and get back - I do not need the code as if it were to fulfill something as I am not having luck getting things to "appear" in the same window - so the above described request was to avoid having to message box things - i thouht if someone could show me tha I would get it - but in fact my original problem is really what I want to see OOP or just one long file - no worries.

Thanks
0
 
LVL 15

Expert Comment

by:angus_young_acdc
ID: 19615449
Hi Karl66

Do you mean you want details on object orientated programming?  If so here are a few starter links:
http://www.brpreiss.com/books/opus6/html/page588.html
http://www.developerfusion.co.uk/show/3821/
http://www.samspublishing.com/articles/article.asp?p=101373&rl=1 - possibly the best site.

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:Karl66
ID: 19619524
itsbth -

It doesnt seem to much care for that code.. is it supposed to be a "kind of like this" example?

I tried things like:

Form1.button1.Visible = true; // And the OK button.
but it keeps telling me an objext reference is required?
0
 
LVL 1

Expert Comment

by:itsbth
ID: 19619695
Try this.<name of button>.Visible
0
 

Author Comment

by:Karl66
ID: 19619766
Here is what I have - it doesn't seem to care for Form1 or greeting.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace GUIs_and_Buttons_example
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form1.Visible = true; // Show the text box...
            button1.Visible = true; // And the OK button.

        }

        private void button2_Click(object sender, EventArgs e)
        {
            greeting.Text = "Hi there " + Form1.Text; // Set the label to Hi there + the name from the text box.
            greeting.Visible = true; // Show the message.

        }
    }
}
0
 

Author Comment

by:Karl66
ID: 19619786
OK DUH! but it still doesn't like greeting
0
 
LVL 1

Expert Comment

by:itsbth
ID: 19619823
Doen't use Form1. Use the name you gave the them. Eventually this.<the-name-you-gave-them>.
0
 

Author Comment

by:Karl66
ID: 19619848
OK thanks - got it! Here come the points - here is what I did:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace GUIs_and_Buttons_example
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            textBox1.Visible = false;
            button2.Visible = false;
            label1.Visible = false;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Visible = true; // Show the text box...
            button2.Visible = true; // And the OK button.

        }

        private void button2_Click(object sender, EventArgs e)
        {
            label1.Text = "Hi there " + textBox1.Text; // Set the label to Hi there + the name from the text box.
            label1.Visible = true; // Show the message.

        }
    }
}
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses
Course of the Month16 days, 5 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question