I'm a little bit frustrated with forms and feel like there have to be some features that I do not know yet (I'm still new to this). Currently I want to toggle two panels on button click, and have one panel move out on the left while the other moves in on the right. I can get it working somehow, but I'm losing so much time because I can only work on the panel that I see and have to keep dragging the panel that is out of the main form into the main form in order to see it and work on it.
Is there a way to also draw elements that are technically out of the draw range?
The panels should have transparent background and the main form background should not move , so moving in another form does not look like a viable option.
Related
let's say I want to make program settings menu like:
Many tab options that change the layout of the rest of the window
My program is in C# and I'm making it in Visual Studio
I tried to do it 2 ways:
Make the window super large with all possible layouts in the Form designer and then just resizing it to fit one of them at the time but this method works for like 4 tabs when you can fit them all at 1 screen. If it's large you have to work with slide bars and that's really impractical, laggy and for many tabs you even have to search them
Not using Form designer at all and hand write all the declarations, positions, sizes, colors etc. But like this it takes pretty a while even just to set up 1 button and there is no way I can fast see how it looks like
So the question is: Is there a magic way I don't know about to do this? And how is this made professionally?
Simple solution for small number of views
You can use a TextBox and ListView docked in a Panel docked left.
And a ControlTab docked fill in a panel named for example PanelMain docked fill at right with visible at false.
You will create any tabpage as option. In each tabpage you will put a panel docked fill and dedicated content in. On the listview item click event or itemchange, you will set the tabpage panel parent to PanelMain.
The little problem can be about spacing and the code file can be large (regions can be used).
Advanced solution more clean for several views
You can use the standard multipage pattern with one form per option/view, and do the same thing as exposed previously.
You create one form per view and put a panel docked fill embedding controls.
When the user click on the menu, you set the form main panel parent to the option form or the main panel of the options form.
I hope I haven't written too badly in unverified English.
Feel free to open any new question centered on any atomic and code problem on this subject.
So I am working on a program that has several screens which causes it to have overlapping controls (Buttons and lists).
I put the controls in panels which works great and then do show/hide for the panels.
This also works well.
I am having a problem now that I am up to several panels where when I move one panel up it gets absorbed by another and I need them to stay separate.
Example: When I move panel2 into place over panel1, panel2 becomes part of panel1. Then when I do panel1.Hide() and panel2.Show(), panel2 is still hidden because it is part of panel1. is there a way for me to ungroup these or move panel2 into place without it automatically becoming part of panel1? (I know I can show hide the controls inside of the panels, but this will add a lot of complexity because I have a ton of controls)
Perhaps there is a better solution than using panels?
You can use the View + Other Windows + Document Outline tool window to get these panels separated again. Drag the inner panel back to the parent. You'll then also have to edit the Location property to get it back in the right position.
This is annoying of course and good odds that you'll have to do this repeatedly. There's a better way to go about it, a TabControl has good design-time support and also has the same "overlapping panel" metaphor. You just need to hide the tabs at runtime. That's pretty easy to do, check the StackPanel control in this answer.
If you imagine a win form with a line drawn vertically down the middle. On the left i have a graph, and when you click the graph certain forms open on the right in an mdi type panel.
I am trying to figure out how to logically get this to look like a proper application should but am failing!
The whole form loads in a maximised view. I first set the panel width to 0 then when i add a form i check if the panels width is less than the forms, if it is then change the panels width to that of the forms.
This doesn't look great tho tbh, resizing makes strange things happen and i see a lot of grey. Does anyone have any ideas?
Use a SplitContainer on your main form. Ensure it's Dock property is set to Fill
Put your graph stuff on the left panel, and your other stuff on the right side.
I'm making a bomberman game in a C# windows form application. It has over 300 pictureboxes (walls) that are placed on a panel. The picturebox of bomberman himself is also on that panel.
When the location of bombermans picturebox changes, all the controls on the panel are automatically refreshed. Because there are so many controls on that panel, and because the location of the picturebox changes multiple times per second, the program becomes laggy when I try to move.
I want to have control over the refresh event of the panel (and it's controls), because I think my problem is solved when only the pictureboxes that need to be refreshed, are refreshed programmatically.
I hope someone can help me out with this!
Ruud.
If you move the child, the parent has to be refreshed because it may need to draw the area where child was located previously. It would also mean that all children (of parent) would get refreshed.
OTH, using so many controls may not be a good idea. I would suggest you to keep data structures describing walls and then use it to draw it within Panel (or your custom control). You can write your own logic for hit testing (mouse or keyboard click within wall boundary) by capturing mouse/keyboard events at Panel/Parent level. With correct organization data structure, hit testing can be very efficient.
You are trying to paint the whole form which will surely take time . If you want to change only a part of the form, which in your case is Moving the bomberman to a new position, Only invalidate the area you want to repaint and then pass it to the Invalidate method.
Do something similar to this.
//Invalidate previous position of bomberman
Rectangle invalid = new Rectangle(picturebox1.Location.x,picturebox1.Location.y,picturebox1.Width,picturebox1.Height);
Invalidate(invalid);
//Add code to move your picture box and then call above two lines again
invalid = new Rectangle(picturebox1.Location.x,picturebox1.Location.y,picturebox1.Width,picturebox1.Height);
Invalidate(invalid);
Note sure but somthing similar polished code would work...
Here is a link to an example for reference. http://msdn.microsoft.com/en-us/library/ms229628.aspx
I am creating a GUI with C#. I intended to use a ListView to see preview of pictures, and a PictureBox to display the full view. I used a Panel as parent and placed a PictureBox inside of that to have scrollbars appear on the picture box.
What I still can't figure out how to do is to provide close, maximize, and minimize, buttons on the Panel, as seen in many GUI applications.
How can I do this? Any ideas will be appreciated.
Those other GUI applications probably use a Form instead of a Panel/PictureBox, assuming that they provide maximize, minimize, and close buttons.
You could add your own buttons to the Panel control, and then write code in their Click event handlers to do whatever you want with the control. This is easy and relatively straight-forward if you just want to be able to close the picture, but it seems like unnecessary work to duplicate all of the functions that are built right into a Form.
I'd ditch the Panel control, add a new Form to my project, place the existing PictureBox control onto the form that I just added, and go from there. You might want to set the form's FormBorderStyle property to something like "SizableToolWindow", depending on how you want it to look.