Thread: how to

Results 1 to 6 of 6
  1. #1
    Keroka0's Avatar
    Join Date
    Jun 2012
    Gender
    male
    Posts
    22
    Reputation
    10
    Thanks
    1

    how to

    iam looking to make 2 buttons one connect and one disconnect and i need to show status in label

    everything is okay but how can i change label text with buttons


    i mean need it green when connected and red when disconnected



    and this is the code is there any thing wrong ?


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

    private void button1_Click(object sender, EventArgs e)
    {
    label1.Text = "Connected";
    label1.Visible = true;
    }

    private void button2_Click(object sender, EventArgs e)
    {
    label1.Text = "Disconnected";
    label1.Visible = true;
    }
    }
    }

  2. #2
    'Bruno's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Portugal
    Posts
    2,883
    Reputation
    290
    Thanks
    1,036
    My Mood
    Busy
    First of all, Use CODE tags.
    Second, why the "label1.Visible = true;"? It should be always visible.
    Third, that code should be working, whats wrong with it?

    By the way, learn to rename your controls, it makes everything easier:
    Instead of button1 and button2 you could have, btnCon, btnDisc. (btn for button)
    Or instead of label1 and label2 you could ahve, lblCon, lblDisc. (lbl for label)
    Etc...

    For the color, change the foreground color propriety (I think thats it).
    Light travels faster than sound. That's why most people seem bright until you hear them speak.

  3. #3
    Keroka0's Avatar
    Join Date
    Jun 2012
    Gender
    male
    Posts
    22
    Reputation
    10
    Thanks
    1
    Quote Originally Posted by Brinuz View Post
    First of all, Use CODE tags.
    Second, why the "label1.Visible = true;"? It should be always visible.
    Third, that code should be working, whats wrong with it?

    By the way, learn to rename your controls, it makes everything easier:
    Instead of button1 and button2 you could have, btnCon, btnDisc. (btn for button)
    Or instead of label1 and label2 you could ahve, lblCon, lblDisc. (lbl for label)
    Etc...

    For the color, change the foreground color propriety (I think thats it).

    iam just new here and i was trying so wasn't care about renaming buttons and iam looking to make one label with 2 colors or do you got any idea wanna make 2 buttons 1disconnect and 1 connect when connect active it show status connected << Green and if dis show it in red

  4. #4
    'Bruno's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Portugal
    Posts
    2,883
    Reputation
    290
    Thanks
    1,036
    My Mood
    Busy
    Quote Originally Posted by Keroka0 View Post
    iam just new here and i was trying so wasn't care about renaming buttons and iam looking to make one label with 2 colors or do you got any idea wanna make 2 buttons 1disconnect and 1 connect when connect active it show status connected << Green and if dis show it in red
    My previous post said everything you need to know. Im not spoonfeeding you with code when you just started.
    Light travels faster than sound. That's why most people seem bright until you hear them speak.

  5. #5
    Pingo's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Posts
    687
    Reputation
    24
    Thanks
    865
    My Mood
    Blah
    Last edited by 'Bruno; 08-22-2012 at 06:31 PM. Reason: If you want to help him, this will do.

  6. #6
    joe_dm's Avatar
    Join Date
    Oct 2012
    Gender
    male
    Posts
    26
    Reputation
    10
    Thanks
    138
    My Mood
    Relaxed
    If I understand right you need one button that toggles between connect and disconnect. Your solution to this is to only have one visible at a time.
    If this is the case I would advise against it. I am new to C# myself but creativity in coding goes a long way.
    Personally I would use the text to trigger and if..
    e.g.
    if (btnConnection.text = "Connect")
    {
    btnConnection.text = "Disconnect";
    }
    else
    {
    btnConnection.text = "Connect";
    }


    theres going to be better ways to do it. Like I said I'm new myself... Changing the colour should be easy enough for you to work out.
    Last edited by joe_dm; 10-12-2012 at 06:33 AM. Reason: add ;

Similar Threads

  1. how about Tantra Online Game
    By scoutranger in forum General Gaming
    Replies: 2
    Last Post: 09-25-2018, 06:57 AM
  2. How many people on this forum Play WoW?
    By RebornAce in forum General
    Replies: 27
    Last Post: 12-31-2009, 05:27 PM
  3. How to Use Tsearch
    By wardo1926 in forum Hack Requests
    Replies: 5
    Last Post: 12-18-2007, 09:24 PM
  4. How to get Perl
    By shercipher in forum Programming
    Replies: 2
    Last Post: 01-02-2006, 11:28 PM
  5. How To Brute Force
    By Flawless in forum Game Hacking Tutorials
    Replies: 0
    Last Post: 01-01-2006, 05:01 PM