Appointment Calendar for a month on one form

divjoy

Well-known member
Joined
Aug 25, 2013
Messages
159
Programming Experience
1-3
Hi,

I am trying to design a monthly calendar to be shown on a form at once.

I can do a week using a datagridview, showing each appointment by time and day of the week, but with 31 days it seems difficult to decide which way I should do it.

Do I add 31 datagridviews to a single form, that may be slow to draw so many all at once and show in one form?

Or compress all appointments into 1 string and show a rectangle for each day of the month, which could be easier to do and run a lot faster.

I'd be interested in what people think and a pointer in the best direction? Or even screenshot of how one might look?

kind regards
G
 
I don't really want to go down a blind alley, so hoping someone might have tried it and decided the best way to go!

I'm thinking now that I will use a datagridview with large cells there is a cell for each day of the month and I need a way to show the appointments for that day as a single line in each cell.
Can anyone help with the code?
 
Last edited:
If you want something that the DataGridView does not already do then you can look into creating your own custom column, cell and editing control classes. Another option for tabular layout, if you're not editing in-place, is a TableLayoutPanel. Each cell can only contain one direct child control so, if you want something complex, you can add a Panel and then add an arbitrary number of children to that. Most likely though, you'd be better off creating a user control that already contains the children you want, then adding instances of that to the cells. I can imagine a situation where you have a Panel with AutoScroll set to True on the form and a TableLayoutPanel in that, then a FlowLayoutPanel in each cell and then an arbitrary number of your own user control in that. If you familiarise yourself with what controls are available and what they can do first, then you can determine what controls would be best in which situation. This is what I mean about doing research first. If you don't know what controls are available then you won't know to use them in situations that suit them. If you do the research first, you already know the possibilities to choose from.
 
1584806132980.png


So here is my draft monthly calendar using a datagridivew , I still have to add more appointment data to the appt time which is easy enough, but I'd like to color code the appointment lines?
Any idea how it might be done?
 
Having trouble adding CR/LF to text in cells I have added

DataGridView1.DefaultCellStyle.WrapMode = DataGridViewTriState.True

But that allows to display CR/LF but also wraps the text , Id prefer not to warp the text if possible, any ideas?
 
Yes, that what I want to do, may need a bit of help tho.

My first step now is to put together say 4 strings with CR/LF at the end, with each line with a different cokour background into some type of object?
Can this be done in a textbox or listboax perhaps?

and then add that object to the cell in the datagridview using the cellpaint event!

Any help appreciated!
 
There's no need for a control unless the user is entering the text or you want them to format it. Otherwise, you just do it in code. String manipulation is simple stuff and something you can research independently.

Strings don't contain formatting though. A String is just text. If you want to include formatting metadata then you have to use a format that supports that, e.g. HTML or RTF. You'd have to parse out that metadata when actually displaying the text though, unless you were using a control understood the format, e.g. a WebBrowser or RichTextBox. If you're just drawing the text yourself on the cell in the CellPainting event handler, you need to use GDI+ to draw the different parts of the text in the appropriate colours, e.g. if you have three lines of text in three different colours then you would need to call DrawString three times. Do some research on the CellPainting event - starting with reading the documentation and including searching for examples online - and also about GDI+ in general, so you know the sorts of things you can do in the event handler.
 
Your right no control required, just a string of text nad using the graphic pen to color thetext.

I have looked at a few examples but not that clear yet. Will do some testing tomorrow.

Does every cell call cellpaint?
 
Does every cell call cellpaint?
No cells call cellpaint. The CellPainting event is raised by the grid every time any cell needs to be painted. Like all cell-centric events of the DataGridView, the CellPainting event provides a means to determine which cell it currently relates to, so you can decide whether to act based on that.
 
So I first need to disable any cell content I was adding!

Then I somehow need to set the cell paintintg e.Value to the string content I wish to display.

So I need to pick up the string from with cellpainting method !

And then do it through cell paint using the Graphic pen!
 
The Value of each cell should be the data you want in that cell. How you then display that data is another matter. The data is already in the Value property. You get it from there and then draw it using GDI+.
 
So here is my test code, but text disappears instantly for some reason?
VB.NET:
Private Sub DataGridView1_CellPainting(sender As Object, e As DataGridViewCellPaintingEventArgs) Handles DataGridView1.CellPainting

        If e.RowIndex >= 0 AndAlso e.ColumnIndex >= 0 Then
            e.Paint(e.ClipBounds, DataGridViewPaintParts.All)  'Draw all parts of the cell normally
            Dim newRect As New Rectangle(e.CellBounds.Left, e.CellBounds.Y + 6, 12, 12)
            e.Graphics.FillRectangle(Brushes.Crimson, newRect) 'draws a red filled rectangle in each cell

            Dim RowHeight1 As Integer = 80 'DataGridView1.Rows(e.RowIndex).Height
            Dim newCell As Rectangle = DataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, False)

            '  newCell.X += DataGridView1.Left
            ' newCell.Y += DataGridView1.Top + RowHeight1

            Dim px As Point = PointToScreen(New Point(newCell.X, newCell.Y))
            
            Using font = New Font("Century Gothic", 8.0F, FontStyle.Regular, GraphicsUnit.Pixel)
                Using Brush = New SolidBrush(Color.Black) 'Pen Type
                    ' Int(px = newCell.X + newCell.Width)
                    e.Graphics.DrawString("SUBJECT:", font, Brush, px)
                    px.Y = px.Y + 12
                    e.Graphics.DrawString("ENGLISH", font, Brush, px)

                End Using
            End Using
            e.Handled = True
        End If
        'e.Handled = True  'complete cell painting!

    End Sub
 
So what your saying is I first populate the datagridview cells with my text.

CellPainting will then pick up this text and assign it to e.Value ?

And then I can manipulate the graphics using GDI. What the difference between GDI and e.Graphics.Drawstring ?

kind regards
 
Back
Top