I have numerous methods returning voids that I written for my program in C# forms which I use all the time. Since I need to use them on multiple forms, I figure there must be better way to save them in some Class, Data rather then copying them for every form individually… I am quite new at this so I am looking for advice. What to do?
Sample: I’ve created methods similar to these:
private void NewBtn(string nName, int locX, int locY)
private void NewPic(string nName, int locX, int locY, int SizX, int SizY, Image Img)
Now, instead of copying them in every form I want to write them in some other file and still be able to call them in any new form I add. Suggestions?
Ok everyone else has taken a shot at this I might as well too.
I think this answer has been suggested but maybe not explained clear enough.
add a new class to your project
in Visual C# you would go
Project -> add Class
Give your Class a name and click ADD
Normally I name this class Tools
then inside the Tools.cs file
EDITED:
I was looking at some of your other questions and I think I found the actual method you are trying to implement. As someone had commented in that thread you really need to use better names, I have made changes to the method to hopefully simulate what you are going for. For anyone trying to understand this please see C# graphics, paint, picturebox centering
Now in one of your forms
or
PictureBox myButton=Tools.NewBtn(“btn1”,200,200);
I did not compile this or test it in anyway, there may well be a typo, please let me know if there is something obvious so I can edit out the errors