Group: Forum Members
Last Active: 14 Years Ago
Posts: 5,
Visits: 1
|
I am using the NCommand approach to menu and toolbar generation... and I like it.
I am looking to extend the NCommand approach to buttons. Found the NButton control, but do not see how to automatically bind an NCommand to the NButton - the expected Command property of NButton is not there :-)
... there must be a way since its such an obvious extension.
Any ideas ? (Using Vision 2010 vol1. in a WinForms app)
Thanks J
|
Group: Forum Members
Last Active: Last Month
Posts: 139,
Visits: 184
|
Hello Jeff, The default representation of NCommand was made to look like a button. You can find the properties that setup text, image etc. in NCommand.Properties property: NCommand cmd1 = new NCommand(); cmd.Properties.Text = "Command 1"; ... There is also another possibility to extend the command to host and display any control you want. In the following topic in the forum you can find example that demonstrates how to create such command: http://community.nevron.com/Forum/shwmessage.aspx?ForumID=2&MessageID=3077 Regards, Angel.
|
Group: Forum Members
Last Active: 14 Years Ago
Posts: 5,
Visits: 1
|
Angel -> thanks a lot for the quick reply....
Let me clarify what my goals are...
I have a WinForms form. I have created menus and toolbars by first creating NCommandContext objects, setting appropriate properties, adding these to the NMenuBar and NToolbar objects connected to the form and poof -> menus and toolbars that are bound to the NCommandContext objects.
Now I want to add a regular, everyday button to the form (not to a toolbar).
Using traditional Windows controls it might look something like...
Button b = new Button(); b.Text = "Foo"; myForm.Controls.Add(b);
What I want to do is the following (these properties do not exist, but this is my P-Code)
NCommand com = new NCommand(); com.Properties.Text = "Foo"; ....
NButton button = new NButton(); button.Command = com; // bind the button to the command -- does not exist
myForm.Controls.Add(button);
************* OR *****************
NCommand com = new NCommand(); com.Properties.Text = "Foo"; ...
myForm.Controls.Add(com); // and have com render as a button. Is this what you are suggesting in the first part of your response?
then in the app, when com.Properties.XXX are changed, those properties in the NButton instance also change. Basically a model/view pattern between the NCommand and the NButton.
This all works perfectly in menus and toolbars. I want a simple button. More specifically I want to *bind* an NCommand object to an NButton object.
....
I tried the NControlHostCommand option you suggested... public class NCommandButton : { public NCommandButton() { NButton b = new NButton(); SetControl(b); } }
... and ... private void Form1_Load(object sender, EventArgs e) { NCommandButton button = new NCommandButton(); button.Properties.Text = "Button"; Controls.Add(button.HostedControl); }
but the rendered button has no text, leading me to believe that the bindings between the NControlHostCommand and the HostedControl are not set up properly behind the scenes.
Thanks Jeff
|
Group: Forum Members
Last Active: Last Month
Posts: 139,
Visits: 184
|
Hi Jeff, At the previous post I didn't understand you correctly. Based on the description you gave I assume that you want to share the same command context for command and button. Unfortunately, it is not possible to be done so straight forward as you described. The reason is that NButton properties doesn't match to the NCommand.Properties so they cannot share the same NCommandProperties. You should do it manually by setting each property separately. Regards, Angel.
|
Group: Forum Members
Last Active: 14 Years Ago
Posts: 5,
Visits: 1
|
Angel -- thanks for your time !
In the end that's when I ended up with.
Jeff
|