-2

I'm learning C++/CLI with .NET in Visual Studio.

I want to create a TrackBar, where the minimum value is RGB white and the maximum value is RGB black.

I've dropped into the Form a Label that shows the value of the TrackBar's pointer position, but I want to show it only while I'm scrolling or holding the TrackBar's pointer with the mouse. Can someone help me?

Here's the TrackBar scroll listener:

private: System::Void trackBar1_Scroll(System::Object^ sender, System::EventArgs^ e) {
    //Set label text to trackbar value
    label2->Text = trackBar1->Value.ToString();
    //Set label2 visible to show trackbar value
    label2->Visible = true;
}
  • Note that C++ and C++/CLI are two different languages. You are learning C++/CLI, not C++. – Ted Lyngmo Feb 08 '22 at 21:06
  • Yes! Thanks for specifying it! i wronly tought it was needed just to say c++ but yeah pure c++ is actually just a command line code – Thomas Basile Feb 08 '22 at 21:13
  • You're welcome! You can [edit](https://stackoverflow.com/posts/71040745/edit) your question to correct the mistake. – Ted Lyngmo Feb 08 '22 at 21:23
  • I don't know if this applies to .NET's TrackBar, but in pure Win32 API, a [TrackBar control](https://learn.microsoft.com/en-us/windows/win32/controls/bumper-trackbar-trackbar-control-overviews) has `WH_(H|V)SCROLL` and `TRBN_THUMBPOSCHANGING` notifications that you can intercept while it is being scrolled/dragged. In particular, `TRBN_THUMBPOSCHANGING` has a `TB_ENDTRACK` reason code to tell you when the scroll/drag is finished, so you can hide your Label. How/If this can translate to .NET, I don't know. – Remy Lebeau Feb 08 '22 at 21:38
  • There's no event to help you with this. A simple alternative is a Timer to hide the label again. – Hans Passant Feb 09 '22 at 01:03

1 Answers1

-1

First of all, thank you all for help! I finally decided to show the label only when trackbar is set to 0 or 100 and instead of showing up 0 or 100 it says Light or Dark. Now i need to get the trackbar to go from rgb white to rgb black and set it as system color for window background... My idea is to use GetSysColor and use the trackbar value as a multiplier for for the actual rgb system window color but i don't know how to convert this to code.

Btw, here's the code for the label behavior:

#pragma endregion
    private: System::Void trackBar1_Scroll(System::Object^ sender, System::EventArgs^ e) {
        
        label2->Text = trackBar1->Value.ToString();
        if (trackBar1->Value == 0 || trackBar1->Value == 100)
        {
            label2->Visible = true;
        }
        else
        {
            label2->Visible = false;
        }

        if (trackBar1->Value == 0)
        {
            label2->Text = "Light";
        }
        if (trackBar1->Value == 100)
        {
            label2->Text = "Dark";
        }
        
    }
    };