# [.net] C# - putting forms on a panel

This topic is 4734 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm writing this C# app where I am trying to put multiple forms on a panel but at certain times I can't seem to move the forms around until I move the entire app. What I have is a panel where the docking style is Fill, so the panel always changes size if the app is re-sized. I also have the auto scroll field set to true. Now I have this second panel that is kinda big (5Kx5K) added to the control list of the first panel. This big panel is the one I add the forms to. So basically I have a panel in a panel. Now I have added this little form to the big panel and when the program starts I can move it around and such, no problem. But when I use the scroll bars (spawned from the first panel) so that the little form in the big panel is partly clipped away I then can not move the little form around. It's basically stuck. The only way I can move it around again is if I move the whole program around. Any one know why this could be happening? What I'm doing is creating a visual material editor tool like the one used with Unreal Engine 3. It's for my own engine, as I don't like writing the material files out by hand. :) Plus this kind of program is interesting to me so I want to make my own. I'm only so-so with GUI programming so I'm not sure what's wrong. If I could figure this out, then everything else won't be a problem. Here is some code (from a test app, not my main material editor) where I set up the panels and test form:
m_mainPanel   = new Panel();
m_canvasPanel = new Panel();

m_mainPanel.AutoScroll  = true;
m_mainPanel.BackColor   = System.Drawing.Color.MidnightBlue;
m_mainPanel.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
m_mainPanel.Location    = new System.Drawing.Point(5, 30);
m_mainPanel.Name        = "canvas holder";
m_mainPanel.Dock        = DockStyle.Fill;

m_canvasPanel.BackColor = System.Drawing.Color.Gainsboro;
m_canvasPanel.Location  = new System.Drawing.Point( 5, 5 );
m_canvasPanel.Name      = "canvas";
m_canvasPanel.Size      = new System.Drawing.Size( 5000, 5000 );

Form temp = new Form();

temp.BackColor = System.Drawing.Color.Navy;
temp.ClientSize = new System.Drawing.Size( 150, 150 );
temp.Location = new System.Drawing.Point( 10, 10 );
temp.Name  = "temp";
temp.Text  = "temp";
temp.Paint += new PaintEventHandler(temp_Paint);
temp.TopLevel = false;		// Required to add to the panel list of controls
temp.MinimizeBox = false;
temp.MaximizeBox = false;
temp.FormBorderStyle = FormBorderStyle.FixedToolWindow;

temp.ResumeLayout( false );
temp.Show();


I'd really appreciated it if someone could help me with this. I don't do GUI stuff much so it's prolly something easy. EDIT: I just noticed that the form doesn't HAVE to be clipped for it to stick. Just moving the scroll bars a little does it too. -SirKnight

##### Share on other sites
Update:

It seems that the position of the little form doesn't change when the scroll bars move around, yet the form graphic does move so it LOOKS like the form's coords changed with the panel but they really didn't. When the form "sticks", it can still be moved around if click-and-dragged where the form's title bar was before the scroll. But shaking the whole app (or anything that causes a WM_PAINT) fixes the "stickyness."

I just wonder if I should be sending update info to the little form so it scrolls correctly with the panel somehow or if I should force a WM_PAINT message after scrolling. I'm just not sure why the form corrects itself only when the whole app needs to be repainted.

-SirKnight

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 15
• 13
• 9
• 12
• 10
• ### Forum Statistics

• Total Topics
631442
• Total Posts
3000089
×