Need help with C# UI in Visual Studio 2012

  • (2 Pages)
  • +
  • 1
  • 2

22 Replies - 872 Views - Last Post: 02 October 2013 - 06:43 PM Rate Topic: -----

#1 Eruthien  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 01-October 13

Need help with C# UI in Visual Studio 2012

Posted 01 October 2013 - 12:39 PM

I'm beginning to learn C# and I want to make a simple program with UI. The program is going to ask you for your name and then when you press a button a text box will pop up and say Hello 'your name' however I don't know how to use the string the user entered into the text box in the code that make the text box pop. Where do I set up the variable and

Here's the code so far


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

// when button is clicked a box will pop and say hello

        private void button1_Click(object sender, EventArgs e)
        {
           
            MessageBox.Show("Hello ");            // Is supposed to say hello
            
        }
// User enters their name here
        private void textBox1_TextChanged(object sender, EventArgs e)  // I need the string that goes in there to be put inside a variable
        {
           
        }
    }
}




What should I do? Thanks in advance

Is This A Good Question/Topic? 0
  • +

Replies To: Need help with C# UI in Visual Studio 2012

#2 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1010
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: Need help with C# UI in Visual Studio 2012

Posted 01 October 2013 - 12:53 PM

You should check out TextBox.Text
Was This Post Helpful? 1
  • +
  • -

#3 Technosis  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 15
  • Joined: 18-September 13

Re: Need help with C# UI in Visual Studio 2012

Posted 01 October 2013 - 01:13 PM

hint:
 
private void button1_Click(object sender, EventArgs e)
{
   if (textBox1.Text != "")
    MessageBox.Show("hello");
            
}

Was This Post Helpful? 1
  • +
  • -

#4 Eruthien  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 01-October 13

Re: Need help with C# UI in Visual Studio 2012

Posted 01 October 2013 - 01:13 PM

I don't understand, how do I use
 public override string Name
        {
            get;


            set;
        }


in my code?
Was This Post Helpful? 0
  • +
  • -

#5 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1010
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: Need help with C# UI in Visual Studio 2012

Posted 01 October 2013 - 01:15 PM

Totally unrelated to your first question, but you'd use it like a variable
Name = "fred";
Console.WriteLine("{0} <- your name", Name);

Was This Post Helpful? 0
  • +
  • -

#6 Eruthien  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 01-October 13

Re: Need help with C# UI in Visual Studio 2012

Posted 01 October 2013 - 01:17 PM

I understand now,thank you people.
Was This Post Helpful? 0
  • +
  • -

#7 Eruthien  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 01-October 13

Re: Need help with C# UI in Visual Studio 2012

Posted 01 October 2013 - 01:24 PM

Also, in he Message.Box(), how do I make it say "hello," and the variable? how do I connect them so its one phrase? sorry for the silly questions but I just switched from c++ to c# hoping it'll be similar but its not.
Was This Post Helpful? 0
  • +
  • -

#8 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1010
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: Need help with C# UI in Visual Studio 2012

Posted 01 October 2013 - 01:27 PM

Two ways:
String concatination MessageBox.Show("hello " + Name);
String formating MessageBox.Show(String.Format("hello {0}", Name));
Was This Post Helpful? 2
  • +
  • -

#9 Eruthien  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 01-October 13

Re: Need help with C# UI in Visual Studio 2012

Posted 01 October 2013 - 02:23 PM

Another question, if I press a button I want it to load up a picture in a picture box, how do I make the image invisible until I hit the button?

I tried

private void button3_Click_1(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
    {
              
        pictureBox1.Load(openFileDialog1.FileName);  
    }



but it just loads up my documents.
Was This Post Helpful? 0
  • +
  • -

#10 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4484
  • View blog
  • Posts: 7,811
  • Joined: 08-June 10

Re: Need help with C# UI in Visual Studio 2012

Posted 01 October 2013 - 02:27 PM

I'm confused at your goal. Do you want the user to choose an image to load, or do you already have a particular image selected and you want it to be shown/hidden with a button?

Because what you're doing is prompting the user to select a file. If you already know the file path to your image, use that as a string.
Was This Post Helpful? 0
  • +
  • -

#11 Eruthien  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 01-October 13

Re: Need help with C# UI in Visual Studio 2012

Posted 01 October 2013 - 02:31 PM

I already have a particular image I want to show. My goal is when the user presses a butto the image will show up.
Was This Post Helpful? 0
  • +
  • -

#12 Eruthien  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 01-October 13

Re: Need help with C# UI in Visual Studio 2012

Posted 01 October 2013 - 02:46 PM

I finally found a way to do it but it doesn't work correctly, it shows a red cross, what's wrong?

This is my code

private void button3_Click_1(object sender, EventArgs e)
        {

            pictureBox1.ImageLocation = "C:.Users.Natha_000.Pictures.imageforapp.jpeg";
    }



what's wrong with it? The size of the image is 402x402. Is there a limit to how big the image can be?
Was This Post Helpful? 0
  • +
  • -

#13 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4484
  • View blog
  • Posts: 7,811
  • Joined: 08-June 10

Re: Need help with C# UI in Visual Studio 2012

Posted 01 October 2013 - 03:00 PM

Because file path separators are not periods, they're backslashes. Except in C# a backslash is also an escape character, so you have two options:

"C:\\Users\\Natha_000\\Pictures\\imageforapp.jpeg is a normal string. Each double-backslash is rendered as a single one, because backslashes are an escape character.

But since this is a pain for things like file paths, C# gives you the option of a verbatim string, which ignores escape sequences. That would look like this:

@"C:\Users\Natha_000\Pictures\imageforapp.jpeg"
Was This Post Helpful? 1
  • +
  • -

#14 jimzcoder  Icon User is offline

  • D.I.C Regular

Reputation: 54
  • View blog
  • Posts: 331
  • Joined: 14-November 12

Re: Need help with C# UI in Visual Studio 2012

Posted 01 October 2013 - 05:34 PM

you can make 3 options. because forward slashes can also do it.
"C:/User/Natha_000/Pictures/imageforapp.jpeg"
Was This Post Helpful? 0
  • +
  • -

#15 Eruthien  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 01-October 13

Re: Need help with C# UI in Visual Studio 2012

Posted 01 October 2013 - 11:06 PM

The image is still a red cross. I don't know what's wrong.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2