Question

C# Language The ColourControl Class The class should be public. The class defines a read-only or...

C# Language

The ColourControl Class

  • The class should be public.
  • The class defines a read-only or private set public property named Value of type int.
  • The class defines a public event named ValueChanged whose delegate type is void with two parameters, object sender and EventArgs e.
  • The public constructor for the class is a default constructor (i.e., takes no parameters). The constructor sets the Value property to 128.
  • The class defines a public void method named IncreaseValue. The method increases Value by 5. If after adding 5 the value is greater than 255, then Value should be set to 255 instead. The ValueChanged event should be raised only if the value has changed.
  • The class defines a public void method named DecreaseValue. The method decreases Value by 5. If after subtracting 5 the value is less than 0, then Value should be set to 0 instead. The ValueChanged event should be raised only if the value has changed.
  • The class defines a public void method named ResetValue. The method sets Value to 128. The ValueChanged event should be raised only if the value has changed.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

using System;


public class ColourControl
{
  
//private readonly int Val;

public int Val { get; private set; }
  
// Constructor that takes no arguments:
public ColourControl()
{
Val=128;
}

  

public delegate void EventHandler();
  
  
public event EventHandler Valuechanged;
  
  

protected virtual void OnNumChanged()
{
if (Valuechanged != null)
{
Valuechanged();
}
else
{
Console.WriteLine("Event fired!");
}
}
  

public void Increasedvalue()
{
ColourControl c1=new ColourControl();
int k=c1.Val;
  
c1.Val=c1.Val+5;
  
if(c1.Val>255)
{
c1.Val=255;
}
  
if(k!=c1.Val)
{
OnNumChanged();
}
  
}
public void Decreasedvalue()
{
ColourControl c1=new ColourControl();
int k=c1.Val;
  
c1.Val=c1.Val-5;
  
if(c1.Val<0)
{
c1.Val=0;
}
  
if(k!=c1.Val)
{
OnNumChanged();
}
  
}

public void ResetValue()
{
ColourControl c1=new ColourControl();
int k=c1.Val;
c1.Val=128;
if(k!=c1.Val)
{
OnNumChanged();
}
  
}   
  
}

Add a comment
Know the answer?
Add Answer to:
C# Language The ColourControl Class The class should be public. The class defines a read-only or...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using C# Language Develop a Visual C# .NET application that performs a colour control operation. The...

    Using C# Language Develop a Visual C# .NET application that performs a colour control operation. The main form contains a reset button and sets the form's background colour according to the colour values indicated by the colour control objects. Each colour control object is controlled by a corresponding colour control form which provides a progress bar to show the value (in the range 0 to 255) of the corresponding colour control object. The user can click the increase (+) or...

  • Create a BoxFigure class that inherits RectangleFigure class BoxFigure Class should contain:- Height instance field- Default...

    Create a BoxFigure class that inherits RectangleFigure class BoxFigure Class should contain:- Height instance field- Default constructor -- that calls the default super class constructor and sets the default height to 0- Overloaded constructor with three parameters (length, width and height) – that calls the two parameterized super class constructor passing in length and width passed and sets the height to passed height.- setDimension method with three parameters (length, width, height) – call the super class setDimension and pass in...

  • 7 1.5 By organizing reusable codes to a C++ class named "Sample.cpp", which of the following...

    7 1.5 By organizing reusable codes to a C++ class named "Sample.cpp", which of the following is the correct way to import the reusable codes to another C++ file named "Test.cpp"? #define "Sample.cpp" #include "Sample.cpp" #copy "Sample.cpp" #using "Sample.cpp" #import "Sample.cpp" 28 1.5 Given the following code, which can assign "appletree" to the "textBox1" control as caption? TextBox textBoxl; textBox1-> Caption="appletree"; textBox1.Text ="appletree"; textBox1.Caption="appletree"; textBox1.Text = "appletree"; textBox1-> Caption("appletree"); 109 1.5 Given the following code, which can register a "SelectedIndexChanged"...

  • Visual Basic 2015: Extra 18-1 Use inheritance with the Inventory Maintenance Application Source Code: 1. frmNewItem.vb...

    Visual Basic 2015: Extra 18-1 Use inheritance with the Inventory Maintenance Application Source Code: 1. frmNewItem.vb Public Class frmNewItem Public InvItem As InvItem Private Sub frmNewItem_Load(sender As Object, e As EventArgs) Handles MyBase.Load Me.LoadComboBox() End Sub Private Sub LoadComboBox() cboSizeOrManufacturer.Items.Clear() If rdoPlant.Checked Then cboSizeOrManufacturer.Items.Add("1 gallon") cboSizeOrManufacturer.Items.Add("5 gallon") cboSizeOrManufacturer.Items.Add("15 gallon") cboSizeOrManufacturer.Items.Add("24-inch box") cboSizeOrManufacturer.Items.Add("36-inch box") Else cboSizeOrManufacturer.Items.Add("Bayer") cboSizeOrManufacturer.Items.Add("Jobe's") cboSizeOrManufacturer.Items.Add("Ortho") cboSizeOrManufacturer.Items.Add("Roundup") cboSizeOrManufacturer.Items.Add("Scotts") End If End Sub Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click If IsValidData() Then InvItem = New InvItem(CInt(txtItemNo.Text),...

  • In the "Go" button add 15 random numbers in the array using a random number generator....

    In the "Go" button add 15 random numbers in the array using a random number generator. Remove the call to "SetToZero" and the code following. Remove the "SetToZero" method. Add Access Keys of your choice Assign an accept button Assign cancel button (Exit) Add a Button "Find Max" Write an appropriately named method that Accepts the array Finds the largest int and returns the value "Find Max" button click Calls above method Opens a MessageBox to display the returned value...

  • q2: Write a public class named MythMouseListener that implements the Mouselistener interface. This class will have...

    q2: Write a public class named MythMouseListener that implements the Mouselistener interface. This class will have a public constructor that takes a JTextArea and a JLabel as parameters and stores these in instance variables. Override the mouseEntered method to . display the text from the JTextArea on the JLabel in all upper case letters. Then, override the mouseReleased method to display the text from the JTextArea on the JLabel in all lower case letters. The other three methods from the...

  • Language: C++ Create an abstract base class person. The person class must be an abstract base...

    Language: C++ Create an abstract base class person. The person class must be an abstract base class where the following functions are abstracted (to be implemented in Salesman and Warehouse): • set Position • get Position • get TotalSalary .printDetails The person class shall store the following data as either private or protected (i.e., not public; need to be accessible to the derived classes): . a person's name: std::string . a person's age: int . a person's height: float The...

  • An application contains the Structure statement shown here. Structure MyFriend Public strName As String Public strBirthday...

    An application contains the Structure statement shown here. Structure MyFriend Public strName As String Public strBirthday As String End Structure Create a VB.Net Windows Form application named MyFriend_YourName. Change the name property of your form to frmMain. Add the MyFriend Structure to the public class frmMain. Create 2 text boxes txtName and txtBirthday, and a button with the name property changed to btnExecute and the text property changed to Execute. In the button click event, write a Dim statement that...

  • Create the header file named “Complex.h” that contains the following class: The class Complex represents a...

    Create the header file named “Complex.h” that contains the following class: The class Complex represents a complex number which is a number of the form a + bi where a and b are real numbers and i2 = −1. The class should contain: Private double field named real. Private double field named imaginary. Public default constructor that assigns 1 to real and 0 to imaginary. Public overloaded constructor that takes a double as a parameter named real. It assigns real...

  • Write the C# code and make a screenshot of the output according to tasks given below:...

    Write the C# code and make a screenshot of the output according to tasks given below: Create a class named Prism with protected data fields named height and volume (Use double data type for the fields) [5 points] Include public properties for each field. The Height and Volume properties should have get and set accessors. [5 points] Add default constructor which sets the value of Height and Volume properties to 1 and 1 respectively. [5 points] Add overloading constructor which...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT