By Edhy Rijo - 4/24/2008
Hi,I have a WinForm which I need to handle to either Hide or Close the form based on a parameter passed to the form. I have the following code as part of my LaunchForm method: loForm = CType(Activator.CreateInstance(FormType, Parameters), Form)My question is where in the called form class I enter the code to handle the parameter? I tried this code without sucess: Private _HideThisform As Boolean = FalsePublic Sub New(ByVal tHideForm As Boolean) ' This call is required by the Windows Form Designer. InitializeComponent() ' Add any initialization after the InitializeComponent() call. _HideThisform = tHideForm End Sub Can anybody show me a sample code to handle a form's parameter? Thanks!
|
By Trent L. Taylor - 4/24/2008
The problem is that your parm is being interpretted as another overload. Explicitly define the ParamArray parm as an object array and it will ensure that the proper overload is used:Dim loForm As Form loForm = CType(Activator.CreateInstance(GetType(Form1), New Object() {True}), Form)
|
By Edhy Rijo - 4/24/2008
Hi Trent,I am sorry, but I am still getting an error and been trying to get this one without sucess. Here is the whole LaunchForm versio n I am using: Private Sub LaunchForm(ByVal FormType As System.Type, ByVal ParamArray Parameters() As Object) '-- Establish Locals Dim loForm As Form '-- Create the form If Parameters Is Nothing Then loForm = CType(Activator.CreateInstance(FormType), Form) Else ' loForm = CType(Activator.CreateInstance(FormType, Parameters), Form) ' this is the Original code I had. loForm = CType(Activator.CreateInstance(FormType, New Object() {Parameters}), Form) End If '-- Check if the form exist in the MDI collection and if so activate it. For Each currentForm As Form In Me._MDI.Controls If currentForm.Name = loForm.Name Then '-- IF the form is minimized then restore it. If currentForm.WindowState = FormWindowState.Minimized Then currentForm.WindowState = FormWindowState.Normal End If '-- Show the form on top of the others. currentForm.BringToFront() Exit Sub End If Next '-- Set the MDI parent loForm.MdiParent = Me '-- Show the form loForm.Show() End Sub The error I am getting is this: MissingMethodException Constructor on type 'IBS_UI.frmInsuredCustomer' not found. Source : mscorlib Stack Trace: at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) at System.Activator.CreateInstance(Type type, Object[] args) at IBS_UI.RibbonForm1.LaunchForm(Type FormType, Object[] Parameters) in E:\Visual Studio 2008 Projects\StrataFrame\Insurance Broker System (SF)\UI\RibbonForm1.vb:line 148 at IBS_UI.RibbonForm1.RibbonControl_ItemClick(Object sender, ItemClickEventArgs e) in E:\Visual Studio 2008 Projects\StrataFrame\Insurance Broker System (SF)\UI\RibbonForm1.vb:line 196 at DevExpress.XtraBars.BarManager.RaiseItemClick(ItemClickEventArgs e) at DevExpress.XtraBars.BarItem.OnClick(BarItemLink link) at DevExpress.XtraBars.BarBaseButtonItem.OnClick(BarItemLink link) at DevExpress.XtraBars.BarItemLink.OnLinkClick() at DevExpress.XtraBars.BarItemLink.OnLinkAction(BarLinkAction action, Object actionArgs) at DevExpress.XtraBars.BarButtonItemLink.OnLinkAction(BarLinkAction action, Object actionArgs) at DevExpress.XtraBars.BarItemLink.OnLinkActionCore(BarLinkAction action, Object actionArgs) at DevExpress.XtraBars.ViewInfo.BarSelectionInfo.ClickLink(BarItemLink link) at DevExpress.XtraBars.ViewInfo.BarSelectionInfo.UnPressLink(BarItemLink link) at DevExpress.XtraBars.Ribbon.Handler.BaseRibbonHandler.OnUnPressItem(DXMouseEventArgs e, RibbonHitInfo hitInfo) at DevExpress.XtraBars.Ribbon.Handler.BaseRibbonHandler.OnUnPress(DXMouseEventArgs e, RibbonHitInfo hitInfo) at DevExpress.XtraBars.Ribbon.Handler.BaseRibbonHandler.OnMouseUp(DXMouseEventArgs e) at DevExpress.XtraBars.Ribbon.Handler.RibbonHandler.OnMouseUp(DXMouseEventArgs e) at DevExpress.XtraBars.Ribbon.RibbonControl.OnMouseUp(MouseEventArgs e) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at DevExpress.Utils.Controls.ControlBase.WndProc(Message& m) at DevExpress.XtraBars.Ribbon.RibbonControl.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativewindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativewindow.WndProc(Message& m) at System.Windows.Forms.Nativewindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
The value passed to the FormType parameter in LaunchForm is something like this: 'IBS_UI.frmInsuredCustomer' which is the form name stored in the Tag properties of the menu. This has been working very well but now I have one form which I would like to pass a parameter so I can know where to run some code in that form based on this parameter, so I am trying to get the LaunchForm to work with form with or without parameters. P.S. Sorry for the long post, but I think I sould clarify what I am doing.
|
|