Click here to Skip to main content
15,881,139 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hey guys,

i have been making my programming language and thanks to some very helpful people, i am now able to create windows forms using my programming language, but that is all. i need to be able to add things to it like buttons and text boxes. the first thing is buttons and this is my current code:

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.Drawing;

namespace programming_language_test_1
{
    class Program : System.Windows.Forms.Form
    {
        static void Main(string[] args)
        {
            StreamReader sr = new StreamReader(args[0]);
            string code = sr.ReadToEnd();
            Run(code);
        }

        static void Run(string code)
        {
            code = code.Replace(((char)13).ToString(), "");

            foreach (string a in code.Split('\n'))
            {
                if (a == "new form")
                {
                    Form form = new Form();
                    form.Activate();
                    form.Enabled = true;
                    form.Focus();
                    Application.EnableVisualStyles();
                    Application.Run(form);
                }

                if (a == "new button")
                {
                    Button button = new Button();
                    button.Visible = true;
                    button.Enabled = true;
                    button.Focus();
                    button.Text = "i am a button";
                    button.Location = new Point(50, 50);
                }
            }
        }
    }
}


1. make a new console application
2. add a windows form
3. add this code in


if you were going to test this code out by using:

new form
new button


you would soon see that a new form is created, but the button isn't on the form. I need help on making buttons and everything on the form.
Posted
Updated 15-Sep-12 0:34am
v2
Comments
Ganesh Nikam 15-Sep-12 6:33am    
hii you need to add control to form
Ganesh Nikam 15-Sep-12 6:34am    
i.e form.controls.add(button)

You have the wrong approach for this.
A Button class has to be assigned to a Form before it appears.
Like

C#
Form f = new Form();
Button b = new Button();

f.Controls.Add(b);


Create you Form, and in the constructor of the From you then create the Button.
The best help you can do for your self, is to start a new project in Visual Studio with a Form project.
From there you can see all the code that Visual Studio Form designer is making.

Good luck :-)
 
Share this answer
 
Comments
Member 8378691 15-Sep-12 6:44am    
this does help, it introduced me to the Form.Controls.Add() function. this isn't the full answer so i won't 'Accept Solution', but i do want you to know that you help me a lot. thnx :)
Kim Togo 18-Sep-12 2:03am    
Great to hear.
But writing all the code for you, will not make you a better coder.
The best way to learn to code, is to do it your self. But I am glad I could help.
[no name] 15-Sep-12 10:31am    
I have upvoted this one. This is the answer the OP was looking for. He just won't accept the solution because you did not write his code for him.
Kim Togo 18-Sep-12 2:04am    
Thanks Wes
Hey you must add your button to the form ..
C#
 Button button = new Button();
                    button.Visible = true;
                    button.Enabled = true;
                    button.Focus();
                    button.Text = "i am a button";
                    button.Location = new Point(50, 50);
this.Controls.Add(button);
 
Share this answer
 
This sounds like homework to me.
However, How to Convert a Console App into a Windows App in C#[^] should help you out.

This describes the various assemblies / steps to use a form with a console application.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900