Please Help: MDI Container Form with Label on the background

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?RnJhbmsgVXJheQ==?=

    Please Help: MDI Container Form with Label on the background

    Hi all

    I have a MDI Container Form, with one label control
    on the Background of this container form.
    When I now open a child form, this form is behind
    the label ... and this looks ugly ... :-))

    When I set the label with "SendToBack ", it completely disapears.
    I also tried to set the child form like "BringToFro nt" but this also does
    not help.

    Does anybody know how to handle this problem ??

    Thanks for any comments and best regards
    Frank Uray
  • =?Utf-8?B?anAybXNmdA==?=

    #2
    RE: Please Help: MDI Container Form with Label on the background

    What are you trying to do, Frank?

    It sounds like you want a label to appear over the Child Form(s) with a
    transparent background.

    Your label is on the MDI Form? If this is your goal, try the following:
    In the Designer, select your label. In the Appearances category, set the
    BackColor to Transparent (on the Web pallet). Tada!

    "Frank Uray" wrote:
    Hi all
    >
    I have a MDI Container Form, with one label control
    on the Background of this container form.
    When I now open a child form, this form is behind
    the label ... and this looks ugly ... :-))
    >
    When I set the label with "SendToBack ", it completely disapears.
    I also tried to set the child form like "BringToFro nt" but this also does
    not help.
    >
    Does anybody know how to handle this problem ??
    >
    Thanks for any comments and best regards
    Frank Uray

    Comment

    • =?Utf-8?B?RnJhbmsgVXJheQ==?=

      #3
      RE: Please Help: MDI Container Form with Label on the background

      Hi

      Thanks for your answer.

      I am trying to do the following:

      I have a form (IsMdiContainer = true).
      On this Form I place a label, for example "Version 1.0".
      What I now want is: When I open a child form and when
      I move this over the Label, the Label should be behind this
      Child form (not visible any more).
      Now when I move the child form over the label,
      the text of this label appears to be on the child form ...

      Thanks for your help.

      Best regards
      Frank




      "jp2msft" wrote:
      What are you trying to do, Frank?
      >
      It sounds like you want a label to appear over the Child Form(s) with a
      transparent background.
      >
      Your label is on the MDI Form? If this is your goal, try the following:
      In the Designer, select your label. In the Appearances category, set the
      BackColor to Transparent (on the Web pallet). Tada!
      >
      "Frank Uray" wrote:
      >
      Hi all

      I have a MDI Container Form, with one label control
      on the Background of this container form.
      When I now open a child form, this form is behind
      the label ... and this looks ugly ... :-))

      When I set the label with "SendToBack ", it completely disapears.
      I also tried to set the child form like "BringToFro nt" but this also does
      not help.

      Does anybody know how to handle this problem ??

      Thanks for any comments and best regards
      Frank Uray

      Comment

      • Jay Riggs

        #4
        Re: Please Help: MDI Container Form with Label on the background

        On Sep 24, 12:59 pm, Frank Uray <FrankU...@disc ussions.microso ft.com>
        wrote:
        Hi
        >
        Thanks for your answer.
        >
        I am trying to do the following:
        >
        I have a form (IsMdiContainer = true).
        On this Form I place a label, for example "Version 1.0".
        What I now want is: When I open a child form and when
        I move this over the Label, the Label should be behind this
        Child form (not visible any more).
        Now when I move the child form over the label,
        the text of this label appears to be on the child form ...
        >
        Thanks for your help.
        >
        Best regards
        Frank
        >
        >
        >
        "jp2msft" wrote:
        What are you trying to do, Frank?
        >
        It sounds like you want a label to appear over the Child Form(s) with a
        transparent background.
        >
        Your label is on the MDI Form? If this is your goal, try the following:
        In the Designer, select your label. In the Appearances category, set the
        BackColor to Transparent (on the Web pallet). Tada!
        >
        "Frank Uray" wrote:
        >
        Hi all
        >
        I have a MDI Container Form, with one label control
        on the Background of this container form.
        When I now open a child form, this form is behind
        the label ... and this looks ugly ... :-))
        >
        When I set the label with "SendToBack ", it completely disapears.
        I also tried to set the child form like "BringToFro nt" but this also does
        not help.
        >
        Does anybody know how to handle this problem ??
        >
        Thanks for any comments and best regards
        Frank Uray- Hide quoted text -
        >
        - Show quoted text -

        Frank,

        My first impulse was to suggest that if your goal was to make the mdi
        parent's Label contents visible regardless of the location of child
        windows, perhaps you can put the Label's contents on a StatusStrip on
        the parent form.

        I also thought about what you'd have to do to get your idea (as I
        understand it) to work. You'd basically have to perform some hit
        testing to determine if a child form is over the Label on the mdi
        parent. If so, you'd set the Visible property on your parent form
        Label to false, and you'd set a similar Label on the child to true.

        I tried a quick experiment and it appeared to work. What I did was
        create a child form with an event that contains the form's location
        and size in its parameters. This event fires on the form's
        LocationChanged and ResizeEnd events. The mdi parent subscribes to
        these events and each time they are raised, the parent sees if the
        moved child form overlaps the parent's label. If so parent's Label's
        Visible property is set to false and the child form's Label is set to
        true, through a method on the child form.


        Here's what I did:
        1. Create a new project and create a mdi parent form.
        2. Add a Label to this form. I called mine label1.
        3. Add a child form to your project and add a label to it. I called
        this form Child.cs and the Label label1.


        4. On the Child form, I added this code:

        internal delegate void MdiChildMovedHa ndler(object sender, Point
        location, Size size);
        internal event MdiChildMovedHa ndler MdiChildMoved;

        private void Child_LocationC hanged(object sender, EventArgs e) {
        if (MdiChildMoved != null) {
        MdiChildMoved(t his, this.Location, this.Size);
        }
        }

        internal void SetLabelVisible (bool setting) {
        label1.Visible = setting;
        }

        private void Child_ResizeEnd (object sender, EventArgs e) {
        if (MdiChildMoved != null) {
        MdiChildMoved(t his, this.Location, this.Size);
        }
        }



        5. Add the following code to the parent form:

        private void MdiChildMoved(o bject sender, Point location, Size size) {
        //Console.WriteLi ne("ID: {4} -- x:{0}, y:{1}, w:{2}, h:{3}",
        location.X, location.Y, size.Width, size.Height,
        ((Child)sender) .Name);
        Rectangle formRectangle = new Rectangle(locat ion, size);
        Rectangle labelRectangle = new Rectangle(label 1.Location,
        label1.Size);
        label1.Visible = !LabelInsideChi ld(formRectangl e, labelRectangle) ;
        ((Child)sender) .SetLabelVisibl e(LabelInsideCh ild(formRectang le,
        labelRectangle) );
        }

        // Return true if the label rectangle is completely contained in the
        child form's rectangle.
        private bool LabelInsideChil d(Rectangle labelRectangle, Rectangle
        childFormRectan gle) {
        Point formTopLeftPoin t = new Point(childForm Rectangle.Left,
        childFormRectan gle.Top);
        Point formTopRightPoi nt = new Point(childForm Rectangle.Left +
        childFormRectan gle.Width, childFormRectan gle.Top);
        Point formBottomLeftP oint = new Point(childForm Rectangle.Left,
        childFormRectan gle.Top + childFormRectan gle.Height);
        Point formBottomRight Point = new Point(childForm Rectangle.Left +
        childFormRectan gle.Width, childFormRectan gle.Top +
        childFormRectan gle.Height);

        // Check Top Left, Top Right, Bottom Left, Bottom Right.
        Console.WriteLi ne(" TL: {0} [x:{1},y:{2}]",
        PointInsideRect angle(labelRect angle, formTopLeftPoin t),
        childFormRectan gle.Top, childFormRectan gle.Left);
        Console.WriteLi ne(" TR: {0} [x:{1},y:{2}]",
        PointInsideRect angle(labelRect angle, formTopRightPoi nt),
        childFormRectan gle.Top, childFormRectan gle.Left +
        childFormRectan gle.Width);
        Console.WriteLi ne(" BL: {0} [x:{1},y:{2}]",
        PointInsideRect angle(labelRect angle, formBottomLeftP oint),
        childFormRectan gle.Top + childFormRectan gle.Height,
        childFormRectan gle.Left);
        Console.WriteLi ne(" BR: {0} [x:{1},y:{2}]",
        PointInsideRect angle(labelRect angle, formBottomRight Point),
        childFormRectan gle.Top + childFormRectan gle.Height,
        childFormRectan gle.Left + childFormRectan gle.Width);
        Console.WriteLi ne("=========== ===========");


        return PointInsideRect angle(labelRect angle, formTopLeftPoin t)
        && PointInsideRect angle(labelRect angle, formTopRightPoi nt)
        && PointInsideRect angle(labelRect angle, formBottomLeftP oint)
        && PointInsideRect angle(labelRect angle,
        formBottomRight Point);
        }

        // Return true if the Point is inside the Rectangle.
        private bool PointInsideRect angle(Rectangle r, Point p) {
        return (r.X < p.X) && (p.X < (r.X + r.Width)) && (r.Y < p.Y) && (p.Y
        < (r.Y + r.Height));
        }

        Your child forms would subscribe to the MdiChildMoved event




        Give this a try. It worked for me but you'll want to test and refine
        things a bit. I tried to format my code so it wouldn't be too
        difficult for you to copy and paste it. If you want I can email you
        the project file (VS 2005).



        -Jay

        Comment

        • =?Utf-8?B?RnJhbmsgVXJheQ==?=

          #5
          Re: Please Help: MDI Container Form with Label on the background

          Hi Jay

          Thanks a lot for your answer !!

          I am not sure if you mean the same as I ...

          Try to do the following:
          - Create a new C# Application Solution.
          - Set the Form1 as MdiContainer = true
          - Place a Label in the middle of Form1
          - In the Load Event of Form1 place the following code:
          this.IsMdiConta iner = true;
          System.Windows. Forms.Form local_Form = new System.Windows. Forms.Form();
          local_Form.MdiP arent = this;
          local_Form.Show ();

          When you now move the child form over the Label,
          the Label appears on the child form ...
          This is what I dont want. The Label should be always
          behind every child form.

          Thanks for your help on this !

          Best regards
          Frank

          Comment

          • =?Utf-8?B?anAybXNmdA==?=

            #6
            Re: Please Help: MDI Container Form with Label on the background

            Jay's response would probably handle what you need, but the way I see it -
            I'm sure it would be choppy (I did not actually build the project, though).

            If I follow Jay's logic correctly, if the child form's edges creap into the
            space of the MDI form's label, the label is hidden.

            I'm not sure, though, if Jay's version would handle the case of a form being
            created or being maximized to cover the label.

            I'm still following this post, but it is likely that this is not something
            that can be naturally done.

            Here's an interesting theory: Since an MDI form is essentially a container
            for other forms, it may be forms created in the MDI parent are being treated
            as if they are being displayed behind a glass wall (uh... Windows) so when
            labels are dropped on the MDI form, they are being placed on top of the plate
            glass. I don't know if that is the case, though. I don't know *how* software
            development tools go about creating an MDI application.

            "Frank Uray" wrote:
            Hi Jay
            >
            Thanks a lot for your answer !!
            >
            I am not sure if you mean the same as I ...
            >
            Try to do the following:
            - Create a new C# Application Solution.
            - Set the Form1 as MdiContainer = true
            - Place a Label in the middle of Form1
            - In the Load Event of Form1 place the following code:
            this.IsMdiConta iner = true;
            System.Windows. Forms.Form local_Form = new System.Windows. Forms.Form();
            local_Form.MdiP arent = this;
            local_Form.Show ();
            >
            When you now move the child form over the Label,
            the Label appears on the child form ...
            This is what I dont want. The Label should be always
            behind every child form.
            >
            Thanks for your help on this !
            >
            Best regards
            Frank
            >

            Comment

            • Jay Riggs

              #7
              Re: Please Help: MDI Container Form with Label on the background

              On Sep 25, 1:50 am, Frank Uray <FrankU...@disc ussions.microso ft.com>
              wrote:
              Hi Jay
              >
              Thanks a lot for your answer !!
              >
              I am not sure if you mean the same as I ...
              >
              Try to do the following:
              - Create a new C# Application Solution.
              - Set the Form1 as MdiContainer = true
              - Place a Label in the middle of Form1
              - In the Load Event of Form1 place the following code:
                 this.IsMdiConta iner = true;
                 System.Windows. Forms.Form local_Form = new System.Windows. Forms.Form();
                 local_Form.MdiP arent = this;
                 local_Form.Show ();
              >
              When you now move the child form over the Label,
              the Label appears on the child form ...
              This is what I dont want. The Label should be always
              behind every child form.
              >
              Thanks for your help on this !
              >
              Best regards
              Frank


              Hi Frank,

              Sorry, I misunderstood some of what you want. As jp2msft said, what I
              wrote would probably handle what you needed but it could be improved
              upon.

              To just display a string on a mdi background you can override the mdi
              parent's OnPaint event and 'manually' draw a string (what you want in
              the Label) on the background using the DrawString method. I did this
              on a .net 1.1 application and it worked great. Unfortunately I don't
              have the source here at work and I couldn't find any decent links in a
              quick Google search I did.

              I can post some details later at about 9 pm PST.

              -Jay

              Comment

              • Family Tree Mike

                #8
                Re: Please Help: MDI Container Form with Label on the background

                Have you considered creating an image with the text you want, and
                regenerating the image if the label text needs altering? You then would use
                this image as the MDI container background. I've put images back there but
                never a control.



                "Frank Uray" <FrankUray@disc ussions.microso ft.comwrote in message
                news:C16E564E-862C-4385-9CF4-3D7EC6862A12@mi crosoft.com...
                Hi all
                >
                I have a MDI Container Form, with one label control
                on the Background of this container form.
                When I now open a child form, this form is behind
                the label ... and this looks ugly ... :-))
                >
                When I set the label with "SendToBack ", it completely disapears.
                I also tried to set the child form like "BringToFro nt" but this also does
                not help.
                >
                Does anybody know how to handle this problem ??
                >
                Thanks for any comments and best regards
                Frank Uray

                Comment

                • Jay Riggs

                  #9
                  Re: Please Help: MDI Container Form with Label on the background

                  On Sep 25, 1:50 am, Frank Uray <FrankU...@disc ussions.microso ft.com>
                  wrote:
                  Hi Jay
                  >
                  Thanks a lot for your answer !!
                  >
                  I am not sure if you mean the same as I ...
                  >
                  Try to do the following:
                  - Create a new C# Application Solution.
                  - Set the Form1 as MdiContainer = true
                  - Place a Label in the middle of Form1
                  - In the Load Event of Form1 place the following code:
                     this.IsMdiConta iner = true;
                     System.Windows. Forms.Form local_Form = new System.Windows. Forms.Form();
                     local_Form.MdiP arent = this;
                     local_Form.Show ();
                  >
                  When you now move the child form over the Label,
                  the Label appears on the child form ...
                  This is what I dont want. The Label should be always
                  behind every child form.
                  >
                  Thanks for your help on this !
                  >
                  Best regards
                  Frank

                  Frank,

                  OK, I looked over my project where I succesfully write text to a mdi
                  parent's background and the way I 'drew' this text is to create an in-
                  memory bitmap that includes the text and then use this bitmap as the
                  parent's background image. Any mdi client forms will hide the text on
                  the mdi parent's background.

                  I created a minimal functioning solution in C# 2.0 that demonstrates
                  this but I noticed that when I resize the mdi parent, the background
                  flickers a bit. It doesn't do this on my 1.1 project. I'm not sure
                  why this is but I think you'll find the project useful.

                  Here's how I did it.

                  1. Create a new project. On Form1 set the IsMdiContainer property to
                  true.


                  2. Add the following field to the form's code:

                  private MdiClient _mdiClient;


                  3. Create a Load event for the form, and add this code:

                  private void Form1_Load(obje ct sender, EventArgs e) {
                  foreach (Control c in this.Controls) {
                  _mdiClient = c as MdiClient;
                  if (_mdiClient != null) {
                  break;
                  }
                  }
                  _mdiClient.Resi ze += new EventHandler(md iClient_Resize) ;
                  }


                  4. Add the following event to the form:

                  private void mdiClient_Resiz e(object sender, System.EventArg s e) {
                  Bitmap bufferImage;
                  Rectangle r = new Rectangle(Point .Empty, _mdiClient.Size );

                  if (r.Height <= 0 || r.Width <= 0) {
                  return;
                  }

                  bufferImage = new Bitmap(r.Width, r.Height);
                  Graphics g = Graphics.FromIm age(bufferImage );

                  StringFormat sf = new StringFormat(St ringFormatFlags .NoWrap);

                  string text = "Press F12 to log in";
                  sf.LineAlignmen t = StringAlignment .Center;
                  SolidBrush brush = new SolidBrush(Syst emColors.Contro lDarkDark);
                  g.FillRectangle (brush, r);
                  brush.Dispose() ;

                  Font font = new Font("Arial Rounded MT Bold", 36,
                  FontStyle.Regul ar, GraphicsUnit.Pi xel);
                  sf.Alignment = StringAlignment .Center;
                  sf.Trimming = StringTrimming. EllipsisWord;
                  g.DrawString(te xt, font, Brushes.Yellow, (RectangleF)r, sf);

                  font.Dispose();
                  sf.Dispose();
                  g.Dispose();

                  _mdiClient.Back groundImage = bufferImage;
                  }

                  That should do it!

                  The way it works is pretty simple: When the form loads it finds a
                  reference to the MdiClient control and it adds a Resize event. The
                  Resize event creates the background image I talked about, adds,
                  formats and positions text on this image and then sets this image to
                  the MdiClient control's BackgroundImage property.

                  Let me know if this works for you. If you can correct the flickering,
                  let me know.

                  -Jay


                  Comment

                  • Mick Doherty

                    #10
                    Re: Please Help: MDI Container Form with Label on the background

                    Any Controls placed on the MDIClient will always show on top of any MDI
                    Child Forms.
                    Draw to the MDIClient rather than placing a Control onto it.

                    You'll find an example on my Form Tips page:


                    --
                    Mick Doherty



                    Comment

                    Working...