• entries
743
1924
• views
578744

# Properties

71 views

Once again, I couldn't find a built in control that provided what I wanted for property editing, so I've implemented the above property grid manually.

I'm drawing the lines and text with GDI+ methods, then moving a borderless TextBox over the selected value. When the selection changes, the relevant property is validated and updated. Works really well.

The PropertyForm actually owns a list of MapItemProperties, which can have either a Number or Text type. The idea is that the same form can be used to edit the properties of different sorts of items.

I just add values to the PropertyForm's List and update it. Plan is to have a delegate callback that is called when a value is succesfully updated so I can then manually update whatever is being edited.

In theory, I should even be able to select multiple items (once they are implemented) and have the property form show the common items for all of them.

Pretty cool really. I must learn how to turn these into reusable components at some point.

Are you using tree different forms in one "window" or are the two other forms positioned at the side of the main form or are they controls?

Basically is my question, how have you designed the app? :)

Did you check out the PropertyGrid component? That's what I always use.

Map editor is coming along nicely! You said you're releasing it with Udo, right? (can't remember; haven't been getting a lot of sleep lately lol.)

Walle - three different windows. The right hand two are stay-on-top resizable tool windows.

Programmer16 - I looked at the PropertyGrid, but it looked to me like you had to assign a C# object to it. The properties I need to edit are dynamic properties specified in a scheme file that correspond to the properties of the objects in my game. Can the PropertyGrid be used for that? I couldn't find a way to make it work.

Quote:
 Original post by EasilyConfused Programmer16 - I looked at the PropertyGrid, but it looked to me like you had to assign a C# object to it. The properties I need to edit are dynamic properties specified in a scheme file that correspond to the properties of the objects in my game. Can the PropertyGrid be used for that? I couldn't find a way to make it work.

I'm not quite sure what you mean, but here's an example of using it:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
public partial class Form1 : Form
{
class Object
{
public String Name;
public Point Location;

public Object(String Name, Point Location)
{
this.Name = Name;
this.Location = Location;
}

[DisplayName("Object Name")]
public String ObjName
{
get
{
return Name;
}

set
{
Name = value;
}
}

[DisplayName("Object Location")]
public Point ObjLocation
{
get
{
return Location;
}

set
{
Location = value;
}
}
};

Object MyObject = new Object("Donny", new Point(10, 10));

public Form1()
{
InitializeComponent();

propertyGrid1.Select();
propertyGrid1.SelectedObject = MyObject;
}
}
}



With this I can set my name and location in the property grid.

If this isn't what you need, totally ignore me lol.

Appreciate the explaination and that looks like a really useful control to know about, but unfortunately for this project the objects whose properties I need to edit do not have a corresponding C# object.

For example, inside of Udo (in C++) there are Block objects that have properties like X, Y, Width, Height and so on.

When you define a scheme file for Map.NET (just a text file), you define the items you can place on the map and their properties like:

item 10 "Block"
X=0 Y=0 Width=64 Height=64 Attribute=8 end
image "block.bmp"


Map.NET requires that X, Y, Width and Height are defined but the rest are arbitrary. These are all the properties I need to edit in a property editor.

When Map.NET exports the compiled level map, it writes out each property value into the file for each item. The C++ Udo code then loads these properties into each object from the file.

Hope that makes more sense.

## Create an account

Register a new account