public class FormEx<Tform> where Tform : XtraForm
{
public Tform form;
public FormEx(Tform parameterForm)
{
form = parameterForm;
}
public FormEx()
{
form = Activator.CreateInstance<Tform>();
}
public FormEx<Tform> LoadForm(Action<Tform> load)
{
form.Load += (zz, ee) => { load(form); };
return this;
}
public FormEx<Tform> Close(Action<Tform> close)
{
form.FormClosed += (zz, ee) => { close(form); };
return this;
}
public FormEx<Tform> Confirm(Action<Tform, FormEx<Tform>> confirmAction)
{
EventInfo eventInfo = form.GetType().GetEvent("Confirm");
JDelegate confDelegate = () => { confirmAction(form, this); };
eventInfo.AddEventHandler(form, confDelegate);
return this;
}
public FormEx<Tform> Confirm(Action<Tform> confirmAction)
{
EventInfo eventInfo = form.GetType().GetEvent("Confirm");
JDelegate confDelegate = () => { confirmAction(form); };
eventInfo.AddEventHandler(form, confDelegate);
return this;
}
public Action ExecuteAfterClose;
public FormEx<Tform> ShowDialog()
{
using (form)
{
if (UserPrivileges.CheckResource(typeof(Tform).Name))
{
form.ShowDialog();
}
else
{
Mess.boxInf("Нямате права за този ресурс.\r\nЗа повече информация се обърнете към Вашия администратор!");
}
if (!form.Disposing && !form.IsDisposed)
{
form.Dispose();
}
if (ExecuteAfterClose != null)
ExecuteAfterClose();
return this;
}
}
public FormEx<Tform> Show()
{
form.Show();
return this;
}
}
// EXAMPLE
new FormEx</*FormClass*/>()
.LoadForm(form =>
{
})
.ShowDialog();
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter