Unable to change the properties of the Month Calendar Control on my forms app.
-
Okay call me dumb!!!! dahhh.... Thansk for the suggestion. I do have one other question for you... Where do I turn on/off "Visual Styles" for the MoNthCalendar? It is not in the controls properties where else should I be looking?
Squire Dude wrote:
Okay call me dumb!!!! dahhh....
Its ok buddy... it just brought a good smile on both our faces. So fine. There are two things that you can do. 1. As mentioned above, you can extend the class. Here is a class that does the job:
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace EZ
{
public class EZMonthCalendarControl : MonthCalendar
{
[DllImportAttribute("uxtheme.dll")]
private static extern int SetWindowTheme(IntPtr hWnd, string appname, string idlist);protected override void OnHandleCreated(EventArgs e) { SetWindowTheme(this.Handle, "", ""); base.OnHandleCreated(e); } private void InitializeComponent() { this.SuspendLayout(); this.ResumeLayout(false); } }
}
2. You can disable the theme in the Main funtion in Program.cs. Just remove the line EnableVisualStyles(). But this will cause the visual style to be disabled for the whole of the application. Cheers.
-
Squire Dude wrote:
Okay call me dumb!!!! dahhh....
Its ok buddy... it just brought a good smile on both our faces. So fine. There are two things that you can do. 1. As mentioned above, you can extend the class. Here is a class that does the job:
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace EZ
{
public class EZMonthCalendarControl : MonthCalendar
{
[DllImportAttribute("uxtheme.dll")]
private static extern int SetWindowTheme(IntPtr hWnd, string appname, string idlist);protected override void OnHandleCreated(EventArgs e) { SetWindowTheme(this.Handle, "", ""); base.OnHandleCreated(e); } private void InitializeComponent() { this.SuspendLayout(); this.ResumeLayout(false); } }
}
2. You can disable the theme in the Main funtion in Program.cs. Just remove the line EnableVisualStyles(). But this will cause the visual style to be disabled for the whole of the application. Cheers.
Thanks for the ideas and suggestion and code... First I tried your second suggestion... turing off VisualStyles... and id does kind of mess things up on other forms. Then I looked at your code and it looed simple enough! I have never put a wrapper around a class before as in you first suggestion. How do I apply the code?
-
Thanks for the ideas and suggestion and code... First I tried your second suggestion... turing off VisualStyles... and id does kind of mess things up on other forms. Then I looked at your code and it looed simple enough! I have never put a wrapper around a class before as in you first suggestion. How do I apply the code?
Squire Dude wrote:
How do I apply the code?
1. Add a new class into your project, replace content with the code i provided. 2. compile the project once 3. instead of dropping the month calendar. drop this new control on your form.
-
Squire Dude wrote:
How do I apply the code?
1. Add a new class into your project, replace content with the code i provided. 2. compile the project once 3. instead of dropping the month calendar. drop this new control on your form.
Now I am feeling really dumb!!!! I got through parts 1 & 2 but how do I "Drop" the new control on the form? I tried makeing a User Control & a Class with your code replacing the generic code. I ran Build... But if I try to drag & drop the file onto the form it will not stick. What am I missing???
-
Now I am feeling really dumb!!!! I got through parts 1 & 2 but how do I "Drop" the new control on the form? I tried makeing a User Control & a Class with your code replacing the generic code. I ran Build... But if I try to drag & drop the file onto the form it will not stick. What am I missing???
google: how to use custom user controls on c# forms. this is the first link: click here
-
google: how to use custom user controls on c# forms. this is the first link: click here
Thanks for the pointer. I could not get any of the links to work but did start reading the text further down the page... I am not sure how it realates to what I was asking? Maybe I am just having very dumb day as I could not see how it related what I am trying to accomplish. But thanks anyway for your time and assistance.
-
Thanks for the pointer. I could not get any of the links to work but did start reading the text further down the page... I am not sure how it realates to what I was asking? Maybe I am just having very dumb day as I could not see how it related what I am trying to accomplish. But thanks anyway for your time and assistance.
well, since you are creating your custom control within your project, it should be available in the toolbar at the very top. Above "All Windows Controls".
-
well, since you are creating your custom control within your project, it should be available in the toolbar at the very top. Above "All Windows Controls".
Okay my bad.... I had a big case of Brain Fade yesterday now I hope that it is behind me and I can move forward today.... so far so good! I appologise for not getting it... You are correct of course the new Control is on the Left (Controls) pane and can be dragged onto a form etc. Thank you for your patience and sticking with me I really do appreaciate the effort. Thanks SquireDude
-
Okay my bad.... I had a big case of Brain Fade yesterday now I hope that it is behind me and I can move forward today.... so far so good! I appologise for not getting it... You are correct of course the new Control is on the Left (Controls) pane and can be dragged onto a form etc. Thank you for your patience and sticking with me I really do appreaciate the effort. Thanks SquireDude
:) Happens... Everyone has day like that :)
-
I have a Forms Application which I have just added the MothCalendar control too and I am ubale to change any of the properties, such as BackGroundColor, Size, etc. I have tried using the designer and in code but the interface does not change! Is there a trick to using this control? Thanks
I have just tested the MothCalendar control after seeing your question. I am able to change most of the properties (haven't checked them all) except for the Size, by normal means anyway, although BackColor and most others are OK. To overcome this size limitation I have found a work around: 1) Change the Font size. Not exactly precise but it works. MonthCalendars' size is controlled because it would look really silly with an enormous control and all the data squashed up in one corner.
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”