An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
Hi melisaonur-4906,
>>I tried this.hide or this.dispose, but when I use them, the buttons in my form window are not visible.
Are you referring to the button on the usercontrol?
I have two suggestions for you to refer to:
- Add usercontrol and button controls by coding.
You can refer to the following code: UserControl userControl = new UserControl();
private void Form1_Load(object sender, EventArgs e)
{
Button button = new Button();
button.Click += new EventHandler(click);
userControl.Controls.Add(button);
button.BackColor = Color.Red;
userControl.BackColor = Color.Green;
this.Controls.Add(userControl);
}
public void click(object sender, EventArgs e)
{
userControl.Hide();
}
2.When adding usercontrol visually, make sure that the user control and the main forms have the same "using" references.
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
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 WindowsFormsApp
{
public partial class UserControl1 : UserControl
{
......
private void button1_Click(object sender, EventArgs e)
{
this.Hide();
}
}
}
Best Regards,
Daniel Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.