Making a normal form as MDI - vb.net

I am working on a application in which I have to show different forms stacked one upon the other. Due to some restrictions, I cannot use MDI and also it has a lot of issues.
I am able to get what I want but with a problem. The forms will be stacked, but they do not remain in the parent form.
Lets take it by an example. The structure goes like this.
1) There is a form A (My parent form)
2) a second form "B" opens on a button click event on Form "A". (Note: B.ShowInTaskBar=False)
3) again, a third form "C" opens on a button click event on Form "B". (Note: C.ShowInTaskBar=False)
Now, when I minimize form A, it gets minimized but the Form B and C, remains as it is. I want them to get minimized at the same time. I want form B and C should remain as a child form of form A.
How to get that.

Just use MDI forms. There is no technical restriction about FormBorderStyle's value for MDI children. Remember to set the IsMdiContainer property to true for the parent form and then set the child form's MdiParent property to the parent form before Show() is called.
Edit:
I'm not exactly sure what you mean by stacking. You can easily control the child positions if that is what you mean:
public void ShowChildren()
{
Child child1 = new Child();
Child child2 = new Child();
child1.MdiParent = this;
child2.MdiParent = this;
child1.Show();
child2.Show();
child1.Size = new System.Drawing.Size(100, 100);
child1.Location = new System.Drawing.Point(0, 0);
child2.Size = new System.Drawing.Size(100, 100);
child2.Location = new System.Drawing.Point(0, 100);
}
Edit #2:
Are you trying to nest the forms? If so you can make the parent a normal form and place a UserControl A in the parent. Then place UserControl B in UserControl A. Allowing the user to move these around becomes more difficult, but if you already wanted no border this may not be an issue for you.

public void formMain_buttonShowA_click() {
FormA formA = new FormA();
formA.ShowDialog();
}
public void formA_buttonShowB_click() {
FormB formB = new FormB();
formB.ShowDialog();
}

Related

VB.net - Making a translucent form (with fully visible controls) [duplicate]

I have a form that i set it's Opacity as 50% like this:
this.Opacity = 0.5D; <--this==Form
My problem is that everything that on the form is with an Opacity of 50%
I have two buttons on the form and I want them without Opacity.
I know that this.Opacity included all Controls and for some reason the graphics too
My question is, How to Exclude the Opacity of the controls?
Example Image:
Thanks!
Since Control doesn't have Opacity property and plus that, most of the controls doesn't support transparent colors, then a working solution can be this:
Create a Form called MainForm and place all the controls you're going to be excluded.
1.1 Set both of BackColor and TransparencyKey properties of MainForm to the same color, e.g Color.Red
Create another form named TransparentForm and place all controls that must become transparent. Set ShowInTaskbar property to False.
In the MainForm Load event show the TransparentForm and send it to back.
private void MainForm_Load(object sender, EventArgs e)
{
TransparentForm form = new TransparentForm();
form.Opacity = 0.5D;
form.Show();
form.SendToBack();
}
The position of controls in both form must be such that, when combined, it shows the proper user interface.
Crate a C# project and add 3 forms named
MAIN
BACKGOUND
Child
and add the following code for "MAIN" form load event;
private void MAIN_Load(object sender, EventArgs e)
{
Child frm1 = new Child();
BACKGOUND frm2 = new BACKGOUND();
frm2 .WindowState = System.Windows.Forms.FormWindowState.Maximized;
frm2.Opacity = 0.5;
frm2.Show();
frm1.ShowDialog();
frm2.Close();
}

Connecting 2 Forms together [duplicate]

How to make the child form follow main form.
for example: open a winform [.net2], winform opens form, form follows the mainform if mainform is moving.
Use the LocationChanged event from the MainForm to always set the location of the ChildForm.
Working example:
Form childForm = new Form();
protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
childForm.StartPosition = FormStartPosition.Manual;
childForm.Width = this.Width;
childForm.Height = 96;
childForm.Location = new Point(this.Left, this.Bottom);
childForm.Show();
}
protected override void OnLocationChanged(EventArgs e) {
base.OnLocationChanged(e);
if (childForm != null) {
childForm.Location = new Point(this.Left, this.Bottom);
}
}
Superficially simple answer is just to add handlers for when Mainform is moved or resized and then set childform Location and size accordingly.
However do you say want to stop main form being moved such that childform end up off screen.
Can child form be moved independantly.
What about minimise and maximise?
Might you want other arrangements, nore than one child, left and right, child form above main form...
Be worth writing a layout class, and shoving all this stuff off to it.

How do I disable opening multiple MDI Child in VB2010

I am trying to create a menu driven application using MDI forms. My problem is that the menu in the MDI parent will create a new child every time i clicked on it. How do i allow only one particular instance of the child to be open for a particular form but allow multiple forms from different menu to be open. For example, I would want a child from "File" to be open along with an "Edit" child. Also, is there a way to close all other forms whenever a new form is open?
You can do all of that my checking the MdiChildren array of your main form. That array will list all of the open MDI children on your form.
You can determine if an instance of a form is open by looping through the array and checking if a form of the type requested is already open.
To close all open forms, just loop through MdiChildren and call Close on all of the forms.
You can check for an existing instance of your form through the MDIChildren collection:
private void form2ToolStripMenuItem_Click(object sender, EventArgs e) {
Form2 f = this.MdiChildren.OfType<Form2>().SingleOrDefault();
if (f == null) {
f = new Form2();
f.MdiParent = this;
f.Show();
} else {
f.BringToFront();
}
}
If you want to close any previous open form, you can also just go through the MDIChildren collection:
if (f == null) {
while (this.MdiChildren.Count() > 0) {
this.MdiChildren[0].Dispose();
}
// etc...

VB.NET never get focus on any control

i have developed a simple calculator like in windows calculator,
but unlike in windows calculator, after clicking any button, the focus on that button is still there on the particular clicked button.
so how to never get focus for all buttons on calculator form ... ?
i don't think that it will better to write loose focus code on every button's click event ... so any better solution ?
Without seeing any code of yours, I am going to assume that you have a text box that displays the numbers pressed by the user, so you need to set the focus to the text box once a user clicks a button, like this:
TextBox1.Focus()
Note: If your text box is not named TextBox1, then change the name to whatever your text box is actually named.
Instead of a standard button use an instance of a NoFocusButton class derived from the Standard button. In this class override the ShowFocusCues property and return always false.
Form f = new Form();
// Need to add manually the buttons to your form unless you build a customcontrol
NoFocusButton b = new NoFocusButton();
b.Text = "ClickMe";
f.Controls.Add(b);
f.Show();
// Class derived by the Button control, it is identical but the
// property that control the drawing of the Focus rectangle returns FALSE
// tricking the WinForm system to avoid to draw the focus rectangle
class NoFocusButton : System.Windows.Forms.Button
{
protected override bool ShowFocusCues
{
get
{
return false;
}
}
}
The credit goes to Remove Focus Rectangle from Button

How to hide a control from the form while designing in visual studio?

I am designing a settings form for my application as shown below:
A tree view with multiple nodes at the left and I want to have one GroupBox for each node to be displayed at the right whenever a node is selected. I have designed my group box with necessary controls for the first node. The question is, how do I design an another group box in the same place when another item is already there. Is there a way to hide a control from a form during design time?
I have always just changed the Z-Order of the GroupBox or Panel by right clicking on it and sending it to back. Just make sure when you add the other GroupBoxes that you add them to the same Parent. Make their Visible property False and then display the GroupBox you want at runtime by making it Visible.
EDIT: Changed answer to be more relevant.
EDIT #2: I missed the VB tag, translating this should be a trivial task anyway.
If you extend GroupBox like this, you'll have a stock GroupBox which will hide itself at design time.
public class myGroupBox : GroupBox
{
public myGroupBox() { InitializeComponent(); }
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if (DesignMode) this.Visible = false;
}
}
NOTE: This should work for almost any non-sealed control.

Categories