Click here to Skip to main content
15,890,717 members
Home / Discussions / C#
   

C#

 
GeneralRe: Populate a DVG from a csv file Pin
JOHNNYDEMICHAEL8-Jan-14 0:58
JOHNNYDEMICHAEL8-Jan-14 0:58 
GeneralRe: Populate a DVG from a csv file Pin
Dave Kreskowiak8-Jan-14 2:53
mveDave Kreskowiak8-Jan-14 2:53 
GeneralRe: Populate a DVG from a csv file Pin
JOHNNYDEMICHAEL9-Jan-14 2:28
JOHNNYDEMICHAEL9-Jan-14 2:28 
GeneralRe: Populate a DVG from a csv file Pin
Dave Kreskowiak9-Jan-14 4:25
mveDave Kreskowiak9-Jan-14 4:25 
AnswerRe: Populate a DVG from a csv file Pin
OriginalGriff5-Jan-14 23:03
mveOriginalGriff5-Jan-14 23:03 
AnswerRe: Populate a DVG from a csv file Pin
Eddy Vluggen6-Jan-14 8:13
professionalEddy Vluggen6-Jan-14 8:13 
QuestionReading values from window-form to XNA Pin
larsp7775-Jan-14 0:42
larsp7775-Jan-14 0:42 
AnswerRe: Reading values from window-form to XNA Pin
Ron Beyer5-Jan-14 17:52
professionalRon Beyer5-Jan-14 17:52 
Change Form1 to this:

C#
public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        Game1 game1;
        int counter = 1;
           
        public Game1 Game { get { return game1; } set { game1 = value; } }
                   
        public IntPtr getDrawSurface()
        {
            return pctSurface.Handle;
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            game1.buttonHit(350, 450, true);
            counter++;
            label1.Text = counter.ToString();
        }
 
    }
}


Then change Program.cs to:

C#
static void Main(string[] args)
        {
            Form1 form = new Form1();
            
            Game1 game = new Game1(form.getDrawSurface());
            form.Game = game;
            form.Show();
            //game.buttonHit(400,500, true);
            game.Run();
        }


Can you see why? You create a game in the Program.cs file, and you create another one in the Form1.cs file. Even though the names are the same, they are not the same game, essentially you have two Game1 objects created. The one you are talking to in Form1 is not the one you created when the program starts. Somehow you need to give Form1 a reference to the game you created. This is one way, there are others, for example, you could also do this:

Form1.cs:
C#
public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        int counter = 1;
                   
        public IntPtr getDrawSurface()
        {
            return pctSurface.Handle;
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            Program.game.buttonHit(350, 450, true);
            counter++;
            label1.Text = counter.ToString();
        }
 
    }
}


Then change Program.cs to:

C#
static Game1 game;
static void Main(string[] args)
        {
            Form1 form = new Form1();
            form.Show();
            game = new Game1(form.getDrawSurface());
            //game.buttonHit(400,500, true);
            game.Run();
        }


There are many ways to skin a cat, but these are two of the easiest.
GeneralRe: Reading values from window-form to XNA Pin
larsp7775-Jan-14 22:09
larsp7775-Jan-14 22:09 
GeneralRe: Reading values from window-form to XNA Pin
Ron Beyer6-Jan-14 7:44
professionalRon Beyer6-Jan-14 7:44 
GeneralRe: Reading values from window-form to XNA Pin
larsp7776-Jan-14 8:24
larsp7776-Jan-14 8:24 
GeneralRe: Reading values from window-form to XNA Pin
larsp7773-Feb-14 22:00
larsp7773-Feb-14 22:00 
Questionhow i can auto searching devices and sending file with bluetooth using 32feet ,C#,WPf Pin
h.k_net4-Jan-14 21:32
h.k_net4-Jan-14 21:32 
AnswerRe: how i can auto searching devices and sending file with bluetooth using 32feet ,C#,WPf Pin
Kornfeld Eliyahu Peter4-Jan-14 22:29
professionalKornfeld Eliyahu Peter4-Jan-14 22:29 
QuestionCreating C# TCP listener windows Service Pin
Tobben_4-Jan-14 11:47
Tobben_4-Jan-14 11:47 
AnswerRe: Creating C# TCP listener windows Service PinPopular
Ron Beyer4-Jan-14 12:00
professionalRon Beyer4-Jan-14 12:00 
QuestionGetting Thread Exception: while using System.Timer Class Pin
Member 99612394-Jan-14 7:16
Member 99612394-Jan-14 7:16 
AnswerRe: Getting Thread Exception: while using System.Timer Class Pin
Pete O'Hanlon4-Jan-14 8:15
mvePete O'Hanlon4-Jan-14 8:15 
AnswerRe: Getting Thread Exception: while using System.Timer Class Pin
Dave Kreskowiak4-Jan-14 10:20
mveDave Kreskowiak4-Jan-14 10:20 
AnswerRe: Getting Thread Exception: while using System.Timer Class Pin
Brite Varghese9-Jan-14 6:22
Brite Varghese9-Jan-14 6:22 
AnswerRe: Getting Thread Exception: while using System.Timer Class Pin
Member 99612399-Jan-14 17:47
Member 99612399-Jan-14 17:47 
QuestionC# datagridview navigator Pin
Member 78188924-Jan-14 3:58
Member 78188924-Jan-14 3:58 
AnswerRe: C# datagridview navigator Pin
Alan N4-Jan-14 4:20
Alan N4-Jan-14 4:20 
Questionabout Sign unsigned drivers Pin
delphix53-Jan-14 8:43
delphix53-Jan-14 8:43 
AnswerRe: about Sign unsigned drivers Pin
Dave Kreskowiak3-Jan-14 9:05
mveDave Kreskowiak3-Jan-14 9:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.