I am making a c# level editor and it is a bit out of my league but it should be good to learn oop algorithems.

I have only just started and have already come across a problem. ** I need to load images as sprites and then create a button with the image on and the button's text being the images name. **The button will then call a diolog box which will contain a load of check boxes about which premade methods the sprite will use. All the information: checkboxes, name, image will later be compiled down to a class and used in level editor which will then convert the level into a class file.

The part I need the help with is the bit in blod.

I know im a noob but im only a young teenager and I really want to be a programmer or game developer.

4 Years
Discussion Span
Last Post by yup790

So your sepecific problem is creating these controls at runtime?

If that's the case:

 private void CreateImageButton(Rectangle bounds, string text, Image image)
     Button btn = new Button();
     btn.Bounds = bounds;
     btn.Text = text;
     btn.Image = image;

This will create a button with the given location and size (the bounds argument), will put text on it as well as an image and will add it to your form at runtime.


Thank you so much!!!! Also, how would I make this button load a dialog box.


Add this to skatamatic's sample code:

btn.Click += btn_Click;

Then you'll need to create a new method to handle the Click event:

private void btn_Click(object sender, EventArgs args)
    MyDialogForm form = new MyDialogForm();

Now, there's a couple ways you can handle associating the dialog box with a class. So, is the dialog box going to be different depending on the button selected, or the same basic layout/options?


This only works for 1 button, I need it to work for as many buttons as the user wants.


This allows each button to be associated with one event handler, which is how this should be handled. This is why I asked the question, but let me rephrase it: what is going to be different about each different button press?

If only one button is creating the new dialog, then maybe you put the first piece of code in the wrong location... or something else is going on. Each event handler (essentially the new method we created) can be associated with several events (the Click event of each button).


Each button will open its own dialog box. the settings you choose are then turned into an object, this object will then be turned into an xna/c# code file.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.