• Log in or sign up for an account here: https://www.sythe.org/login

Problems with C# [Help Please]

htaed

Forum Addict
Banned
Joined
Dec 19, 2005
Sythe Gold
0
Messages
336
Age
38
Location
Anchorage, Alaska
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.
:o
 
Problems with C# [Help Please]
Anywhere in the code this is placed? or in a class or some special area?
 
Problems with C# [Help Please]
and string is most used to hold text, while int numbers...
 
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.

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

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.
:o

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.
 
Runescape Gamblingrunescape gambling
Back
Top