Ugly thick style border when Form.toplevel = false - c#

I have a form that will display a number of gauges that the user can resize, move around close, etc. For this I use:
Form gaugeForm = new GaugeForm();
gaugeForm.TopLevel = false;
gaugeForm.Parent = this;
gaugeForm.Show();
The problem is that the gaugeForm has a thick, ugly, old-style border. If I open the same form without modifying parent/toplevel, it looks like all the other forms, but I want it to be inside the main form.
Any pointers? This is how it looks: Ugly form
Cheers,
Jostein

Related

Open Form at certain location in MdiForm

I was thinking to create my own Menu in Mdiform, something like this:
End then I would create another Form which would open up when I click on the buttons to the left. However, I would like to open this form as maximized but without hiding menu buttons on the left from my MdiForm. Is this possible and if so, how can this be achieved?
Thank you for the input LarsTech...
Meanwhile, I have entered code to solve this:
FORM_MANAGE_PRODUCT formProduct = new FORM_MANAGE_PRODUCT();
formProduct.TopLevel = false;
formProduct.AutoScroll = true;
MAIN_PANEL.Controls.Add(formProduct);
formProduct.FormBorderStyle = FormBorderStyle.None;
formProduct.Show();

Small game menu in C# forms

I'm supposed to create a small game menu in C#. What i'm doing now is that with each button you click in the main menu, you get a new form so it's something like this.
User clicks: Play
Form playMenu = new Form();
playMenu.Show();
this.Hide();
New form including buttons appears with new options to choose from.
I feel like there is a better way to do this but i have no idea how.
Something in a way of having just 1 form instead of multiple and having buttons something like this:
User clicks: Options
playButton.visible = false;
options.Visible = true;
Doing the above makes it possible to just have 1 form but wouldn't it be difficult to make changes to the buttons?
I have no idea if this is the right way to do this.
You have to design your sub-menus as UserControls instead of Forms, put them all in a single container (Panel) with Dock = DockStyle.Fill and toggle their Visible or z-order (with BringToFront and SendToBack methods).
This gives you much flexibility in terms of visual layout and data flow.

How to make changing "screens" in c#

I'm new in C#, and I wanted to know if there was any way to show a screen with certain elements, and then with the click of a button, switch to another screen, similar to an installer.
From my experience in Java, I would just use a few JPanels and then hide only the one i want visible.
However, I'm new to C# forms and it's very different from Java swing. Anyone understand my problem and can tell me pretty much how this works? Thanks.
Simple approach
Just use a Grid with multiple Grids inside of it. Set the Visibility property of each internal Grid (except the first one you want to show) to Hidden or Collapsed, and then set them to Visible when you want to display them.
Better approach
Create a class for each section, each of which derives from the same parent class. Create a DataTemplate for the parent class, then just have instances of the template load into the original Grid through a ContentPresenter.
You can try this creating new forms. From my experience I've tried this:
Form2 formTwo = new Form2(); // creates instance
formTwo.Show(); // displays the new form
this.WindowState = FormWindowState.Minimized; // minimizes previous form
this.ShowInTaskbar = false; // hides it from taskbar
Keep in mind that this does not close the previous form. I would recommend setting ShowIntaskbar as True if you don't mind the user seeing the form minimized.
EDIT: If you want to show new elements I suggest you can try adding a new Form class to the project then using the designer.

Sizing issues while adding a .Net UserControl to a TabPage

I have a complex Windows Forms GUI program that has a lot of automated control generation and manipulation. One thing that I need to be able to do is add a custom UserControl to a newly instatiated TabPage. However, when my code does this I get automatic resizing events that cause the formatting to get ugly. Without detailing all of the different Containers that could possibly be involved, the basic issue is this:
At a certain point in the code I create a new tab page:
TabPage tempTabPage = new TabPage("A New Tab Page");
Then I set it to a certain size that I want it to maintain:
tempTabPage.Width = 1008;
tempTabPage.Height = 621;
Then I add it to a TabControl:
tabControl.TabPages.Add(tempTabPage);
Then I create a user control that I want to appear in the newly added TabPage:
CustomView customView = new CustomView("A new custom control");
Here is where the problem comes in. At this point both the tempTabPage and the customView are the same size with no padding or margin and they are the size I want them to be. I now try to add this new custom UserControl to the tab page like this:
tempTabPage.Controls.Add(customView);
When making this call the customView and it's children controls get resized to be larger and so parts of the customView are hidden.
Can anyone give me any direction on what to look for or what could be causing this kind of issue?
Thanks ahead of time.
The UserControl's "AutoScaleMode" property should be set to "None".
If you want the customView to fill the TabPage.
Use Dock like this:
tempTabPage.Controls.Add(customView);
customView.Dock = DockStyle.Fill;
Then the customView will fill out the space in the TabPage, but you have to handle resizing of the customView so child controls will be shown properly.
I had the same issue.
The UserControl's "AutoScaleMode" set to "None" works for me.

winforms panels vs java swing panels

In java swing I can insert panels into panels and so on, and not have to build a brand new window for every view of my applicaiton, or mess around removing and adding controls.
Theres a panel clas sin C# however I cant see any way of creating a 'panel form' or basically just a form in form designer thats a panel and its contents.
How do I do this then and work the way I did with java swing?
Usually i just dock different forms within eachother setting the IsMdiContainer Property to true on the parent window. Then i create subforms that i dock using the following function:
static class FormUtil
{
static public void showForm(Form sender, Control reciever)
{
sender.ControlBox = false;
sender.FormBorderStyle = FormBorderStyle.None;
sender.ShowInTaskbar = false;
sender.TopLevel = false;
sender.Visible = true;
sender.Dock = DockStyle.Fill;
reciever.Controls.Clear(); //clear panel first
reciever.Controls.Add(sender);
}
}
then whenever i need to dock a form inside a panel on the parents form i just do:
FormUtil.showForm(new SomeForm(), this.splitContainer1.Panel1);
This allows me to delegate some of the form creation to different designers. Works like a charm for me, love to hear if theres a better way of doing it.
Actually, you can use the panel control and set it's Dock property to Fill. That way, your panel will be the entire canvas of the form. Then, you can add child panels as needed either through code behind or through forms designer.
There's the concept of user controls which basicly provides you with a panel like designer surface , not to mention that you can create atomic forms (which can be reused) and register them as inheritable, that way you can provide inheritance too.

Categories

Resources