Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows Forms
  4. Unable to change the properties of the Month Calendar Control on my forms app.

Unable to change the properties of the Month Calendar Control on my forms app.

Scheduled Pinned Locked Moved Windows Forms
question
13 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Squire Dude
    wrote on last edited by
    #1

    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

    S H 2 Replies Last reply
    0
    • S Squire Dude

      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

      S Offline
      S Offline
      Som Shekhar
      wrote on last edited by
      #2

      Probably because there is no control called as MothCalendar ;) On serious note, MonthCalendar cannot be modified while you are using Visual Styles for the control. You need to disable the visual styles and Month Calendar will respond to your modifications. If you do not want to switch off visual styles for the complete application, extend the MonthCalendar class and then disable the visual styles for a that class. Then you can use this new control on your forms.

      S 1 Reply Last reply
      0
      • S Som Shekhar

        Probably because there is no control called as MothCalendar ;) On serious note, MonthCalendar cannot be modified while you are using Visual Styles for the control. You need to disable the visual styles and Month Calendar will respond to your modifications. If you do not want to switch off visual styles for the complete application, extend the MonthCalendar class and then disable the visual styles for a that class. Then you can use this new control on your forms.

        S Offline
        S Offline
        Squire Dude
        wrote on last edited by
        #3

        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?

        S 1 Reply Last reply
        0
        • S Squire Dude

          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?

          S Offline
          S Offline
          Som Shekhar
          wrote on last edited by
          #4

          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.

          S 1 Reply Last reply
          0
          • S Som Shekhar

            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.

            S Offline
            S Offline
            Squire Dude
            wrote on last edited by
            #5

            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?

            S 1 Reply Last reply
            0
            • S Squire Dude

              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?

              S Offline
              S Offline
              Som Shekhar
              wrote on last edited by
              #6

              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.

              S 1 Reply Last reply
              0
              • S Som Shekhar

                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.

                S Offline
                S Offline
                Squire Dude
                wrote on last edited by
                #7

                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???

                S 1 Reply Last reply
                0
                • S Squire Dude

                  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???

                  S Offline
                  S Offline
                  Som Shekhar
                  wrote on last edited by
                  #8

                  google: how to use custom user controls on c# forms. this is the first link: click here

                  S 1 Reply Last reply
                  0
                  • S Som Shekhar

                    google: how to use custom user controls on c# forms. this is the first link: click here

                    S Offline
                    S Offline
                    Squire Dude
                    wrote on last edited by
                    #9

                    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.

                    S 1 Reply Last reply
                    0
                    • S Squire Dude

                      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.

                      S Offline
                      S Offline
                      Som Shekhar
                      wrote on last edited by
                      #10

                      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".

                      S 1 Reply Last reply
                      0
                      • S Som Shekhar

                        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".

                        S Offline
                        S Offline
                        Squire Dude
                        wrote on last edited by
                        #11

                        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

                        S 1 Reply Last reply
                        0
                        • S Squire Dude

                          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

                          S Offline
                          S Offline
                          Som Shekhar
                          wrote on last edited by
                          #12

                          :) Happens... Everyone has day like that :)

                          1 Reply Last reply
                          0
                          • S Squire Dude

                            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

                            H Offline
                            H Offline
                            Henry Minute
                            wrote on last edited by
                            #13

                            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.”

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups