patterncsharpMinor
Triggering editing mode for a form
Viewed 0 times
editingmodeformfortriggering
Problem
I think that my code isn't perfect and I need a help to understand how to optimize it.
In my application I have a main form and several forms for data editing.
The user can:
You can see an example of my code below. I think that the approach to trigger editing mode isn't good.
An alternative way is to create a new form without parameters and then run methods
Editor modes:
Main form has several buttons:
Editor form:
```
private Item T = null;
private EditMode Mode;
private ItemForm()
{
InitializeComponent();
}
public ItemForm(EditMode mode) : this()
{
Mode = mode;
switch (Mode)
{
case EditMode.Add:
T = new Item();
T.Sort_Order = DateTime.Now;
b
In my application I have a main form and several forms for data editing.
The user can:
- Add a new item
- Edit the selected item
- Delete the selected item
- Duplicate an item with a new name
You can see an example of my code below. I think that the approach to trigger editing mode isn't good.
An alternative way is to create a new form without parameters and then run methods
AddItem(), EditItem(), etc., but I don't think that's a good idea either.Editor modes:
public enum EditMode { Add, Edit, Delete, Copy };Main form has several buttons:
private void AddItemBarButton_ItemClick(object sender, ItemClickEventArgs e)
{
ItemForm IF = new ItemForm(EditMode.Add);
IF.ShowDialog();
IF.Dispose();
}
private void EditItemBarButton_ItemClick(object sender, ItemClickEventArgs e)
{
if (ActiveItem != null)
{
ItemForm IF = new ItemForm(EditMode.Edit, ActiveItem);
MIF.ShowDialog();
MIF.Dispose();
}
}
private void DeleteItemBarButton_ItemClick(object sender, ItemClickEventArgs e)
{
if (ActiveItem != null)
{
ItemForm IF = new ItemForm(EditMode.Delete, ActiveItem);
MIF.Dispose();
}
}
private void CopyItemBarButton_ItemClick(object sender, ItemClickEventArgs e)
{
if (ActiveItem != null)
{
ItemForm IF = new ItemForm(EditMode.Delete, ActiveItem, "somenewname");
MIF.Dispose();
}
}Editor form:
```
private Item T = null;
private EditMode Mode;
private ItemForm()
{
InitializeComponent();
}
public ItemForm(EditMode mode) : this()
{
Mode = mode;
switch (Mode)
{
case EditMode.Add:
T = new Item();
T.Sort_Order = DateTime.Now;
b
Solution
A small note on naming:
Being new to your code base, I have no idea what
Being new to your code base, I have no idea what
MIF represents and worse, IF looks a lot like if and it confuses my eyes. As a rule of thumb, don't abbreviate names. Spell them out so that the maintainer coming behind you understands what everything is.Context
StackExchange Code Review Q#69580, answer score: 6
Revisions (0)
No revisions yet.