Reset Control Attributes
-
Hi, Please forgive me as this may be a very simple question but I am a newbie at this. I have searched for this info for three days now and cannot seem to find any answers. I have two questions: Q1. How do I reset the background color of a push button. I have a standard button. In the code snippet below I also have a cursor style change. The cursor changes back to the original (default cursor) when the mouse leaves the button (without me including any cursor specific code in the MouseLeave function) but the back color does not change. I even tried to set up a pointer to store the original color and this works but after the mouse leaves the button the style of the button is chnaged to flat. Do I need to also store the FlatStyle and retrieve it on MoudeLeave? // declare an int pointer (for the exit button background color) called btnExit_default_BackColor int *btnExit_default_BackColor; // declare a boolean pointer (for the exit button UseVisualStyle background color) called btnExit_default_UseVisualStyleBackColor bool *btnExit_default_UseVisualStyleBackColor; private: System::Void btnExit_MouseEnter(System::Object^ sender, System::EventArgs^ e) { // allocate memory for an int variable and make the btnExit_default_BackColor pointer point to this new memmory btnExit_default_BackColor=new int; //assign the exit button background color to the memory allocated *btnExit_default_BackColor=btnExit->UseVisualStyleBackColor; // allocate memory for a bool variable and make the btnExit_default_UseVisualStyleBackColor pointer point to this new memmory btnExit_default_UseVisualStyleBackColor=new bool; //assign the exit button background color to the memory allocated *btnExit_default_UseVisualStyleBackColor=btnExit->UseVisualStyleBackColor; btnExit->Cursor=Cursors::Hand; // change mouse cursor to hand when over a push button // Change button outline color to 0x00FF4500 (orange red with opacity 0) System::String^ highlightColor="#0x00FF4500"; btnExit->BackColor=System::Drawing::ColorTranslator::FromHtml(highlightColor); } private: System::Void btnExit_MouseLeave(System::Object^ sender, System::EventArgs^ e) { // Change button outline color to original state before mouse hover btnExit->BackColor=System::Drawing::Color::FromArgb(*btnExit_default_BackColor); btnExit->UseVisualStyleBackColor=*btnExit_default_UseVisualStyleBackColor; delete btnExit_default_BackColor; // d
-
Hi, Please forgive me as this may be a very simple question but I am a newbie at this. I have searched for this info for three days now and cannot seem to find any answers. I have two questions: Q1. How do I reset the background color of a push button. I have a standard button. In the code snippet below I also have a cursor style change. The cursor changes back to the original (default cursor) when the mouse leaves the button (without me including any cursor specific code in the MouseLeave function) but the back color does not change. I even tried to set up a pointer to store the original color and this works but after the mouse leaves the button the style of the button is chnaged to flat. Do I need to also store the FlatStyle and retrieve it on MoudeLeave? // declare an int pointer (for the exit button background color) called btnExit_default_BackColor int *btnExit_default_BackColor; // declare a boolean pointer (for the exit button UseVisualStyle background color) called btnExit_default_UseVisualStyleBackColor bool *btnExit_default_UseVisualStyleBackColor; private: System::Void btnExit_MouseEnter(System::Object^ sender, System::EventArgs^ e) { // allocate memory for an int variable and make the btnExit_default_BackColor pointer point to this new memmory btnExit_default_BackColor=new int; //assign the exit button background color to the memory allocated *btnExit_default_BackColor=btnExit->UseVisualStyleBackColor; // allocate memory for a bool variable and make the btnExit_default_UseVisualStyleBackColor pointer point to this new memmory btnExit_default_UseVisualStyleBackColor=new bool; //assign the exit button background color to the memory allocated *btnExit_default_UseVisualStyleBackColor=btnExit->UseVisualStyleBackColor; btnExit->Cursor=Cursors::Hand; // change mouse cursor to hand when over a push button // Change button outline color to 0x00FF4500 (orange red with opacity 0) System::String^ highlightColor="#0x00FF4500"; btnExit->BackColor=System::Drawing::ColorTranslator::FromHtml(highlightColor); } private: System::Void btnExit_MouseLeave(System::Object^ sender, System::EventArgs^ e) { // Change button outline color to original state before mouse hover btnExit->BackColor=System::Drawing::Color::FromArgb(*btnExit_default_BackColor); btnExit->UseVisualStyleBackColor=*btnExit_default_UseVisualStyleBackColor; delete btnExit_default_BackColor; // d
I can't answer your first question but I can explain the ^ operator: That operator is a reference to a managed object. So, if you have
void btnExit_MouseLeave(System::Object^ sender, System::EventArgs^ e)
That means that the function takes a
reference
to a System:Object and areference
to a System::EventArgs object. If you haveObject* obj
, it means thatobj
points to the object on the heap. In the same way, the ^ means that the variable points to the object on themanaged
heap. The ^ is used with the gcnew operator to assign a new object instance to a variable, as in:Object^ var = gcnew Object()