Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello,

 

I've written a calendar for the pocket pc.

 

The problem is that this one is very slow and when i jump a month back or forward, the created days from that previous month won't dissapear.

 

Is there any way to remove all the created 'txt' labels? And what about the speed... I am just a simple beginnen, but i have to create it for my work... am a trainee :p

 

   Private Sub Calendar() 'ByVal iYear As Integer, ByVal iMonth As Integer, ByVal iDay As Integer)

       System.Windows.Forms.Cursor.Current.Current = System.Windows.Forms.Cursors.WaitCursor()

       Dim iDaysInMonth As Integer 'The number of days in a month
       Dim iCurrentDay As Integer = 1 'The current day... necessary for the loop
       Dim iDowStart As Integer 'Declare daysofweek from the 1st day of the month
       Dim iBoxDimension As Integer = 30 'The width of the text box with the day number in it.
       Dim iBoxPosX, iBoxPosY As Integer 'The position of the box which is going to be created
       Dim iTxtPoxX, iTxtPoxY As Integer 'The position where the day should be placed.

       iDaysInMonth = Now.DaysInMonth(iYear, iMonth)
       iDowStart = DateTime.Now.Parse(iYear & "/" & iMonth & "/01").DayOfWeek + 1 'The number of the Day Of Week for the 1st of the month
       iTxtPoxX = iDowStart 'Initize with the Day Of Week start
       iTxtPoxY = 1 'Initize with 1

       Do Until iCurrentDay > iDaysInMonth
           Dim pnlBorder As Panel 'Create a panel for the border
           pnlBorder = New Panel

           Dim pnlBack As Panel 'Create a panel for the background
           pnlBack = New Panel

           Dim txt As Label 'Create a label
           txt = New Label

           txt.Refresh()

           iBoxPosX = ((iTxtPoxX * iBoxDimension) + (iTxtPoxX)) - iBoxDimension
           iBoxPosY = ((iTxtPoxY * iBoxDimension) + (iTxtPoxY)) - iBoxDimension

           With pnlBorder    'Panel is border for the label
               .Location = New Point(iBoxPosX, iBoxPosY)
               .Size = New Size(iBoxDimension + 2, iBoxDimension + 2)
               .BackColor = Color.DarkBlue
               .Visible = True
           End With

           With pnlBack    'Panel is background for the label
               .Location = New Point(1, 1)
               .Size = New Size(iBoxDimension, iBoxDimension)
               .BackColor = Color.White
               .Visible = True
           End With

           With txt    'Create label for the number of the day
               .Location = New Point(0, 0)
               .Size = New Size(iBoxDimension, iBoxDimension)
               .Text = iCurrentDay
               .Visible = True
               .ForeColor = Color.Firebrick
           End With

           Me.Controls.Add(pnlBorder)
           pnlBorder.Controls.Add(pnlBack)
           pnlBack.Controls.Add(txt)
           iCurrentDay += 1
           iTxtPoxX += 1
           If iTxtPoxX = 8 Then
               iTxtPoxX = 1
               iTxtPoxY += 1
           End If
       Loop
       System.Windows.Forms.Cursor.Current.Current = System.Windows.Forms.Cursors.Default()
   End Sub

Posted

Another way to see this

 

First thing first.

 

  1. I recommand you doing it in a class.
  2. To remove all objects from your calendar...

if dates are labels... make this :

 

ArrayList tabDates = new ArrayList(31); // 31 is enough for 1 month ya !?

 

everytime you want to add : tabDates.Add( ... );

everytime you want them to be cleared : tabDates.Remove(...);

 

BUT

 

if you want to do it your own way... you'll have to delete controls

 

Me.Controls.Add(pnlBorder) ' this one may be redundant

pnlBorder.Controls.Add(pnlBack) ' this one too

pnlBack.Controls.Add(txt) 'this one is okay

 

you see... if you add controls to a panel... they won't disapear like this. You'll have to destroy or the pnlBack or all the txt inside.

 

If you need more precision... just tell me :D

"If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown

"Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me

"A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend.

C# TO VB TRANSLATOR

Posted

Thank you very much for your reaction.

 

I've added a screenshot of the calendar.

 

The blue border is the first layer, a panel...

The white background inside the blue border is the second layer, a panel

The text is the third layer, a label

 

So you will see the layout of it... thats the problem i've got. The position of the panels+labels who have to be re-positioned. :mad:

 

Im going to check how my calendar acts on my pocket PC. :)

Posted

Well... you've made an awesome job.

Very clean... and really pratical. Continue like this ! It's on a good way.

"If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown

"Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me

"A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend.

C# TO VB TRANSLATOR

Posted

I know, Thanks...

 

There are some problems which i can't solve i think becouse of the compact framework :(

 

When I click a daynumber there should be a query triggered with the current date and show the appointments. Not possible with a label...

 

Another problem is that the screen should be refreshed.

 

I've got an idea, just create all the colums and first fill them with "" (nothing), after that fill them with the day number. Tomorrow another day. But then they arent still clickable...

 

Maybe There will be a miracle this evening and I will get a solution for this prob :D

 

[edit]My calendar is not slow on PPC :cool: :) :D [/edit]

Posted

So the process is now more fast !?

 

Should help to have 100 labels less in central memory. :p

"If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown

"Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me

"A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend.

C# TO VB TRANSLATOR

Posted

Lol... I am going to write it from the beginning... the days should be clickable.

 

Then there will be two other problems. How do I know which day is clicked and how can I see how many appointments are there on that day? (extra label on button?)

 

:mad: :mad: :mad:

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...