Sign in to follow this  
0xwarning

Learn C# | Form Control

Recommended Posts

If you have ever wanted to learn c# for multiple purposes.

Then here is your answer.

 

[hide]

Lets Get Started

 

You Will Need

Visual Studio.

Make Sure To Have C# Installed.

 

So I'm Currently using a windows form.

 

Have A Layout of what you want but

here is mine for an example.

 

Make Three RadioButtons

Name Them radioRed, radioGreen, radioBlue

 

Add A Panel Called colorPanel

 

Now Add a button

 

Code

Panel Color

          if (radioRed.Checked == true) // If Red Is Checked
            {
                colorPanel.BackColor = Color.?; //Hint [in The Name]
            }
            if (radioBlue.Checked == true) // If Blue Is Checked
            {
                colorPanel.BackColor = Color.?; //Hint [in The Name]
            }
            if (radioGreen.Checked == true) // If Green Is Checked
            {
                colorPanel.BackColor = Color.?; //Hint [in The Name]
            }

Now try to make it change the panel color

I Have Left Some Hints

 

If Successful here is the code you should have

           if (radioRed.Checked == true) // If Red Is Checked
            {
                colorPanel.BackColor = Color.Red; // Color
            }
            if (radioBlue.Checked == true) // If Blue Is Checked
            {
                colorPanel.BackColor = Color.Blue; // Color
            }
            if (radioGreen.Checked == true) // If Green Is Checked
            {
                colorPanel.BackColor = Color.Green; // Color //Hint [Pretty Obvs]
            }

Now try to make it change the panel color to a color you want and add a extra RadioButton

           if (radioMyColor.Checked == true) // If My Color Is Checked
           {
               colorPanel.BackColor = Color.Lime; // Custom Color
           }

We Can Also Make a ComboBox And A List Box To Change The Panel Color

Simply edit the items

like

this

 

Add Some

Colors

 

Double Click the ComboBox

           if (metroComboBox2.SelectedItem == "?") // Check If text == 
           {
               colorPanel.BackColor = Color.?; // Color
           }

           if (metroComboBox2.SelectedItem == "?") // Check If text ==
           {
               colorPanel.BackColor = Color.?; // Color
           }

           if (metroComboBox2.SelectedItem == "?") // Check If text ==
           {
               colorPanel.BackColor = Color.?; // Color
           } 

Now Add a listbox add the same items 

        if (metroListbox1.SelectedItem == "?") // Check If text ==
           {
               colorPanel.BackColor = Color.?; // Color
           }

           if (metroListbox1.SelectedItem == "?") // Check If text ==
           {
               colorPanel.BackColor = Color.?; // Color
           }

           if (metroListbox1.SelectedItem == "?") // Check If text ==
           {
               colorPanel.BackColor = Color.?; // Color
           }  

Your Code Should Come Out Like This

 

Combo Box

           if (ComboBox2.SelectedItem == "Blue")
           {
               colorPanel.BackColor = Color.Blue;
           }

           if (ComboBox2.SelectedItem == "Green")
           {
               colorPanel.BackColor = Color.Green;
           }

           if (ComboBox2.SelectedItem == "Red")
           {
               colorPanel.BackColor = Color.Red;
           }

// For Custom Color

           if (ComboBox2.SelectedItem == "Lime")
           {
               colorPanel.BackColor = Color.Lime;
           } 

List Box

           if (metroListbox1.SelectedItem == "Blue")
           {
               colorPanel.BackColor = Color.Blue;
           }

           if (metroListbox1.SelectedItem == "Green")
           {
               colorPanel.BackColor = Color.Green;
           }

           if (metroListbox1.SelectedItem == "Red")
           {
               colorPanel.BackColor = Color.Red;
           }

// For Custom Color

           if (metroListbox1.SelectedItem == "Lime")
           {
               colorPanel.BackColor = Color.Lime;
           } 

 Now We Are Going to Attempt To Use A Color Picker

 

Now Select A Unused Button

 

Don't Forget To Add

These

           colorDialog1.ShowDialog(); // Shows Color Dialog
           colorPanel.BackColor = colorDialog1.Color; // Sets Selected Color

We Are Done

 

Please Leave Feedback on what i should do next

The Code will eventually get better. im just doing simple code at first so people can understand

 

Extra

 

Button And A List View

 

Add This Code Into The Button

           openFileDialog1.ShowDialog(); // File Dialog
           openFileDialog1.FileName.ToString(); // Get File Name

           string[] row = { openFileDialog1.FileName.ToString()};
           var listViewItem = new ListViewItem(row); 
           listView1.Items.Add(listViewItem); // Display File Name

Next Thread Will Contain More File Functions

 

I Hope You Enjoyed The Thread

 

[/hide]

Share this post


Link to post
Share on other sites

Si alguna vez has querido aprender c # para múltiples propósitos.

Entonces aquí está tu respuesta.

 

 

 

Un poco mas detallado queda mejor :fuck:

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this