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. C#
  4. Web-style UI with re-flow - seen any examples?

Web-style UI with re-flow - seen any examples?

Scheduled Pinned Locked Moved C#
csharpwinformsdesigntutorialquestion
6 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.
  • M Offline
    M Offline
    Mal Ross
    wrote on last edited by
    #1

    Hi all, I'm looking to implement a web-style UI using Windows Forms and C#. I want my task screens' content to fill the width of the window and to reflow nicely, like a web browser. While I realise the docking features of Windows Forms are great for resizing content to fit a window, you run into problems when, say, the word-wrapping in a static text control changes such that the line count changes (2 lines become 3, for example). In such a situation, you'd want the controls below the static to shuffle up or down accordingly, but the docking properties aren't enough to cater for this. Has anyone seen any Forms code that avoids ugly spaces opening up (or conversely, overlapping controls) by correctly reflowing the form's content? Cheers, Mal.

    S M 3 Replies Last reply
    0
    • M Mal Ross

      Hi all, I'm looking to implement a web-style UI using Windows Forms and C#. I want my task screens' content to fill the width of the window and to reflow nicely, like a web browser. While I realise the docking features of Windows Forms are great for resizing content to fit a window, you run into problems when, say, the word-wrapping in a static text control changes such that the line count changes (2 lines become 3, for example). In such a situation, you'd want the controls below the static to shuffle up or down accordingly, but the docking properties aren't enough to cater for this. Has anyone seen any Forms code that avoids ugly spaces opening up (or conversely, overlapping controls) by correctly reflowing the form's content? Cheers, Mal.

      S Offline
      S Offline
      sreejith ss nair
      wrote on last edited by
      #2

      hi, put little R and D on Anchoring and docking. It may help you out. ************************** S r e e j i t h N a i r **************************

      M 1 Reply Last reply
      0
      • S sreejith ss nair

        hi, put little R and D on Anchoring and docking. It may help you out. ************************** S r e e j i t h N a i r **************************

        M Offline
        M Offline
        Mal Ross
        wrote on last edited by
        #3

        Thanks for the reply, but as I explained, the anchoring and docking aren't enough. Unless, that is, you're telling me to handle the Layout event and do my own layout control? But that's the example I'm hoping I can find without having to code it myself. :) Cheers, Mal.

        1 Reply Last reply
        0
        • M Mal Ross

          Hi all, I'm looking to implement a web-style UI using Windows Forms and C#. I want my task screens' content to fill the width of the window and to reflow nicely, like a web browser. While I realise the docking features of Windows Forms are great for resizing content to fit a window, you run into problems when, say, the word-wrapping in a static text control changes such that the line count changes (2 lines become 3, for example). In such a situation, you'd want the controls below the static to shuffle up or down accordingly, but the docking properties aren't enough to cater for this. Has anyone seen any Forms code that avoids ugly spaces opening up (or conversely, overlapping controls) by correctly reflowing the form's content? Cheers, Mal.

          M Offline
          M Offline
          mav northwind
          wrote on last edited by
          #4

          Although I don't know of any flow-layout panel code you could use it shouldn't be too hard to do it yourself. Derive from Panel and override the Resize event handler to calculate the size your child controls will need and then adjust their position accordingly. Regards, mav

          1 Reply Last reply
          0
          • M Mal Ross

            Hi all, I'm looking to implement a web-style UI using Windows Forms and C#. I want my task screens' content to fill the width of the window and to reflow nicely, like a web browser. While I realise the docking features of Windows Forms are great for resizing content to fit a window, you run into problems when, say, the word-wrapping in a static text control changes such that the line count changes (2 lines become 3, for example). In such a situation, you'd want the controls below the static to shuffle up or down accordingly, but the docking properties aren't enough to cater for this. Has anyone seen any Forms code that avoids ugly spaces opening up (or conversely, overlapping controls) by correctly reflowing the form's content? Cheers, Mal.

            M Offline
            M Offline
            mav northwind
            wrote on last edited by
            #5

            ReHi! Because such a flow panel could be useful for me too, I wrote a quick initial version. You can try it out if you like:

            public class FlowLayoutPanel : Panel
            {
            public FlowLayoutPanel()
            {}

            private Orientation \_orient = Orientation.Horizontal;
            \[DefaultValue(Orientation.Horizontal)\]
            public Orientation Orientation
            {
            	get { return \_orient; }
            	set
            	{
            		\_orient = value;
            		RecalcLayout();
            		Invalidate();
            	}
            }
            
            private void RecalcLayout()
            {
            	if (this.Controls.Count==0)
            	{
            		this.Size = new System.Drawing.Size(100,100);
            		return;
            	}
            
            	int x=0,y=0,h=0,w=0;
            	if (Orientation == Orientation.Horizontal)
            	{
            		// Width stays constant, height differs
            		foreach (Control c in Controls)
            		{
            			if (x+c.Width > this.Width)
            			{
            				x = 0;
            				y = h+1;
            			}
            			c.Left = x;
            			c.Top = y;
            			
            			h = Math.Max(h,c.Bottom);
            			x += c.Width;
            		}
            		this.Height = h;
            	} 
            	else
            	{
            		// Height stays constant, width differs
            		foreach (Control c in Controls)
            		{
            			if (y+c.Height > this.Height)
            			{
            				y = 0;
            				x = w+1;
            			}
            			c.Left = x;
            			c.Top = y;
            			
            			w = Math.Max(w,c.Right);
            			y += c.Height;
            		}
            		this.Width = w;
            	}
            }
            
            protected override void OnResize(EventArgs eventargs)
            {
            	RecalcLayout();
            	base.OnResize (eventargs);
            }
            
            protected override void OnControlAdded(ControlEventArgs e)
            {
            	RecalcLayout();
            	base.OnControlAdded (e);
            }
            
            protected override void OnControlRemoved(ControlEventArgs e)
            {
            	RecalcLayout();
            	base.OnControlRemoved (e);
            }
            

            }

            Regards, mav

            M 1 Reply Last reply
            0
            • M mav northwind

              ReHi! Because such a flow panel could be useful for me too, I wrote a quick initial version. You can try it out if you like:

              public class FlowLayoutPanel : Panel
              {
              public FlowLayoutPanel()
              {}

              private Orientation \_orient = Orientation.Horizontal;
              \[DefaultValue(Orientation.Horizontal)\]
              public Orientation Orientation
              {
              	get { return \_orient; }
              	set
              	{
              		\_orient = value;
              		RecalcLayout();
              		Invalidate();
              	}
              }
              
              private void RecalcLayout()
              {
              	if (this.Controls.Count==0)
              	{
              		this.Size = new System.Drawing.Size(100,100);
              		return;
              	}
              
              	int x=0,y=0,h=0,w=0;
              	if (Orientation == Orientation.Horizontal)
              	{
              		// Width stays constant, height differs
              		foreach (Control c in Controls)
              		{
              			if (x+c.Width > this.Width)
              			{
              				x = 0;
              				y = h+1;
              			}
              			c.Left = x;
              			c.Top = y;
              			
              			h = Math.Max(h,c.Bottom);
              			x += c.Width;
              		}
              		this.Height = h;
              	} 
              	else
              	{
              		// Height stays constant, width differs
              		foreach (Control c in Controls)
              		{
              			if (y+c.Height > this.Height)
              			{
              				y = 0;
              				x = w+1;
              			}
              			c.Left = x;
              			c.Top = y;
              			
              			w = Math.Max(w,c.Right);
              			y += c.Height;
              		}
              		this.Width = w;
              	}
              }
              
              protected override void OnResize(EventArgs eventargs)
              {
              	RecalcLayout();
              	base.OnResize (eventargs);
              }
              
              protected override void OnControlAdded(ControlEventArgs e)
              {
              	RecalcLayout();
              	base.OnControlAdded (e);
              }
              
              protected override void OnControlRemoved(ControlEventArgs e)
              {
              	RecalcLayout();
              	base.OnControlRemoved (e);
              }
              

              }

              Regards, mav

              M Offline
              M Offline
              Mal Ross
              wrote on last edited by
              #6

              Thanks - will check it out pronto. :) Mal.

              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