Problems with C# [Help Please]

Discussion in 'Programming General' started by htaed, Sep 23, 2008.

Problems with C# [Help Please]
  1. Unread #1 - Sep 23, 2008 at 2:43 PM
  2. htaed
    Joined:
    Dec 19, 2005
    Posts:
    336
    Referrals:
    0
    Sythe Gold:
    0

    htaed Forum Addict
    Banned

    Problems with C# [Help Please]

    Well, i've just started to try and upgrade to C# from VB6, and i have had some problems,

    1. Public Variables

    In vb6, it would be as simple as

    Code:
    Public var_Number as Integer
    
    in the decelerations section, i've tried a few things but with no success.

    2. BorderStyle

    Well, this i think is a weird one, i select the form, and in the properties box i set the FormBorderStyle to FixedSingle, and it remains as if it was fully sizable, but gets slightly smaller.
    :eek:
     
  3. Unread #2 - Sep 23, 2008 at 5:58 PM
  4. BigBwoi2001
    Joined:
    Jul 4, 2008
    Posts:
    54
    Referrals:
    0
    Sythe Gold:
    0

    BigBwoi2001 Member

    Problems with C# [Help Please]

    Place right below the namespace place.
    Public static String

    See where I declared "static public string EncodePassword" thats where things are global.
    http://paste-it.net/public/m7a0f63/


    Sizeable problem.
    [​IMG]
     
  5. Unread #3 - Sep 23, 2008 at 6:00 PM
  6. htaed
    Joined:
    Dec 19, 2005
    Posts:
    336
    Referrals:
    0
    Sythe Gold:
    0

    htaed Forum Addict
    Banned

    Problems with C# [Help Please]

    Anywhere in the code this is placed? or in a class or some special area?
     
  7. Unread #4 - Sep 23, 2008 at 6:30 PM
  8. hampe-92
    Joined:
    Jul 10, 2008
    Posts:
    328
    Referrals:
    0
    Sythe Gold:
    0

    hampe-92 Forum Addict

    Problems with C# [Help Please]

    and string is most used to hold text, while int numbers...
     
  9. Unread #5 - Sep 23, 2008 at 7:18 PM
  10. tomanderson12
    Joined:
    Jan 21, 2008
    Posts:
    53
    Referrals:
    0
    Sythe Gold:
    0

    tomanderson12 Member

    Problems with C# [Help Please]

    I think we understand that
     
  11. Unread #6 - Sep 23, 2008 at 11:39 PM
  12. BigBwoi2001
    Joined:
    Jul 4, 2008
    Posts:
    54
    Referrals:
    0
    Sythe Gold:
    0

    BigBwoi2001 Member

    Problems with C# [Help Please]

    lol just let him think he helped.

    Thanks for the new info I didn't know that.
     
  13. Unread #7 - Sep 23, 2008 at 11:48 PM
  14. Swan
    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner

    Swan When They Cry...
    Retired Global Moderator

    Problems with C# [Help Please]

    Depends what type of public variable you want. You can use static variables if you want to access variables outside of the scope of the class you are in (which in your case would be Form1, correct?).

    Here is an example:
    Code:
        public partial class Form1 : Form
        {
            // Public variable declarations (within the scope of Form1)
            public int x;
            public string s;
    
            // Public static variable declarations
            public static int x2;
            public static string s2;
    
            public Form1()
            {
                // Generate random number and assign to 'x'
                x = new Random(DateTime.Now.Millisecond).Next();
                s = "public string";
    
                x2 = new Random(DateTime.Now.Millisecond).Next();
                s2 = "public static string";
    
                InitializeComponent();
    
                publicVarDemo pVD = new publicVarDemo();
            }
        }
    
        public class publicVarDemo
        {
            public publicVarDemo()
            {
                // The following will result in an error.
                // Uncommmend it and see.
                //MessageBox.Show(Form1.x.ToString() + " - " + Form1.s);
    
                // The following is correct, because the variables
                // Being accessed are static.
                MessageBox.Show(Form1.x2.ToString() + " - " + Form1.s2);
            }
        }
    You are just too used to Visual Basic's modifiers, which give you terrible habits if you want to learn languages like C, C++, C# or Java. It took me a while to get over the habits I'd learned from VB.

    You can find a tutorial for C# and its keywords (including modifiers like public, private, protected and so on) HERE

    A fixed border simply means you can't resize it by clicking and dragging the sides of the forms. If memory serves, there will still be things like a maximize / restore button. To get rid of these, either in your form's initialization or in the forms properties window (more common) change the "MaximizeBox" property to False.
     
  15. Unread #8 - Sep 24, 2008 at 11:10 AM
  16. htaed
    Joined:
    Dec 19, 2005
    Posts:
    336
    Referrals:
    0
    Sythe Gold:
    0

    htaed Forum Addict
    Banned

    Problems with C# [Help Please]

    Thanks very much everyone, this has helped ;)
     
< [Help] Creating an IRC Client | SaveIndexed Pictures? >

Users viewing this thread
1 guest


 
 
Adblock breaks this site