I need some help understanding Forms in C#. I thought creating a new form would be as easy as Form myForm = new Form(); but it's not. I started a new windows forms application to try and reverse engineer but since that gave me what I wanted, I continued moving forward. I though the Visual Studio IDE would be more helpful with API inforation and method signatures but I can't figure out how to paint on a form. I looked into some of the msdn api (not as helpful as Java) and tried to go something with private void myForm_Paint(object sender, something else){ but that didn't work either.
I think it's best to create new forms at design time, rather than create them dynamically. I've never used multiple forms in C# before, I found it a bit confusing so I worked around it.
It's definitely easier but sometimes there's a need for creating them dynamically. It's pretty simple though, you can get the hang of it through some simple trial and error.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
namespace FormTest2 { class FormTest2 { static void Main(String[] args) { Form form = new Form(); form.Show(); } } }
Error: The type or namespace 'Form' could not be found
I am designing a game so I need control over drawing image as well as some basic 'drawRectange' etc. for temp graphics as well as eventually removing the standard windows border for my own. This is all really easy in Java and at one point I could do it in VB but I have forgotten all of my VB from 4+ years ago and I want to try something other than java.
It has occured to me that in Java I painted to JPanels inside of JFrames.. potential error there?
Yeah... "Form" is not at the same level as my code I assume. I have the default VStudio using statements:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
and then your code word for word inside of a VStudio generated namespace, a class, and the Main method. Type or namespace "Form" could not be found. From the MSDN article I found it should be under something like System.Windows.Forms but that has dead ended too.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
namespace FormTest2 { class FormTest2 { static void Main(String[] args) { Form form = new Form(); form.Show();
} } }
Is Visual Studio a mistake? I looked at Netbeans although that might be going back to Java. Java is fine but I was looking at moving into Unity3D and DirectX stuff plus another language would be a plus.
That System.Windows.Forms looks important. Does VStudio automatically use these?
What is the C# equivalent to:
public void paintComponent (Graphics g){
super.paintComponent;
g.setColor(Color.BLUE);
g.drawPolygon(poly);
}
for a JPanel in Java? I guess in Java I made a class that extended JPanel and then overrode the paintComponent method myself so I suppose that creating a form is a mistake in and of itself, what I really need is a class that extends Form (or maybe something else that I put onto a form? A panel?) and then write code in that paint method because the paint method I wrote in the Windows Forms application to create a form for me didn't really act as the form's paint method, it was another method with the same constructors but in an exterior class.
So I guess my real question is, where am I storing the graphics information to display to a form? Double clicked inside the design window allows me to edit the Form_Load method, can I get inside the paint Method too? I cannot remember what the layout was in VB, that was years ago. Thanks for the help with the forms declaration. I need to find out what value in VStudio controlls my default imports and add that to it.
Did you create a new Windows forms application or console application? If it's not a Windows form application you'll need to manually add a reference to the dll (right click solution > Add reference... > find System.Windows.Forms)
Where does C# process user defined graphics. If I want to draw a red square and move it across the screen with the arrow keys what do I map the keys to and where do I draw the square?
OK. I sort of understand. Anywhere specific to look on MSDN? Looking at class libraries can only get you so far so I would be interested in any tutorials / examples. I looked on MSDN again and I do see an Event called KeyDown. It looks like the method notation is:
public Class ProjectClass{ /* poor name and this has me thinking, do I make this my form / extend form? */
static void Main(String [] args){
Form form = new Form();
form.Show();
}
public form_KeyDown (object sender, KeyEventArg e){
//So I name it <name>_KeyDown(). Does the <name> connect it to form from earlier?
//Is there a .completion for these methods or will I need to memorize them?
// Do that typing thing
}
}
Java was very concerned that things be organized by class (or at least that is how I was taught). I find it wierd to put methods in different classes with the first part of the name as an address. I understand that C# is NOT Java. Java is all I know at the moment so adjusting to C# is rather jarring at times.