|
Prev: How to call a WCF web service
Next: Need some LINQ love
From: iDesmet on 24 Jun 2008 18:50 Hallo, For example, I have the following procedure to Load a form: Public Sub LoadClient(ByVal Caption As String) Dim frmClient As New frmClient() frmClient.MdiParent = frmMainMDI frmClient.Text = Caption frmClient.Show() frmClient.Focus() frmMainMDI.Text = "Prod 2008 - " & Caption frmMainMDI.btnClientNew.Enabled = False End Sub So to load it, I only call this: LoadClient("New Client") But I need to write almost the same to load another form. The only thing I change is frmClient and the buttom I want to disable in this case. So my question is this: Is it posible to make a generic procedure so I only pass the values I want like in Caption? or I need a diferent approach to acomplish this task? If so how? Thanks in advance Best Regards, David Desmet
From: Steve Gerrard on 24 Jun 2008 22:35 iDesmet wrote: > Hallo, > > For example, I have the following procedure to Load a form: > > Public Sub LoadClient(ByVal Caption As String) > Dim frmClient As New frmClient() > frmClient.MdiParent = frmMainMDI > frmClient.Text = Caption > frmClient.Show() > frmClient.Focus() > > frmMainMDI.Text = "Prod 2008 - " & Caption > frmMainMDI.btnClientNew.Enabled = False > End Sub > > So to load it, I only call this: LoadClient("New Client") > > But I need to write almost the same to load another form. The only > thing I change is frmClient and the buttom I want to disable in this > case. > > So my question is this: Is it posible to make a generic procedure so I > only pass the values I want like in Caption? or I need a diferent > approach to acomplish this task? If so how? > I would write it like this: Public Sub LoadClient(ByVal frm As Form, ByVal Caption As String) frm.MdiParent = frmMainMDI frm.Text = Caption frm.Show() frm.Focus() End Sub And call it like this: LoadClient(New frmClient(), "New Client")
From: Cor Ligthert[MVP] on 24 Jun 2008 23:48 Hi, I think I would do it like this. However I don't understand that button, a menu looks more obvious to me. And for sure not that retro word "Load" (although Microsoft uses it too standard in Load_Form). \\\ Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click Static staticNumber As Integer = 0 CreateClient(staticNumber.ToString) staticNumber += 1 End Sub Public Sub CreateClient(ByVal Caption As String) Dim frm As New Form() frm.MdiParent = Me frm.Text = Caption frm.Show() frm.Focus() frm.Name = "Prod 2008 - " & Caption frm.Text = "Prod 2008 - " & Caption ' Button1.Enabled = False End Sub /// Be aware that the reference to this frm goes direct out of scope so you have to reference it using the MDIParent.MdiChildren array. http://msdn.microsoft.com/en-us/library/system.windows.forms.form.mdichildren(VS.80).aspx Cor "iDesmet" <idesmet.work(a)gmail.com> schreef in bericht news:aad8816a-84ca-475a-8572-827b08a96f43(a)y21g2000hsf.googlegroups.com... > Hallo, > > For example, I have the following procedure to Load a form: > > Public Sub LoadClient(ByVal Caption As String) > Dim frmClient As New frmClient() > frmClient.MdiParent = frmMainMDI > frmClient.Text = Caption > frmClient.Show() > frmClient.Focus() > > frmMainMDI.Text = "Prod 2008 - " & Caption > frmMainMDI.btnClientNew.Enabled = False > End Sub > > So to load it, I only call this: LoadClient("New Client") > > But I need to write almost the same to load another form. The only > thing I change is frmClient and the buttom I want to disable in this > case. > > So my question is this: Is it posible to make a generic procedure so I > only pass the values I want like in Caption? or I need a diferent > approach to acomplish this task? If so how? > > Thanks in advance > > Best Regards, > David Desmet
From: iDesmet on 22 Jul 2008 21:57 Thanks a lot for showing me the way. I had created a Sub that fit my needs. It works well, later I'll add a little more of code to change the Icon of the form. I tried it but didn't work as expected, but anyway, for now it's oke. Here's my code: Public Sub frmMdiChildCtrl(ByVal frmChildForm As Type, ByVal frmChildCaption As String) ', ByVal frmChildIcon As Icon) Dim childForm As Form 'Check if the child form is already displayed so there isn't two instances showing For Each childForm In frmMainMDI.MdiChildren If childForm.Text = frmChildCaption Then If childForm.WindowState = FormWindowState.Minimized Then childForm.WindowState = FormWindowState.Normal End If childForm.Activate() Return End If Next childForm = CType(Activator.CreateInstance(frmChildForm), Form) childForm.MdiParent = frmMainMDI 'childForm.Icon = frmChildIcon childForm.Text = frmChildCaption childForm.Show() childForm.Activate() 'childForm.Focus() frmMainMDI.Text = gsAppName & " - " & frmChildCaption frmMdiChildCtrlBtn(frmChildCaption) End Sub
|
Pages: 1 Prev: How to call a WCF web service Next: Need some LINQ love |