using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SchoolDemo
{
public partial class MDI : Form
{
public MDI()
{
InitializeComponent();
}
private void MDI_Load(object sender, EventArgs e)
{
Demo naya = new Demo();
{
naya.MdiParent = this;
naya.WindowState = FormWindowState.Maximized;
};
naya.Show();
}
}
}
[^This is the code of my MDI form]
In the right hand corner you can see there is a extra layer of max, min and close options.
I have already disabled control box in child form but I am still getting this.
According to your description, you want to remove the layer of control box of the child
form.
You can try the following code to solve this problem.
Child form code:
private void Demo_Load(object sender, EventArgs e)
{
ControlBox = false;
}
I am building an Outlook addin for 2010. How do i create a popup dialog box with user input of 2 text boxes and then get those values to show in the body of my message?
Make sure you add the following:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Tools.Ribbon;
using System.Windows.Forms;
namespace EmailHelper
{
public partial class EmailHelperRibbon
{
private void EmailHelperRibbon_Load(object sender, RibbonUIEventArgs e)
{
}
private void button1_Click(object sender, RibbonControlEventArgs e)
{
System.Windows.Forms.MessageBox.Show("Your Ribbon Works!");
Form Form1 = new Form1();
Form1.Show();
}
}
}
I have 2 forms with a main window and a second window. The main window (Form1) shall get text from the second window (Form2)
My second window (Form2) can write text from form 2 to form 1. In the class I can choose color for my text but my problem is that when I push the button who shall send the text it just comes the text without the color I choose so its just black text in Form1 when I send example yellow.
I'm not a C# expert since I'm pretty new at this. I'm sure its a pretty simple problem to fix but for me its not so easy.
Form1.cs:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace tester
{
public partial class Form1 : Form
{
public string text;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 NewForm2 = new Form2(this);
NewForm2.Show();
}
internal void populate()
{
richTextBox1.Text = text;
}
}
Form2.cs:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Tester
{
public partial class Form2 : Form
{
Form1 texting;
public Form2(Form1 iForm)
{
texting = iForm;
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
texting.text = richTextBox1.Text;
texting.populate();
this.Close();
}
private void button2_Click(object sender, EventArgs e)
{
if ( MyColorDialog.ShowDialog() != DialogResult.Cancel)
{
richTextBox1.ForeColor = MyColorDialog.Color;
}
}
}
Just as you are making public string text in your Form1, you could make a public Color rictTextBoxColor property. Then setting it as well, and referring to it in your populate method
I have the following two pieces of code, please take a look at it, I pointed where it is going wrong.
I removed the functions where I call the second window, they do not make sense here.
First, main form, this form calls the second form:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace STP_Design
{
public partial class STP2Main : Form
{
public STP2Main()
{
InitializeComponent();
tabControl1.SelectedTab = tabPageDeviceManager;
}
private void pictureBox1_Click(object sender, EventArgs e)
{
MenuForm MDIMF = new MenuForm();
MDIMF.MdiParent = this;
MDIMF.StartPosition = FormStartPosition.Manual;
MDIMF.Location = new Point(3, 50);
MDIMF.Show();
tabControl1.Visible = false;
}
public void set()
{
tabControl1.Visible = true; // This statement executes, but does not result in anything I'd expect. The debugger tells me the visibility is false.
tabControl1.BringToFront();
}
}
}
and second form, which I close and should update the first form:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace STP_Design
{
public partial class MenuForm : Form
{
public MenuForm()
{
InitializeComponent();
this.BringToFront();
}
private void button1_Click(object sender, EventArgs e)
{
STP2Main stp = new STP2Main();
stp.set();
this.Close();
}
}
}
You're calling the set method on a new version of the main form, rather than on the version you presumably already have displayed to the user.
What you need to do is get the current main form from the MdiParent property of the menu form, and call the method on that instead.
// In menu form
private void button1_Click(object sender, EventArgs e)
{
var mainForm = this.MdiParent as STP2Main;
if (mainForm != null)
mainForm.set();
this.Close();
}
I am new in c#. I am trying to show a new form (form2) when click button in form1.
this is my code.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace SliceEngine
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button5_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
form2.ShowDialog();
}
}
}
the error show
the type or namespace name 'Form2' could not be found (are you missing
a using directive or an assembly reference?)
this is my code for form2.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace SliceEngine
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
}
}
}
for form2, i just making the design interface.
all i know when using java, i only need to declare the object first. what should i do for this?
I don't see any reason to fail your code, unless you have any typo. I have tried the same code as yours and it worked well on my machine.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace winapp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 frm2 = new Form2();
frm2.ShowDialog();
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace winapp
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
}
}
the type or namespace name 'Form2' could not be found (are you missing
a using directive or an assembly reference?)
It means that you forgot to add the namespace that points to the Form2 directory to your code
If you have got a Form2.cs inside a directory named UI and that directory is inside MyForms directory, then the whole tree would be ProjectName >> MyForms >> UI >> Form2.cs
So you should use this namespace in your code
using ProjectName.MyForms.UI;
Now I should be able to start showing it easily cause I've added its location.
new Form2().Show();
OR instead of all that and bother adding a namespace, you can just use:
new ProjectName.MyForms.UI.Form2().Show();
In form1, you are using the constructor for Form2:
public partial class Form1 : Form
{
public Form2()
{
InitializeComponent();
}
if you change it to
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
you should be fine.
Your code claims you don't have a constructor for Form1.
public partial class Form1 : Form
{
public Form2()
{
InitializeComponent();
}
should be:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
I assume below must be the reason why your code is failing.
You have both of your forms in Form1 and Form2, where Form2 definition is done in another namespace directive, which is not integrated in the namespace of Form1, also you can't use same namespace directive name for two namespaces unless you are overriding them.
Try this code.....
private void button1_Click(object sender, EventArgs e)
{
Form2 frm2 = new Form2();
{
frm2.ShowDialog();
}
}
private void button5_Click(object sender, EventArgs e)
{
Form2.show()
}
My solution:
In click event of Form1 include your button:
string foobar = "Hello world";
Form2 frm2 = new Form2(foobar);
frm2.ShowDialog();
In Form2:
public Form2(string foobar)
{
InitializeComponent();
textbox1.Text = foobar;
}
For anybody still looking for an answer:
At the top of your code, add this namespace:
using YourProjectName;
Then, when you wish to show your form, type this:
var form = YourProjectName.YourFormName();
form.Show(); // Show form using new variable