Home » Community » Newbie corner » How do I 'check' a Switch control
How do I 'check' a Switch control [message #36216] |
Sat, 12 May 2012 17:35  |
awksed
Messages: 68 Registered: April 2012
|
Member |
|
|
Hi,
How do I 'check' a (single) Switch control and how do I determine if it is 'checked'? (I am looking for the equivalent of the MFC CButton::SetCheck() and CButton::GetCheck()).
Thanks,
Jan
|
|
|
|
|
Re: How do I 'check' a Switch control [message #36219 is a reply to message #36216] |
Sat, 12 May 2012 21:18   |
Sender Ghost
Messages: 301 Registered: November 2008
|
Senior Member |
|
|
Hello, Jan.
awksed wrote on Sat, 12 May 2012 17:35 | How do I 'check' a (single) Switch control and how do I determine if it is 'checked'? (I am looking for the equivalent of the MFC CButton::SetCheck() and CButton::GetCheck()).
|
There is Switch example inside reference U++ directory, which "demonstrates Switch widget". Also take a look Switch documentation.
Basically, as Jerson said, you assign the value (of type Value) to Switch object to select concrete case. To get selected value, just use GetData() Switch method or ~ operator before Switch object:
Switch sw;
sw.Add("Left").Add("Center").Add("Right");
sw = 1; // Selecting "Center". Equivalent to sw.SetData(1);
PromptOK(Format("Selected '%s' case with '%s' value", sw.GetLabel(), AsString(~sw)));
Based on CButton::SetCheck method, I think, you need ButtonOption or just Option widget:
#include <CtrlLib/CtrlLib.h>
using namespace Upp;
class App : public TopWindow {
public:
typedef App CLASSNAME;
App();
ButtonOption btnOption;
void PromptOption();
};
void App::PromptOption()
{
static const String cases[2] = { "Off", "On" };
PromptOK(cases[(int)btnOption.Get()]); // ButtonOption::Get is equivalent to CButton::GetCheck.
}
App::App()
{
Title("ButtonOption test application");
Sizeable().Zoomable();
SetRect(Size(320, 240));
btnOption.SetLabel("X");
btnOption.Set(true); // ButtonOption::Set is equivalent to CButton::SetCheck.
btnOption.WhenAction = THISBACK(PromptOption);
Add(btnOption.VCenterPosZ(50).HCenterPosZ(50));
}
GUI_APP_MAIN
{
App app;
app.Run();
}
[Updated on: Sat, 12 May 2012 21:25] Report message to a moderator
|
|
|
|
Goto Forum:
Current Time: Sun Apr 27 01:32:43 CEST 2025
Total time taken to generate the page: 0.02623 seconds
|