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
 
You probably hadn't read my previous post when you wrote this but I will repeat anyway: look first, ask questions later. DrawString is what draws the string so that is where you will control how the string is drawn. READ THE DOCUMENTATION.
No I read that.
 
So I've been working with your code and while I can assign a table with data to the datagridview and change the color of the text, it seems clear that it cant do the things I want it to which is such a shame.

It always wraps the text (which I dont want!) I can't change the background of the text per line of text. I cant add a scroll bar in the cell if if there too many lines either.

See image below of how Id like it too look.. Date right or centered at the top. Each appointment has its own line with a diff back color and if ther more than 4 lines a scroll bar appears.

It doesnt sound a lot but I think CellPainting isnt going to cut it! What alternative do we have?

1585055452494.png


Here my Claendar so far with data loaded from SQL Server, just no formatting being appled!

1585055830552.png
 
It always wraps the text (which I dont want!)
No it doesn't. I told you to read the documentation for the DrawString method and @JohnH specifically told you that it was the StringFormat parameter that controlled wrapping. Did you look into that at all? It's hard to see that you could have. All you had to do was change this:
VB.NET:
e.Graphics.DrawString(lineText, e.CellStyle.Font, brush, e.CellBounds)
to this:
VB.NET:
e.Graphics.DrawString(lineText, e.CellStyle.Font, brush, e.CellBounds, New StringFormat(StringFormatFlags.NoWrap))
Not hard to work out if you had taken the advice provided. I'm not providing this specifically to help you, but rather to show how easy it was to help yourself. If you're not prepared to do that, I'm not prepared to do any more either.
 
I can't change the background of the text per line of text.
Of course you can. You can draw whatever you want using GDI+. The "background" is just the first layer that you draw. If you want multiple different-coloured backgrounds then you call FillRectangle multiple times, then call DrawString to draw text on top of that.
I cant add a scroll bar in the cell if if there too many lines either.
Of course you can't. There's no control in the cell so how could there be a scrollbar? If you had researched how the DataGridView control worked then you'd know that cells don't contain controls by default and are simply a drawn representation of data, which is why that CellPainting event exists in the first place. The only time a control exists in a cell is when you are editing it. If, as I suggested earlier in this thread, you created a custom column, cell and editing control then you could embed an editing control with a scrollbar when a cell gets clicked. That's what happens with all cells, for instance, a combo box cell doesn't contain a ComboBox control by default. It only contains a drawing of a ComboBox, depending on the configuration. When you start editing a cell, which may happen when you enter the cell or may take further action, a ComboBox control is created and embedded in the cell, then removed when the editing finishes.
What alternative do we have?
If only I'd answered that question in the very first reply to this thread.
 
Well that me told ! ???. But thank for your help anyways. Clearly it can be done but with a lot of work and at the moment I don't have the time to reseach all the different Drawstring methods of which there are many!. Not to mention cell boundary and rectangles together with points. It will have to be a project whenever I get more time to spend on it.
 
Back
Top