C
C#2w ago
Nikssna

Can someone help me fix my code, it doesnt open usercoontrols form porperly

i just satrted to learn c# and if i dont understand something sorry
16 Replies
canton7
canton72w ago
It's hard to fix code that we can't see. $help
MODiX
MODiX2w ago
How to get the best help :catpog: Make a post in #help or one of the topic channels under Development. Avoid asking :catthinking: Can anybody help me? :catthinking: Has anyone used XYZ? :catthinking: Why doesn't my code work? C# is a big area! No one knows they can help unless you tell them about the small area you're trying to work in. Explain what you are doing, and potentially why for as much context as possible. Avoid screenshots where possible, share code directly in Discord. Type $code into chat to learn how to post code. See https://www.nohello.net and https://dontasktoask.com if you want common help chat room etiquette.
Nikssna
NikssnaOP2w ago
can i screen share or should i send a screen shot ?
canton7
canton72w ago
Please share all code that's relevant, and include screenshots so we can see what "doesn't open properly" actually means You'll get a much better response with screenshots. I'm at work: I can't take a call, but I can look at images
Nikssna
NikssnaOP2w ago
I think this is all of the code to open the usercontrol form
No description
No description
canton7
canton72w ago
Please post code as $code, not as images
MODiX
MODiX2w ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat For longer snippets, use: https://paste.mod.gg/
Nikssna
NikssnaOP2w ago
$codegif
Nikssna
NikssnaOP2w ago
private void guna2Button8_Click(object sender, EventArgs e)
{
// Create the UC_ListBoxhub user control and pass the Form1 reference to it
UC_ListBoxhub uc = new UC_ListBoxhub(this); // Passing reference to Form1
addUserControl(uc); // Add the user control
}

private void addUserControl(UserControl userControl)
{
// Loop through controls and hide any other user control (but keep FastColoredTextBox visible)
foreach (Control ctrl in this.Controls)
{
if (ctrl is UserControl && ctrl != userControl) // Hide other user controls
{
ctrl.Hide();
}
}

// If the user control is not already added, add it
if (!this.Controls.Contains(userControl))
{
userControl.Dock = DockStyle.Fill; // Make sure it fills the form
Controls.Add(userControl); // Add the user control
}

userControl.BringToFront(); // Bring the new user control to the front
}
private void guna2Button8_Click(object sender, EventArgs e)
{
// Create the UC_ListBoxhub user control and pass the Form1 reference to it
UC_ListBoxhub uc = new UC_ListBoxhub(this); // Passing reference to Form1
addUserControl(uc); // Add the user control
}

private void addUserControl(UserControl userControl)
{
// Loop through controls and hide any other user control (but keep FastColoredTextBox visible)
foreach (Control ctrl in this.Controls)
{
if (ctrl is UserControl && ctrl != userControl) // Hide other user controls
{
ctrl.Hide();
}
}

// If the user control is not already added, add it
if (!this.Controls.Contains(userControl))
{
userControl.Dock = DockStyle.Fill; // Make sure it fills the form
Controls.Add(userControl); // Add the user control
}

userControl.BringToFront(); // Bring the new user control to the front
}
i tried to use chatgpt but i dont think it helped
canton7
canton72w ago
And what does that look like?
Nikssna
NikssnaOP2w ago
like when i open the usercontrol the code button is checked but it doesnt need ato and when i re open it the fastcolored textbox desapears
canton7
canton72w ago
I think we need to see a lot more code -- the stuff you posted doesn't contain anything to do with how the buttons are selected or deselected, and only has one button click handler
Nikssna
NikssnaOP2w ago
maybe when you will get home i could just call you and screen share?
canton7
canton72w ago
Sorry, I'm busy in the evenings
Nikssna
NikssnaOP2w ago
Oh
Want results from more Discord servers?
Add your server