C# - updating a form

7 replies [Last post]
Chris
Offline
Joined: 07/27/2011

Didn't expect to find this section here! Was expecting my first post to be about MattChatt or something (which is awesome, thank you!).... and now it is... kinda.

Anyway, enough rambling.

I'm working on a game, but I'm having an block with finding code to update a form from another class in c#. I've seen it done in the geekpedia chat client and server, but I can't quite disect it enough to figure it out, the author hasn't gotten back to me, and I'm just at a wall. If anyone has any c# coding experience, please let me know. Once I'm past this the rest of things should fall into place.

Thanks in advance,

Chris.

Chris
Offline
Joined: 07/27/2011
Found

Found it...

http://www.daniweb.com/software-development/csharp/threads/350014

Well. Found the simplest example of it. I"m still not 100% sure what it's doing, but it looks like it's creating a ghost form that you update, and it updates the real form then.

Seems like a poor design policy in .net . I understand wanting things in a compartment to stay there, but constricting the means of feedback is just... gah!

Anyway. Thanks to everyone.

davyK
davyK's picture
Offline
Joined: 05/21/2006
Sorry Chris..don't think I

Sorry Chris..don't think I explained it that well.

You can't do it in VB.NET any more either. You have to create public methods for exposing forms controls to other forms. Here's a link that might explain it better:

http://stackoverflow.com/questions/8566/best-way-to-access-a-control-on-...

There is a another quick and dirty shortcut way of making form controls visible to others but I can't remember it and it isn't recommended.

Chris
Offline
Joined: 07/27/2011
@Davy... Oh I wish it were

@Davy...

Oh I wish it were that simple. I miss VB.NET for that reason.

You see, once you make something visible from other places, C# locks it from accessing certain things... like your form components.

I'm closing in on the issue though. I keep finding people using the 'invoke' keyword... but haven't quite cracked it yet. 3 days and counting...

I would have given up... but I've seen it done. So now I can't let it beat me.

davyK
davyK's picture
Offline
Joined: 05/21/2006
I'm more a VB.NET guy but

I'm more a VB.NET guy but since this stuff compiles to the .net common runtime framework I'm guessing its the same with C#.

You can't directly access controls in another form in the direct way you give any more (e.g. form1.txtSurname.text = "Kelly"). The "new" way is that you have to create public methods in your form for setting and reading form and form object properties that are then called from other forms. A bit tedious I know but there you go.

Chris
Offline
Joined: 07/27/2011
Hey, thanks! The big problem

Hey, thanks!

The big problem with C# is that it's "helpful" and locks out controls and private things from any access from anywhere else. So something like:

Form1.TextBox1.text = "YAY IT WORKS";

Only works if you're calling it form the Form1 class. To do the same thing anywhere else requires some crazy secret hand shake that no one has taught me yet.

I'll post the code I have though when I get home, I'm always open for another pair of eyes on my work... it's easy to miss a ';' somewhere and screw it all up.

Side note:

What kind of databases did you work with?

I'm using an access file for the back end right now, and I feel a little dirty... but I can't expect people to have SQL on their systems. Do you have any DB suggestions for something that can be installed with the game?

clok1966
Offline
Joined: 01/21/2009
I coded in C++ for a few

I coded in C++ for a few years, all boring stuff, nothing too complex, but I would need to know more to "maybe" help.. just like algebra from High school.. i knew it, but nowdays its like greek.. I'm not sure how much if anything I remeber (I liked C++ Builder as lots of stuff was already done, and 99% of my work was with databases). I'm a guy who can read and learn by doing, but If I dont keep doing I forget in amazingly quick fashion :( I like to think I'm just learning new stuff and there is no room for the old (did I just say my brain was to small?)

copy paste some code and I will gladly take a look and probebly Shrug, but maybe can anwser you.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.