|
It's pretty sparse on the articles on CP. I've seen lots more on MSDN. Hey! A good place to start for source material would probably be Microsoft's Patterns and Practices[^] site. LOT'S of good stuff in there.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Dave Kreskowiak wrote:
Patterns and Practices[^]
Wow - there is a site ? I own about 8 of the books in that series, I didn't realise there were online resources as well.
The last two I bought were on security and ASP.NET performance and scalability. Close to 1000 pages each, so I have some reading to do.....
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hey Dave, I'm not sure if I understood your solution? Separate my function into a library? Well you see its a function that just adds components to Form1, and it is written on Form1's class and works perfectly fine with a click of anything
But yes I posted this question cause now I ALSO need Form2 to be able to call this same function for it to work as per normal on Form1. They both belong to the same namespace webtest and I use Visual Studio 2003... Please help man, thanks!
|
|
|
|
|
If this is the case, it's a bad idea to move it to a library. I thought your method was more generic than that, doing something on more than one form. If it only deals with one form, it's better to leave the method on that form and make it public so other classes can call it.
Follow the code samples in the other posts. They'll show you how to add a reference for Form1 on Form2. From there, it's a piece of cake.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
What I don't get is, if it's a web app, why does Form2 need to call a method that pertains to form1 ? I think something else is not right here.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
It's a web app? I didn't see that anywhere.
I'll go back and look... when I get a chance.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Dave Kreskowiak wrote:
It's a web app?
No, it's not, but the project is called 'webapplication', because it uses the google API. It sounds like he has no need to pass anything anywhere, I'm not sure where he's been confused.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hey man thanks for the suggestion, you make quite alot of sense and I think its exactly what I need to do but unfortunately it still doesn't work. The function is just simply not called. So I took your advice and I did
private void button1_Click(object sender, System.EventArgs e)
{
Form1 form = new Form1();
form.components();
this.Close();
}
in Form2 and only my Form2 closed without Form1 doing what it was suppose to do. It basically adds a shitload of components to itself with this.Controls.Add and yeah it didn't work. Or if you think its quite crap, still not even this works
private void button1_Click(object sender, System.EventArgs e)
{
Form1 form = new Form1();
form.Close();
this.Close();
}
even though both times were ABLE TO BE COMPILED. so maybe you might have a suggestion as to why? May I'm not doing my classes or namespace or the USING commands properly. Both forms belong to a namespace called webtest and the classes Form1 and Form2 are on different pages using Visual Studio 2003. Please help man, I'd very much appreciate it, thanks!
|
|
|
|
|
DJdC wrote:
Form1 form = new Form1();
form.components();
This is really terrible. I assume the components function adds controls to Form1 ? It will add them to the instance of the form which you call close on ( and which is never shown ).
DJdC wrote:
even though both times were ABLE TO BE COMPILED.
That just means that you have no syntax errors, don't get too excited if your code compiles, that guarentees very little beyond a basic syntax check.
I think you need to do some more explaining
1. Is this a web application ?
2. Why do you need to call this method within Form2 ?
3. What are you trying to achieve through using this method ?
4. What do you expect to happen because you called this method from Form2 ? What is going wrong that in your mind is caused by the method not being called ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hey man, I'm not so sure of what's meant to be obvious, I'm pretty new to programming, ESPECIALLY with C#, student you see, haha... I use Visual Studio.NET 2003 and these forms are both part fo the same project. They belong to the same namespace called webtest, which is the project name right? Yes and my function is on Form1 and it adds components to itself and I need it for Form1 at some time to call this for itself.
But for many reasons now I need Form2 to be able to call Form1's function to be performed as per normal on Form1. Its not really something to share as in the same function to be performed on Form2 thats not what I meant. I just need Form2 to call the function for it to be performed as per normal... So on Form2's code I guess I'd need something like
private void pictureBox1_Click(object sender, System.EventArgs e)
{
//Code here
}
Please help man! Thanks
|
|
|
|
|
The answer remains the same. If the method in question is intrinsic to the fact that it's part of a Form class, then derive a class from Form, and put the method there, then derive both Form1 and Form2 from the common base class, so they both have access to the method. If it's a web app, the base class is Page.
Also, if you're adding components dynamically, make sure it happens in OnInit, so the controls are in the page early enough in the lifecycle that viewstate is restored for them, assuming you want it to be. You should not dynamically generate controls if there is any other way of doing things, it just messes with stuff too much.
DJdC wrote:
Its not really something to share as in the same function to be performed on Form2 thats not what I meant. I just need Form2 to call the function for it to be performed as per normal...
So if Forms2 doesn't need the function performed on it, why is it calling the function at all ? Why does Form2 need to call it ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hey Christian, OnInit?lifecycle?viewstate? Dude it now seems like my problem is more than I can bare haha.
The thing is Form2 has information that Form1 doesn't and sometimes I'd need to pass values too Form1, but first I need a way to link them I guess? They both belong to the same project but Form2 isnt able to call the function. I believe by simply calling the function to be performed as per normal, half my battle is won. Dave said to see posts regarding adding a reference of Form1 to Form2 or something like that? I'm not sure how or if this is it. Thanks man! Please reply!
|
|
|
|
|
DJdC wrote:
OnInit?lifecycle?viewstate?
Is it a web app ? If so, stop now and learn what these things mean. If not, just tell me, as I've asked you so many times now. Your namespace suggests it is.
DJdC wrote:
The thing is Form2 has information that Form1, sometimes I'd need to pass values too, but first I need a way to link them I guess?
OK, so Form1 is causing Form2 to be visible ? When you put 'Form1 form = new Form1', you create ANOTHER Form1, it has nothing to do with any other instance that may be visible.
DJdC wrote:
I believe by simply calling the function to be performed as per normal, half my battle is won.
I'm not sure that this is the case, if you don't have a Form1 instance visible ( i.e. it's not a web app, and Form1 creates and shows Form2, or they are somehow both visible on screen at once ), then the battle is lost, there IS no Form1, and therefore no information.
DJdC wrote:
Dave said to see posts regarding adding a reference of Form1 to Form2 or something like that?
Yes. In Form2, make an instance of Form1 as a member variable. Then make the default constructor private, and create a constructor that takes an instance of Form1 as a parameter, and pass in 'this' from Form1 when you create Form2. Then you can access the actual instance of Form1 that is visible from within Form2.
Form2:
class Form2
{
private Form1 parentForm = null;
// So it cannot be used
private Form2(){};
public Form2(Form1 parent)
{
parentForm = parent;
}
}
in Form1:
Form2 form2 = new Form2(this);
form2.ShowDialog(); // Add checks to dialog result if needed
Now, if your code does not conform to this pattern ( where it's a windows app and Form1 creates Form2, then you need to further explain your problem.
And I'll reiterate that if Form1 and Form2 share some data, it should exist in a seperate class, as a static instance, so that both forms can access it, if both need it, then it belongs to both and not one or the other.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Okay Christian. Its a Windows Application that uses the internet but its nothing to do with ASP.NET . A C# Windows Application. webtest is just the name I gave it I'm sorry if this threw you off. I'm sure you're very familiar with Windows Applications integrating Google APIs? Yes I'm doing this as a project in school. Program works fine, nothing fancy, but I have a new requirement now you see, Supervisor gave me a task to save and retrieve information onto xml files. I haven't really mastered xml but I would later on when I got the foundation to practise with!
Form1 is the actual application, I'd make a menu for the user to retrieve saved files via Form2, cause I don't wanna trouble myself of removing everything from Form1 so the user can see my xml information. Form2 is meant to display URLs, of which they are clickable and Form2's job is done. And that my friend is the logic I came up with. You might want to suggest another alternative but I can safely say it would just throw my fragile understanding in the bin, I'm an amateur in programming and I've only touched C# in April haha.
|
|
|
|
|
DJdC wrote:
I'm sorry if this threw you off.
That's OK, I'm just trying to piece this together.
DJdC wrote:
I'm sure you're very familiar with Windows Applications integrating Google APIs?
LOL - nope.
DJdC wrote:
You might want to suggest another alternative but I can safely say it would just throw my fragile understanding in the bin, I'm an amateur in programming and I've only touched C# in April haha.
*grin* I'll do my best here.
So as I understand it, the functionality you want from Form1 is the stuff that deals with the XML ? There is no reason that this can't be moved to a third class, so both classes can access the XML information from there. In fact, a good design would be to have a class that reads the XML, and then exposes the stuff the XML file stores, so this one file has the job of reading the XML, giving you access to the info, letting you change/add to it, and then saving it. That way, only one part of the code needs to know how your config file is being stored, the rest just knows there is a config file class that it uses.
Or, if that's too hard, then what I illustratated, and making methods public, will solve your problem, at the expense of quality in terms of design. You may prefer to come back to that lesson, but a factor is, how smart is your teacher, and will you be marked on quality of design ? Remember, any class can be created any number of times, and any non static property will only have a specific value for a specific instance of the class. Imagine you have a class to represent a student. If every instance of the class had the same name, you could only create one student, right ? Your form is the same. You can make as many Form1 class instances as you like, but only the one you can see on the screen contains information that is the result of things you've done while using the program ( i.e. stuff where a value has been set outside the constructor ).
I really hope that helps. Let us know if you need more info.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Errrmmm my components function won't have any xml codes. I wanted Form2 to handle all the xmls, and display whatever URL strings necessary, which are clickable, and on clicking it closes Form2 and Form1 runs the components function as per normal, of course with an extra code dealing with this string. The strings are meant to be URLs, and one of the things components() adds is a web browser window which I'd intend to use to navigate to the URL the Form2 string would suggest. I don't know, the logic just seems very clear cut to me I really don't intend to confuse you. And at this point, haha, I won't bother abt how nice my code looks, as long as it works and I understand everything when presentation time comes hahaha.
|
|
|
|
|
DJdC wrote:
I wanted Form2 to handle all the xmls, and display whatever URL strings necessary, which are clickable, and on clicking it closes Form2 and Form1 runs the components function as per normal, of course with an extra code dealing with this string.
So where is the issue ? Form2 returns the string selected, and Form1 uses it ? What does Form1 need to give Form2 again ?
DJdC wrote:
and one of the things components() adds is a web browser window which I'd intend to use to navigate to the URL the Form2 string would suggest.
This method adds a web browser to Form1 ? If you want a web browser in Form2, you need to add it there. Why do you need to add it using code ?
DJdC wrote:
And at this point, haha, I won't bother abt how nice my code looks, as long as it works and I understand everything when presentation time comes hahaha.
It's not about appearance, it's about good design. But sure, I can appreciate that you want to get over the initial learning curve before you worry about that.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Form1 doesn't give Form2 anything, Form1 simply opens Form2 when necessary, letting them be open simultaneously. Form2 is meant to display clickable strings(I mean URLs) frm xml files, thats all. Once anything is clicked, I want to close Form2 and let components() do its job on Form1.
Yes components() adds a web browser on Form1, and no I don't need the browser on Form2, because Form1 has plenty other functions than just calling Form2.
So basically I need to know how to link forms I guess? Or at least thats what I think I need to know.
|
|
|
|
|
If Form1 has no information that Form2 needs, then you've been wasting your time all along
in Form1
Form2 dlg = new Form2();
if (dlg.ShowDialog() == DialogResult.OK)
{
// any post processing in here
}
I assume you've done this all along. If you don't need the browser in Form2, then I'm at a loss as to why you'd want to call the function in form2 ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
You could pass form2 a reference to form1, and then form2 could simply call components() like it would for any other classes' method. Another approach(and possibly cleaner) would be for form2 to fire an event that form1 is registered to listen to, and then in form1's event handler it could call components().
|
|
|
|
|
i am new in the field of game programming , and i decided to use .NET as my platform and C# as my programming language and managed directx9 as my graphics library.
now i need help to find out many resources about this field and under previous considrations , if u can help me please answer me how to find a good resources.
secondly i am wondering is there any tool on earth that can generate the managed directx 9 code , so the devloper can concentrate in the bussnes logic.
thx all
|
|
|
|
|
|
|
Keep in mind that there are no commercial games written in C# for a reason. But by all means, it's as good a place to start as any.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
No comercial games?
try what about?: http://arenawars.krawall.de/eng/
And the only reasons not many comecial games are written in C# is:
1) the VAST majority of games dev tallent is in C++ ...any move over to C# is going to be a slow process as a games dev's time is strongly dictated by deadlines so time out to learn C# is not easy to come by.
2) The prodution cycle for most games is longer than Managaed DX has been a viable alternative for so no wounder they're arn't many commerical games in C# about :?
There is no reason commercial games can not be made in C# with managed DX9 unless you really need to hit up as much power as is possible (that 2% you loose from using managed code) and you are able to use unmanaged code to squeeze it out of a system.... but not every game (or even, every 10th game) needs that raw power and if im not mistaken there is a 3D engine written in C# that belts along faster than its C++ coded version (cant remember the name check out gamedev.net for info).
So to the OP dont abandon C# for games devving, you will get results much faster than a simular project in C++ and it will help keep motivation up ... and no one will be able to tell any difference between your games and games written C++... accept your games will be finished long before the same thing could be coded in C++.
As a non-pro, C#'s managed nature will help you avoid many a pitfall you could stumble in C++ that could cause slowdown or performance issues... so from an amatures point of view you will probably find your games run better if written in c# than they would if you wrote them in c++ as C# will be handling a lot of the stuff that may cause problems for you.
read around, get oppinions from games dev sites, C# is as viable as C++ right now and there is no reason to be struggling with C++ when C# is sutch a cake walk to code.... Ok you wont get a professional games dev' job right now with C# right now but i saw UbiSoft advertising for .Net coders to write games development tools earlier this year, so its only a matter of time before more games dev' houses take up C#.
|
|
|
|
|