Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: Help With C#  (Read 1530 times)

0 Members and 1 Guest are viewing this topic.
Help With C#
« on: July 16, 2006, 09:21:28 am »
  • Flash Software Studios
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 71
Im currently learning c# and i am making a font chooser. Its pretty straight forward but for some reason i keep getting build errors that say  "Error   1   The name 'fontName' does not exist in the current context". This happens with afew of my variables but im sure they ahve been declared. Does anyone think they can help?? thanks.
Logged
 
  • http://www.myspace.com/kristruman
Re: Help With C#
« Reply #1 on: July 16, 2006, 09:35:36 am »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6629
That error means the varaibles either don't exist or are out of scope, can you post some code?
Logged
Re: Help With C#
« Reply #2 on: July 16, 2006, 10:20:12 am »
  • Flash Software Studios
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 71
Code: [Select]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Font_Chooser
{
    public partial class myForm : Form
    {
        public myForm()
        {
            InitializeComponent();
        }

        public class Form : System.Windows.Forms.Form
        {
            //My own variables
            private System.Drawing.Font myFont;
            private string fontName = "Arial";
            private int fontSize = 20;
            private FontStyle myStyle = FontStyle.Regular;
        }
            private void AssignFont(){
            //uses the variables to assign a font

            //check the listbox for a font name
            fontName = lstFontName.Text;

            //look at check boxes for styles
            myStyle = FontStyle.Regular;
            if (chkBold.Checked){
                myStyle = myStyle | FontStyle.Bold;
            } //End If
            if (chkItalic.Checked){
                myStyle = mySytle | FontStyle.Italic;
            } //End If

            //Create the new font and attach to the label
            myFont = new Font(fontName, fontSize, myStyle);
            lblSample.Font = myFont;
        }//End Assignment

   
        private void lstFontName_SelectedIndexChanged(object sender, System.EventArgs e){
            AssignFont();
        }

        private void chkBold_CheckedChanged(object sender, System.EventArgs e){
            AssignFont();
        }

   
        private void chkItalic_CheckedChanged(object sender, System.EventArgs e){
            AssignFont();
        }

   
        private void rad1_CheckedChanged(object sender, System.EventArgs e){
            fontSize = 10;
            AssignFont();
        }

   
        private void rad2_CheckedChanged(object sender, System.EventArgs e){
            fontSize = 20;
            AssignFont();
        }//End AssignFont

    }
}

thats all that there is code-wise here is my design view:
http://img.photobucket.com/albums/v472/flashGX/designview.gif
Logged
 
  • http://www.myspace.com/kristruman
Re: Help With C#
« Reply #3 on: July 16, 2006, 10:51:07 am »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6629
1) You really don't need to nest the class Form into the myForm class.
2) Form is the name of a class in System.Windows.Forms, so for good practice, its best to come up with a different name.
3) The reason you are getting the errors is because the variables are defined in the class Form and your trying to use them in the class myForm. (They are out of scope.)

Also its probably a good idea to use VS2005 (or one of the express versions) as its uses .NET 2.0 which is significantly faster than .NET 1.0 (which VS2003 uses, which I think is the IDE your using).
« Last Edit: July 16, 2006, 10:55:08 am by Helios »
Logged
Re: Help With C#
« Reply #4 on: July 16, 2006, 11:46:08 am »
  • Flash Software Studios
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 71
I have Visual Studios 2005 Pro Corp so i have the .NET 2.0 frameworks already but the book im learning from is obviously old and uses the 1.1 frameworks or something. Can you sugest a better source to learn from? Also should i do all the console programming before i move on to windows programming? its just i find console really annoying i dunno if thats a bad thing but yea what would you sugest?
Logged
 
  • http://www.myspace.com/kristruman
Re: Help With C#
« Reply #5 on: July 16, 2006, 03:46:48 pm »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6629
I have Visual Studios 2005 Pro Corp so i have the .NET 2.0 frameworks already but the book im learning from is obviously old and uses the 1.1 frameworks or something. Can you sugest a better source to learn from? Also should i do all the console programming before i move on to windows programming? its just i find console really annoying i dunno if thats a bad thing but yea what would you sugest?
I dought its your book, C# 2.0 is more or less the same as the first, just with generics and a few other things.
I think you probably just wrote something wrong, try compiling this it should work (not going to test it though as I don't have time)

Code: [Select]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Font_Chooser
{
    public partial class myForm : Form
    {
        //My own variables
        private System.Drawing.Font myFont;
        private string fontName = "Arial";
        private int fontSize = 20;
        private FontStyle myStyle = FontStyle.Regular;

        public myForm()
        {
            InitializeComponent();
        }

        private void AssignFont(){
            //uses the variables to assign a font

            //check the listbox for a font name
            fontName = lstFontName.Text;

            //look at check boxes for styles
            myStyle = FontStyle.Regular;
            if (chkBold.Checked){
                myStyle = myStyle | FontStyle.Bold;
            } //End If
            if (chkItalic.Checked){
                myStyle = mySytle | FontStyle.Italic;
            } //End If

            //Create the new font and attach to the label
            myFont = new Font(fontName, fontSize, myStyle);
            lblSample.Font = myFont;
        }
   
        private void lstFontName_SelectedIndexChanged(object sender, System.EventArgs e){
            AssignFont();
        }

        private void chkBold_CheckedChanged(object sender, System.EventArgs e){
            AssignFont();
        }

   
        private void chkItalic_CheckedChanged(object sender, System.EventArgs e){
            AssignFont();
        }

   
        private void rad1_CheckedChanged(object sender, System.EventArgs e){
            fontSize = 10;
            AssignFont();
        }

   
        private void rad2_CheckedChanged(object sender, System.EventArgs e){
            fontSize = 20;
            AssignFont();
        }

    }
}
Logged
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.037 seconds with 50 queries.