Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » How do I 'check' a Switch control
Re: How do I 'check' a Switch control [message #36219 is a reply to message #36216] Sat, 12 May 2012 21:18 Go to previous messageGo to previous message
Sender Ghost is currently offline  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

 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: time measurement :: RTIMING, TimeStop, GetTickCount
Next Topic: Storing VectorMap
Goto Forum:
  


Current Time: Mon May 06 21:17:50 CEST 2024

Total time taken to generate the page: 0.03241 seconds