duplicating windows form

Dcurvez

Member
Joined
Apr 8, 2010
Messages
18
Programming Experience
Beginner
I have a windows form that is set up like one big calendar for the month of may.

when you click on May 1st...

another form (form2) opens up with some combo boxes and a datagridView on it.

What I need to do is on Form 1 (my calendar form)

when you click on May 2nd...I want to open a duplicate form 2..the one with all the combo boxes on it.

I do not know how to do this lol

do I have to make 30 duplicate forms ( for 31 days of May)

or is there an easier way to make sure that when the user clicks on May2...they dont get a form filled with May1 stuff.


I can see that there is going to be a problem as it sits now because I am going to be adding to form 2 some kind of date box, or a date field in my gridview..So I need each form to display the right date

really dont want to make 30 forms from scratch..I am not that young anymore LOL
 
VB.NET:
Private SecondForm As Form


VB.NET:
Private Sub LoadSecondForm_Click(Byval Sender as Object, ByVal e as EventArgs)

SecondForm = New Form
With SecondForm
.Text = "My Second Form"
.size = new Point(xInt, yInt)
EndWith

Dim vPanel as new Panel
With vPanel
.Dock = DockStyle.Fill
.AutoScroll = True
End With
SecondForm.Controls.Add(vPanel)

'Add your DataGridView and other Controls to the Panel
'Add any data

SecondForm.StartPosition= FormStartPosition.CenterParent
SecondForm.ShowDialogue '(or .Show)


End Sub
 
If you want to transfer some data from the first form a better approach would be:-

VB.NET:
AddHandler CalControl.DateSelected, AddressOf CalendarDateChanged



VB.NET:
Private Sub Private Sub CalendarDateChanged(ByVal sender As Object, ByVal e As DateRangeEventArgs)
'Get the data from your Calendar
Dim vDate As Date = CalControl.SelectionRange.Start
OpenNewForm(vDate, DataItemTwo)
End Sub

VB.NET:
Private Sub OpenNewForm(byval ValueOne as Date, byval ValueTwo as yy)
SecondForm = New Form
With SecondForm
.Text = "My Second Form"
.size = new Point(xInt, yInt)
EndWith

Dim vPanel as new Panel
With vPanel
.Dock = DockStyle.Fill
.AutoScroll = True
End With
SecondForm.Controls.Add(vPanel)

'Add your DataGridView and other Controls to the Panel
'Add any data, like the Date

SecondForm.StartPosition= FormStartPosition.CenterParent
SecondForm.ShowDialogue '(or .Show)


End Sub
 
Another method might be to just load the Calendar as a seperate popup, then populate the form based on the date selected...


VB.NET:
Public CalDate As Date
Public UtilForm1 As Form

VB.NET:
#Region "Calendar PopUp"
    Public Sub CalendarDataPopup()
        UtilForm1 = New Form
        CalDate = "01/01/1900"
        UtilForm1.Controls.Clear()
        UtilForm1.Size = New Point(200, 200)
        UtilForm1.Text = "Calendar"
        Dim vpanel As New Panel
        vpanel.Dock = DockStyle.Fill
        CalControl = New MonthCalendar
        CalControl.MaxSelectionCount = 1
        AddHandler CalControl.DateSelected, AddressOf CalendarDateChanged
        vpanel.Controls.Add(CalControl)
        UtilForm1.Controls.Add(vpanel)
        UtilForm1.StartPosition = FormStartPosition.CenterParent
        UtilForm1.ShowDialog()


    End Sub

    Private Sub CalendarDateChanged(ByVal sender As Object, ByVal e As DateRangeEventArgs)
        Dim vDate As Date = CalControl.SelectionRange.Start
        CalDate = vDate
        UtilForm1.Close()
    End Sub


#End Region



Then add a button on your form to launch the calendar

From the Button.Click event

VB.NET:
AddHandler MyButton.Click, Addressof Launch_Calendar_Click

VB.NET:
Private Sub Launch_Calendar_Click(byval sender as Object, byval e as EventArgs)
CalendarDataPopup()
If not CalDate = "01/01/1900" Then
'Populate the form based on the date

End If
End Sub
 
better explanation

hello and thank you for the fast reply.

let me try to explain it a little better so we arent dancing round and round LOL...dont get me wrong, I do like to dance, Just not that good at it :cool::eek:

anyway

The form 1..the one that holds the main calendar, that form only holds one big clickable calendar. Whenever some one clicks on a date, I am wanting a form2 to open..which I have accomplished. for 1 Day LOL

but now when they click on May 2..I want the same form to open and reflect that it is May 2.

I want to do this without actually having to sit down and recreate 31 form2's from scratch LOL

the form i am trying duplicate at this point does not have any records (content) in the boxes or in DatagridView...It just blank except for the lay out...(ie. gridview, comboboxes, buttons) that are all set and working at this point.

So..really All I want to do is basically make 31 instances of this form, and well..unfortunatly I am toooooo new at all of this when I started this project to know about templates..
 
In that case just create a Dynamic form and you can define the controls and Form.Text based on the variable (Date) from the Calendar

VB.NET:
Dim MyForm2 as New Form
With MyForm2
.Text = "You are working on " & SelectedDate
.Size = New Point(xInt, yInt)
End With

So whatever you have for 01 May 2010 will display as 02 May 2010 when the user clicks that date instead (and so on for any date)
 
hmmmmmmm I dont think this is working

I dont think this is going to work :(

but after giving it some thought ...maybe this way is possible?

This is my form2 Lay out, everything on it is pretty much generic and can be easily linked to my main form. You see, on the main form is a Scratch Calendar. It is one I made myself..it is not a calendar control. The date boxes are actually Buttons that will open form 2 when clicked on.

SO..

the only Identifying way of knowing what date you are on would be the column in a datagridview.

whats happening here is this:

On the left side of my form 2..are a bunch of comboboxes. The selections made from the comboxes will display to the DataGridView on the same form...but the Grid is on the right. That is because this is for a Tire shop that would like to use this on a display screen in their waiting room so that customers could see whats happening to their cars in the shop.

Then at the end of the day..the display Grid contents are saved to a file and closed out. So that when they come in the next day..and click on another day on the calendar ..the same form opens...only empty and ready to use for the day.

Now my problem is this:
LOL...I forgot to put a Date Field in the datagridView :eek:

forgot a date field!!

this morning I tried to just throw a datetimepicker on the form and adding a date field to the grid for it to display to..*sigh*, well im sure you know that ended in disaster..LOL...cuz im using the info in combo boxes to display to grid...and datetimepicker is not a combo box.

so then I said okay..fine, I will just have them type the date in the field..well that didnt work either cuz even though the date was there...the combo selections decided to display in the line underneath it...

so then I said okay..lol...make a combobox with the dates in em...boy o boy...that worked good until ya opened excel up and in the dat field it was all #####.

SO..then I went into the date box and did this #5/1/2010#...and well, thats exactly what you saw in the dropdown LOL

so now I just dont know what to do :(...but somehow I have to get this thing to take a date or the project has to be scapped as it is no good for my user.
 
Back
Top