|
-
Sep 28th, 2008, 04:27 PM
#1
Thread Starter
Lively Member
[2008] MonthCalendar help
How can you add events to a date with MonthCalendar?
-
Sep 28th, 2008, 05:04 PM
#2
Frenzied Member
Re: [2008] MonthCalendar help
I am not sure but i dont think you can actually add an event to a date with the MonthCalender. I think you will have to work with associations maybe using a List(Of ).
-
Sep 28th, 2008, 05:58 PM
#3
Re: [2008] MonthCalendar help
Hello there,
Am I right in saying that what you are trying to achieve is to indicate on the calendar control which dates have an event on that day? i.e. similar to the calendar in Outlook where the dates that you have something on, they are marked in bold?
If this is the case, then you might want to look into adding dates to the MonthCalendar AnnuallyBoldedDates, BoldedDates and MonthlyBoldedDates properties.
These allow to add dates to the calendar that will make them appear bold, for instance:
Code:
monthCalendar1.MonthlyBoldedDates = new System.DateTime[] {
new System.DateTime(2009, 9, 26, 0, 0, 0, 0),
new System.DateTime(2009, 9, 30, 0, 0, 0, 0)};
You could then use the DateChanged Event and if the selected date is one of the dates that have an event associated with it, bring up details of that event.
Hope that helps!!!
Gary
-
Sep 28th, 2008, 06:16 PM
#4
Thread Starter
Lively Member
Re: [2008] MonthCalendar help
How could I have the user type in the event and then have it save the data in a text file and do it that way?
-
Sep 28th, 2008, 06:20 PM
#5
Re: [2008] MonthCalendar help
Hey,
What you would need to do would be something like the following (this is a very rough approximation of one way to achieve this):
1. Have the user select the date in the calendar
2. Have the user enter the information regarding the event
3. Save that information to a text file
Then when you want to display the data
1. Load all the information from the text file into memory
2. Loop through all the events and find the dates and add these to the MonthCalendar as shown above
3. When the user selects a date, display the information about that event.
Depending on exactly what you are trying to do, a text file might not be the best approach. You might want to think about a database, or an xml file.
If you provide some more details about what exactly you are trying to achieve, then I am sure someone here will be able to make some suggestions.
Gary
-
Sep 28th, 2008, 06:26 PM
#6
Thread Starter
Lively Member
Re: [2008] MonthCalendar help
hey,
Could you please explain how I would save the data to a text file because I'm a newbie and don't know how.
-
Sep 28th, 2008, 06:32 PM
#7
Re: [2008] MonthCalendar help
Hey,
Again, there are various ways to do this, and it depends on what you are trying to do, but as a rough guide, this is what you would need to do:
1. Create a FileStream object and either create a new file, or open an existing one.
2. Create a StreamWriter to wrap around the FileStream
3. Use the methods of the StreamWriter to write the information to the file.
4. Once you are done, close the StreamWriter, and then close the FileStream.
Code:
Dim theFile As FileStream = File.Create("C:\somefile.txt")
Dim writer As StreamWriter = New StreamWriter(theFile)
writer.WriteLine("Hello")
writer.Close()
theFile.Close()
It is possible to bypass the need for a FileStream object by simply calling the CreateText method on the File object, which returns a StreamWriter.
Code:
Dim writer As StreamWriter = File.CreateText("c:\somefile.txt")
writer.WriteLine("Hello")
writer.Close()
Or you can write directly to a file using the WriteAllText method.
Code:
File.WriteAllText("c:\somefile.txt", "Hello")
Hope that helps!!
Gary
Last edited by gep13; Sep 28th, 2008 at 07:14 PM.
-
Sep 28th, 2008, 06:42 PM
#8
Frenzied Member
Re: [2008] MonthCalendar help
You may find the following usefull when you want to save to a specific file path on the users computer:
vb Code:
'Here:
'Application Start Up Path
Dim AppStartUp As String = Application.StartupPath
'Desktop
Dim Desktop As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
'MyDocuments
Dim MyDocuments As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
'Application Data
Dim AppData As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
-
Sep 28th, 2008, 06:48 PM
#9
Thread Starter
Lively Member
Re: [2008] MonthCalendar help
Sorry that I don't understand this, but I keep getting errors with the FileStream and StreamWriter. Can you help me with this?
-
Sep 28th, 2008, 06:49 PM
#10
Frenzied Member
Re: [2008] MonthCalendar help
Can we see your code?
Otherwise just use IO.File.WriteAllText().
-
Sep 28th, 2008, 06:50 PM
#11
Re: [2008] MonthCalendar help
Hey,
It might help if you tell me what errors you are getting?
In order for the above to work you need to include:
Gary
-
Sep 28th, 2008, 06:53 PM
#12
Frenzied Member
Re: [2008] MonthCalendar help
 Originally Posted by gep13
Hey,
It might help if you tell me what errors you are getting?
In order for the above to work you need to include:
Gary
Or you can just write the full code.. namespace included.
IO.
-
Sep 28th, 2008, 06:55 PM
#13
Re: [2008] MonthCalendar help
 Originally Posted by noahssite
Or you can just write the full code.. namespace included.
IO.
Granted. However, if he has copied and pasted the above code, it will not work unless the Import statement is used, which would be a lot easier than appending System.IO to each object.
Gary
-
Sep 28th, 2008, 06:58 PM
#14
Frenzied Member
Re: [2008] MonthCalendar help
 Originally Posted by gep13
Granted. However, if he has copied and pasted the above code, it will not work unless the Import statement is used, which would be a lot easier than appending System.IO to each object.
Gary
Well yes.
Also note that system is by default imported. So you would only need to append IO to each object not system.io
-
Sep 28th, 2008, 07:11 PM
#15
Re: [2008] MonthCalendar help
Again, granted. All I was trying to say was, if the above code has been copied and pasted, an Imports statement that has System.IO will be needed in order for it to work.
Gary
-
Sep 28th, 2008, 07:17 PM
#16
Re: [2008] MonthCalendar help
red_bull_NRG,
I have edited the code in Post #7 above, I noticed that there was an error.
Sorry, I was in C# land there for a while. If you re-copy the code then it should now work.
Sorry about that!!
Gary
-
Sep 28th, 2008, 07:17 PM
#17
Frenzied Member
Re: [2008] MonthCalendar help
Oh ya sorry i was jumping to conclusions..
-
Oct 1st, 2008, 09:20 PM
#18
Thread Starter
Lively Member
Re: [2008] MonthCalendar help
How can I set it so that it saves the text file in the same directory that the program is in without knowing where the directory is located?
-
Oct 1st, 2008, 09:51 PM
#19
Re: [2008] MonthCalendar help
Hey,
In the example that I posted, replace the path to the string that I gave, i.e. C:\blah, and give it just a filename instead.
This will then default to storing the file in the same directory as the application is currently running from.
Gary
-
Oct 2nd, 2008, 06:25 PM
#20
Frenzied Member
Re: [2008] MonthCalendar help
 Originally Posted by red_bull_NRG
How can I set it so that it saves the text file in the same directory that the program is in without knowing where the directory is located?
As said in post 8 (Click Here)
To retrieve the Application StartUp path (application folder..):
vb Code:
Dim AppLocation as String = Application.StartUpPath
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|