CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2011
    Posts
    9

    [Problem] MonthCalendar .NET

    I'm working with Windows 7 on my project. I've added MonthCalender to the project and some other controls.
    I've designed it as I wanted and then moved to my other computer which has Windows XP on it.
    MonthCalendar style changed, its size became smaller and actually the whole design has gone.
    Is there anyway to design a windows form (that will look quite good and comfortable) that won't change its style and size in other Windows platforms?

  2. #2
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: [Problem] MonthCalendar .NET

    I have a small app using the MonthCalendar control myself that I both enhance gradually and use in my daily routine. I have developed it under XP and am using it on the same system (and I don't have anything else to test here anyway). But I have distributed the app to some friends who use Vista as well as 7 for use and beta testing, and never heard any complaints from them about the look of the program. (I haven't actually seen it myself on their system yet though.)

    As a reference, I have attached a screen shot of my app under XP (unsing the classic Win95 style). Can you attach screen shots of your app both under 7 and XP to your next post? Maybe this already gives some hints.

    I also have just e-mailed my friends and asked them for screen shots of the calendar app on their systems.

    Maybe we can approach the problem step by step.

    ... or maybe someone who simply knows comes along and simply tells us...
    Attached Images Attached Images  
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  3. #3
    Join Date
    Feb 2011
    Posts
    9

    Re: [Problem] MonthCalendar .NET

    Thank you very much!

    I'll upload screenshots soon!

  4. #4
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: [Problem] MonthCalendar .NET

    Quote Originally Posted by benben12 View Post
    I'll upload screenshots soon!
    Well, you still didn't upload them and it's now three weeks since you posted that, so perhaps you have solved your problem in the meantime. I do this post despite that fact because it may be interesting to other readers - and because I now have a question related to this topic myself...

    Actually, my calendar program did not work under Windows 7 because the default dimensions of the calendar control are bigger there (and under Vista). I fixed that by adjusting the form's size programmatically, according to the calendar control dimensions determined at runtime in the form's Load event handler (also see the attached "before" and "after" screen shots):

    Code:
    System::Void Form1::Form1_Load(System::Object^  sender, System::EventArgs^  e)
    {
      Object ^objTemp = config["windowLocation"];
      if (objTemp) {
        Point pnt = *dynamic_cast<Point ^>(objTemp);
        if (pnt != Point(-1, -1)) Location = pnt;
      }
    #ifdef _DEBUG
      Debug::WriteLine("-----");
      Debug::WriteLine("Main form Size during Load event: {0}", Size);
      Debug::WriteLine("Main form control sizes during Load event:");
      for each (Control ^ctl in Controls)
        Debug::WriteLine("{0}: Bounds = {1}, Margin = {2}", ctl->Name, ctl->Bounds, ctl->Margin);
      Debug::WriteLine("-----");
    #endif
      ClientSize = Drawing::Size(monthCalendar1->Location + monthCalendar1->Size + monthCalendar1->Margin.Size);
    }
    Actually, the form size adjustment is entirely done in the last line of the function body, but I've posted the entire function to show the debugging code that is related to the question I have.

    The form size calculated by this expression under XP actually is only off by one pixel in x direction and two pixels in y direction from the hand-tuned version of the form depicted in post #2. Nothing that is visible to the naked eye...

    And now the question that arose for me: Simply setting the form's AutoSize property to true did not do the trick; it made the form 12 pixels too wide. Why? This is the output I got from the debug code under XP with AutoSize == false:

    Code:
    -----
    Main form Size during Load event: {Width=179, Height=246}
    Main form control sizes during Load event:
    toolStrip1: Bounds = {X=0,Y=24,Width=173,Height=34}, Margin = {Left=0,Top=0,Right=0,Bottom=0}
    monthCalendar1: Bounds = {X=5,Y=60,Width=163,Height=155}, Margin = {Left=2,Top=2,Right=2,Bottom=2}
    menuStrip1: Bounds = {X=0,Y=0,Width=173,Height=24}, Margin = {Left=0,Top=0,Right=0,Bottom=0}
    -----
    So what is pushing the right edge of the form that far? I don't see anything there that is wider than the initial form dimensions.

    BTW, it didn't take me that long to fix the problem, just to get the screen shots of the calendar program under 7 (which I don't have).
    Attached Images Attached Images   
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  5. #5
    Join Date
    Jul 2002
    Posts
    2,543

    Re: [Problem] MonthCalendar .NET

    The best way is to allow a whole form and every control to look in a native way for every OS and every selected scheme. Windows Forms have dynamic layout features (see, for example, TableLayoutPanel and FlowLayoutPanel classes). It is a good idea to design all forms using dynamic layout controls, such application behaves well in every client environment.

  6. #6
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: [Problem] MonthCalendar .NET

    Thanks for pointing me to the dynamic layout features. I actually already planned to usem them later in other apps, mainly to aid in supporting localization. (This is very unlikely to happen to the calendar in the foreseeable future though, because it only supports German holidays anyway and I don't plan to extend this.) Not being able to safely make assumptions about the size of the calendar control was a new experience, however, and I didn't consider schemes to be able to influence the layout as well, though now it looks perfectly logical to me.

    Aside from the (non-)localization I didn't yet see anything I could gain from dynamic layout in the calendar's main form. The menu and tool bar are both anchored top, left and their AutoSize and Stretch properties are both set to true for the menu and false for the tool bar. These are the defaults except for the tool bar's AutoSize which I, IIRC, changed because it otherwise insisted in being a bit too high for my personal taste. (There are probably more elegant ways to achieve this using margin and padding properties but: Never touch a running system... ) The rest of the form is only occupied by the calendar control and I thought there was no point in dynamically layouting a single control (except for adjusting the dimensions of the entire form as I do now). Or am I mistaken here?

    Do you have any idea what might be messing up the form's auto size behaviour here?
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured