Set focus on button - focuses two buttons
-
- Ultimate wxWidgets Guru
- Posts: 670
- Joined: Tue Jul 26, 2016 2:00 pm
Set focus on button - focuses two buttons
Hi
I'm trying to focus a button depending on a variable. Problem is, the top button, which as a standard is focused when showing the wxDialog won't unfocus so I'll end up with two focused buttons. Can I do something about that?
Thanks,
Thomas
I'm trying to focus a button depending on a variable. Problem is, the top button, which as a standard is focused when showing the wxDialog won't unfocus so I'll end up with two focused buttons. Can I do something about that?
Thanks,
Thomas
Re: Set focus on button - focuses two buttons
That should be impossible. Can you show a screenshot? Maybe it's just a redraw issue, try calling Refresh() on the main frame afterwards.
Use the source, Luke!
-
- Ultimate wxWidgets Guru
- Posts: 670
- Joined: Tue Jul 26, 2016 2:00 pm
Re: Set focus on button - focuses two buttons
I tried Refresh but it still show two focused buttons.
https://i.ibb.co/44R8Tz3/widgets-fehler.jpg
The interesting thing is, that when I click another button, the first button (Alpen) is deselected but the second one (Integra) remains selected. So there are always two selected buttons. But if I change the window with Alt+Tab to another open program and then switch back to my program window, there is only one button selected. But somehow I feel that the problem is, that clicking a button will normally make something happen and then the button won't be there anyway. So as I haven't connected the buttons to an action, the selection is changing (which is a normal behavior) and my first programmatically selected button stays selected. But then I don't understand why this programmatically selected button changes as well when I click two buttons.
EDIT:
I have now made functions for all button where again I specify the selection of this button. And then do a Refresh. But still the same behavior.
https://i.ibb.co/44R8Tz3/widgets-fehler.jpg
The interesting thing is, that when I click another button, the first button (Alpen) is deselected but the second one (Integra) remains selected. So there are always two selected buttons. But if I change the window with Alt+Tab to another open program and then switch back to my program window, there is only one button selected. But somehow I feel that the problem is, that clicking a button will normally make something happen and then the button won't be there anyway. So as I haven't connected the buttons to an action, the selection is changing (which is a normal behavior) and my first programmatically selected button stays selected. But then I don't understand why this programmatically selected button changes as well when I click two buttons.
EDIT:
I have now made functions for all button where again I specify the selection of this button. And then do a Refresh. But still the same behavior.
Re: Set focus on button - focuses two buttons
That image is very small
Is it possible that one button is focused and the other one is the "default" button? The visuals are similar. What happens when you use TAB to move the focus?
Is it possible that one button is focused and the other one is the "default" button? The visuals are similar. What happens when you use TAB to move the focus?
Use the source, Luke!
-
- Ultimate wxWidgets Guru
- Posts: 670
- Joined: Tue Jul 26, 2016 2:00 pm
Re: Set focus on button - focuses two buttons
It might be that "Alpen" is the default one. How can I change it or how can I have no default button at all?
If I use TAB the effect is the same.
I have another question. When the user clicks a button, the Listbox next to it should refresh as well because in the function of the button the values are re-read. But doing a Refresh() won't do anything, the values remain the same
Here is a better picture:
EDIT: The Listbox refreshing problem is solved
If I use TAB the effect is the same.
I have another question. When the user clicks a button, the Listbox next to it should refresh as well because in the function of the button the values are re-read. But doing a Refresh() won't do anything, the values remain the same
Here is a better picture:
EDIT: The Listbox refreshing problem is solved
-
- Ultimate wxWidgets Guru
- Posts: 670
- Joined: Tue Jul 26, 2016 2:00 pm
Re: Set focus on button - focuses two buttons
Okay, I did it!
I set a default button before I set the focused button. Then interestingly the default button isn't focused but the one that I want to be focused. I don't understand it but it works.
I set a default button before I set the focused button. Then interestingly the default button isn't focused but the one that I want to be focused. I don't understand it but it works.
Re: Set focus on button - focuses two buttons
What i wanted to know is if one "focus" ring moves and another one doesn't (which would imply that the latter is not a focus ring)
Use the source, Luke!
-
- Ultimate wxWidgets Guru
- Posts: 670
- Joined: Tue Jul 26, 2016 2:00 pm
Re: Set focus on button - focuses two buttons
Actually it's working now but I still think the behavior of this default button is interesting and I don't understand it.
So the default button remains unfocused if I set a focused button after setting the default button. When I click the default button it remains unfocused until I click a second time... But this only happens if the function for the default button is empty. If I show a message box when clicking on the default button, the message box appears and after I close it the default button is still unfocused. But maybe this is the normal behavior.
So the default button remains unfocused if I set a focused button after setting the default button. When I click the default button it remains unfocused until I click a second time... But this only happens if the function for the default button is empty. If I show a message box when clicking on the default button, the message box appears and after I close it the default button is still unfocused. But maybe this is the normal behavior.
-
- Ultimate wxWidgets Guru
- Posts: 670
- Joined: Tue Jul 26, 2016 2:00 pm
Re: Set focus on button - focuses two buttons
I still don't like the behavior of my buttons. In order to keep the buttons from getting selected in pairs I set one button as default button. That helps to keep the selection on the button I want when I click on the buttons. But when I click somewhere else (eg an item in the ListBox), it's always the default button that gets highlighted. Is there a way to not have any button highlighted at all or at least keep the button that I set the focus on highlighted?
Re: Set focus on button - focuses two buttons
Can you post the code for the dialog?
Use the source, Luke!
-
- Ultimate wxWidgets Guru
- Posts: 670
- Joined: Tue Jul 26, 2016 2:00 pm
Re: Set focus on button - focuses two buttons
Code: Select all
Printer_List::Printer_List(wxWindow* parent,wxWindowID id,const wxPoint& pos,const wxSize& size)
{
//(*Initialize(Printer_List)
wxBoxSizer* BoxSizer4;
wxBoxSizer* BoxSizer5;
wxBoxSizer* BoxSizer2;
wxBoxSizer* BoxSizer1;
wxBoxSizer* BoxSizer3;
wxBoxSizer* BoxSizer6;
Create(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, _T("id"));
SetClientSize(wxDefaultSize);
Move(wxDefaultPosition);
BoxSizer1 = new wxBoxSizer(wxHORIZONTAL);
Panel1 = new wxPanel(this, ID_PANEL1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL1"));
BoxSizer2 = new wxBoxSizer(wxVERTICAL);
StaticText1 = new wxStaticText(Panel1, ID_STATICTEXT1, _("Drucker-Auswahl"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT1"));
wxFont StaticText1Font(14,wxFONTFAMILY_SWISS,wxFONTSTYLE_NORMAL,wxFONTWEIGHT_BOLD,false,_T("Arial"),wxFONTENCODING_DEFAULT);
StaticText1->SetFont(StaticText1Font);
BoxSizer2->Add(StaticText1, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
StaticText3 = new wxStaticText(Panel1, ID_STATICTEXT3, _("Schuleinheit " + _User.UserSchuleinheit), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT3"));
wxFont StaticText3Font(12,wxFONTFAMILY_SWISS,wxFONTSTYLE_NORMAL,wxFONTWEIGHT_BOLD,false,_T("Arial"),wxFONTENCODING_DEFAULT);
StaticText3->SetFont(StaticText3Font);
BoxSizer2->Add(StaticText3, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
StaticText2 = new wxStaticText(Panel1, ID_STATICTEXT2, _("Gewünschte/n Drucker auswählen\nMehrfach-Auswahl ist möglich"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE, _T("ID_STATICTEXT2"));
wxFont StaticText2Font(11,wxFONTFAMILY_SWISS,wxFONTSTYLE_NORMAL,wxFONTWEIGHT_NORMAL,false,_T("Arial"),wxFONTENCODING_DEFAULT);
StaticText2->SetFont(StaticText2Font);
StaticText4 = new wxStaticText(Panel1, ID_STATICTEXT3, _("Auswahl-Liste"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT4"));
wxFont StaticText4Font(10,wxFONTFAMILY_SWISS,wxFONTSTYLE_NORMAL,wxFONTWEIGHT_BOLD,false,_T("Arial"),wxFONTENCODING_DEFAULT);
StaticText4->SetFont(StaticText4Font);
StaticText5 = new wxStaticText(Panel1, ID_STATICTEXT5, _("Zu installierende Drucker"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT5"));
StaticText5->SetFont(StaticText4Font);
BoxSizer2->Add(StaticText2, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 10);
BoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
BoxSizer4 = new wxBoxSizer(wxVERTICAL);
Button1 = new wxButton(Panel1, ID_BUTTON1, _("Alpen"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON1"));
BoxSizer4->Add(Button1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Button2 = new wxButton(Panel1, ID_BUTTON2, _("Bubental"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON2"));
BoxSizer4->Add(Button2, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Button3 = new wxButton(Panel1, ID_BUTTON3, _("Bürgli"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON3"));
BoxSizer4->Add(Button3, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Button4 = new wxButton(Panel1, ID_BUTTON4, _("Integra"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON4"));
BoxSizer4->Add(Button4, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Button5 = new wxButton(Panel1, ID_BUTTON5, _("KGS"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON5"));
BoxSizer4->Add(Button5, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Button6 = new wxButton(Panel1, ID_BUTTON6, _("Mösli"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON6"));
BoxSizer4->Add(Button6, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Button8 = new wxButton(Panel1, ID_BUTTON8, _("Alle"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON8"));
BoxSizer4->Add(Button8, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
BoxSizer3->Add(BoxSizer4, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
BoxSizer5 = new wxBoxSizer(wxVERTICAL);
BoxSizer5->Add(StaticText4, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
BoxSizer6 = new wxBoxSizer(wxVERTICAL);
BoxSizer6->Add(StaticText5, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
ListBox2 = new wxListBox(Panel1, ID_LISTBOX2, wxDefaultPosition, wxSize(160,150), 0, 0, wxLB_MULTIPLE|wxLB_NEEDED_SB|wxLB_SORT|wxALWAYS_SHOW_SB, wxDefaultValidator, _T("ID_LISTBOX2"));
BoxSizer6->Add(ListBox2, 0, wxALL|wxEXPAND, 5);
Button9 = new wxButton(Panel1, ID_BUTTON9, _("Entfernen"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON9"));
BoxSizer6->Add(Button9, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
BoxSizer6->Add(-1,0,1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Button10 = new wxButton(Panel1, ID_BUTTON10, _("Ausgewählte Drucker installieren"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON10"));
getPrinters(_User.UserSchuleinheit); //erstellt ein Array mit Strings (Druckernamen)
ListBox1 = new wxListBox(Panel1, ID_LISTBOX1, wxDefaultPosition, wxSize(160,89), 0, 0, wxLB_MULTIPLE|wxLB_NEEDED_SB|wxLB_SORT|wxALWAYS_SHOW_SB, wxDefaultValidator, _T("ID_LISTBOX1"));
int i = 0; //Zähler für Drucker aus Array
while(PrinterList[i] != "")
{
ListBox1->Append(_(PrinterList[i]));
i = i + 1;
}
PrinterList_refresh();
BoxSizer5->Add(ListBox1, 1, wxALL|wxEXPAND, 5);
Button7 = new wxButton(Panel1, ID_BUTTON7, _("Hinzufügen"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON7"));
Button10->SetDefault();
BoxSizer5->Add(Button7, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
BoxSizer6->Add(Button10, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
if(_User.UserSchuleinheit == "Alpen")
{
Button1->SetFocus();
}
if(_User.UserSchuleinheit == "Bubental")
{
Button2->SetFocus();
}
if(_User.UserSchuleinheit == "Bürgli")
{
Button3->SetFocus();
}
if(_User.UserSchuleinheit == "Integra")
{
Button4->SetFocus();
}
if(_User.UserSchuleinheit == "KGS")
{
Button5->SetFocus();
}
if(_User.UserSchuleinheit == "Mösli")
{
Button6->SetFocus();
}
BoxSizer3->Add(BoxSizer5, 1, wxALL|wxEXPAND, 5);
BoxSizer3->Add(BoxSizer6, 1, wxALL|wxEXPAND, 5);
BoxSizer2->Add(BoxSizer3, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Panel1->SetSizer(BoxSizer2);
BoxSizer2->Fit(Panel1);
BoxSizer2->SetSizeHints(Panel1);
BoxSizer1->Add(Panel1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
SetSizer(BoxSizer1);
BoxSizer1->Fit(this);
BoxSizer1->SetSizeHints(this);
Refresh();
Center();
Connect(ID_BUTTON10,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&Printer_List::OnButton10Click);
Connect(ID_BUTTON9,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&Printer_List::OnButton9Click);
Connect(ID_BUTTON8,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&Printer_List::OnButton8Click);
Connect(ID_BUTTON7,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&Printer_List::OnButton7Click);
Connect(ID_BUTTON6,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&Printer_List::OnButton6Click);
Connect(ID_BUTTON5,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&Printer_List::OnButton5Click);
Connect(ID_BUTTON4,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&Printer_List::OnButton4Click);
Connect(ID_BUTTON3,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&Printer_List::OnButton3Click);
Connect(ID_BUTTON2,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&Printer_List::OnButton2Click);
Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&Printer_List::OnButton1Click);
//*)
}
Re: Set focus on button - focuses two buttons
I only made changes to make it compilable for me, but i don't see anything unusual regarding the focus behavior on my system. Tested on Win7 and Win10.
Can you build this minimal sample and check if it shows the same issue?
Can you build this minimal sample and check if it shows the same issue?
Code: Select all
/////////////////////////////////////////////////////////////////////////////
// Name: minimal.cpp
// Purpose: Minimal wxWidgets sample
// Author: Julian Smart
// Modified by:
// Created: 04/01/98
// Copyright: (c) Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
// for all others, include the necessary headers (this file is usually all you
// need because it includes almost all "standard" wxWidgets headers)
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
// ----------------------------------------------------------------------------
// resources
// ----------------------------------------------------------------------------
// the application icon (under Windows it is in resources and even
// though we could still include the XPM here it would be unused)
#ifndef wxHAS_IMAGES_IN_RESOURCES
#include "../sample.xpm"
#endif
// ----------------------------------------------------------------------------
// private classes
// ----------------------------------------------------------------------------
// Define a new application type, each program should derive a class from wxApp
class MyApp : public wxApp
{
public:
// override base class virtuals
// ----------------------------
// this one is called on application startup and is a good place for the app
// initialization (doing it here and not in the ctor allows to have an error
// return: if OnInit() returns false, the application terminates)
virtual bool OnInit() wxOVERRIDE;
};
// Define a new frame type: this is going to be our main frame
class MyFrame : public wxFrame
{
public:
// ctor(s)
MyFrame(const wxString& title);
// event handlers (these functions should _not_ be virtual)
void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
private:
// any class wishing to process wxWidgets events must use this macro
wxDECLARE_EVENT_TABLE();
};
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
// IDs for the controls and the menu commands
enum
{
// menu items
Minimal_Quit = wxID_EXIT,
// it is important for the id corresponding to the "About" command to have
// this standard value as otherwise it won't be handled properly under Mac
// (where it is special and put into the "Apple" menu)
Minimal_About = wxID_ABOUT
};
// ----------------------------------------------------------------------------
// event tables and other macros for wxWidgets
// ----------------------------------------------------------------------------
// the event tables connect the wxWidgets events with the functions (event
// handlers) which process them. It can be also done at run-time, but for the
// simple menu events like this the static method is much simpler.
wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(Minimal_Quit, MyFrame::OnQuit)
EVT_MENU(Minimal_About, MyFrame::OnAbout)
wxEND_EVENT_TABLE()
// Create a new application object: this macro will allow wxWidgets to create
// the application object during program execution (it's better than using a
// static object for many reasons) and also implements the accessor function
// wxGetApp() which will return the reference of the right type (i.e. MyApp and
// not wxApp)
wxIMPLEMENT_APP(MyApp);
// ============================================================================
// implementation
// ============================================================================
enum {
ID_PANEL1 = wxID_HIGHEST + 100,
ID_STATICTEXT1,
ID_STATICTEXT2,
ID_STATICTEXT3,
ID_STATICTEXT4,
ID_STATICTEXT5,
ID_BUTTON1,
ID_BUTTON2,
ID_BUTTON3,
ID_BUTTON4,
ID_BUTTON5,
ID_BUTTON6,
ID_BUTTON7,
ID_BUTTON8,
ID_BUTTON9,
ID_BUTTON10,
ID_LISTBOX1,
ID_LISTBOX2,
};
class Printer_List : public wxFrame
{
public:
Printer_List(wxWindow* parent ,wxWindowID id = wxID_ANY,const wxPoint& pos = wxDefaultPosition ,const wxSize& size = wxDefaultSize)
{
//(*Initialize(Printer_List)
wxBoxSizer* BoxSizer4;
wxBoxSizer* BoxSizer5;
wxBoxSizer* BoxSizer2;
wxBoxSizer* BoxSizer1;
wxBoxSizer* BoxSizer3;
wxBoxSizer* BoxSizer6;
Create(parent, id, wxEmptyString, pos, size, wxDEFAULT_FRAME_STYLE, _T("id"));
BoxSizer1 = new wxBoxSizer(wxHORIZONTAL);
wxPanel *Panel1 = new wxPanel(this, ID_PANEL1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL1"));
BoxSizer2 = new wxBoxSizer(wxVERTICAL);
wxStaticText *StaticText1 = new wxStaticText(Panel1, ID_STATICTEXT1, _("Drucker-Auswahl"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT1"));
wxFont StaticText1Font(14,wxFONTFAMILY_SWISS,wxFONTSTYLE_NORMAL,wxFONTWEIGHT_BOLD,false,_T("Arial"),wxFONTENCODING_DEFAULT);
StaticText1->SetFont(StaticText1Font);
BoxSizer2->Add(StaticText1, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
wxStaticText *StaticText3 = new wxStaticText(Panel1, ID_STATICTEXT3, _("Schuleinheit "), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT3"));
wxFont StaticText3Font(12,wxFONTFAMILY_SWISS,wxFONTSTYLE_NORMAL,wxFONTWEIGHT_BOLD,false,_T("Arial"),wxFONTENCODING_DEFAULT);
StaticText3->SetFont(StaticText3Font);
BoxSizer2->Add(StaticText3, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
wxStaticText *StaticText2 = new wxStaticText(Panel1, ID_STATICTEXT2, _("Gewünschte/n Drucker auswählen\nMehrfach-Auswahl ist möglich"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE, _T("ID_STATICTEXT2"));
wxFont StaticText2Font(11,wxFONTFAMILY_SWISS,wxFONTSTYLE_NORMAL,wxFONTWEIGHT_NORMAL,false,_T("Arial"),wxFONTENCODING_DEFAULT);
StaticText2->SetFont(StaticText2Font);
wxStaticText *StaticText4 = new wxStaticText(Panel1, ID_STATICTEXT3, _("Auswahl-Liste"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT4"));
wxFont StaticText4Font(10,wxFONTFAMILY_SWISS,wxFONTSTYLE_NORMAL,wxFONTWEIGHT_BOLD,false,_T("Arial"),wxFONTENCODING_DEFAULT);
StaticText4->SetFont(StaticText4Font);
wxStaticText *StaticText5 = new wxStaticText(Panel1, ID_STATICTEXT5, _("Zu installierende Drucker"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT5"));
StaticText5->SetFont(StaticText4Font);
BoxSizer2->Add(StaticText2, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 10);
BoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
BoxSizer4 = new wxBoxSizer(wxVERTICAL);
wxButton *Button1 = new wxButton(Panel1, ID_BUTTON1, _("Alpen"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON1"));
BoxSizer4->Add(Button1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
wxButton *Button2 = new wxButton(Panel1, ID_BUTTON2, _("Bubental"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON2"));
BoxSizer4->Add(Button2, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
wxButton *Button3 = new wxButton(Panel1, ID_BUTTON3, _("Bürgli"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON3"));
BoxSizer4->Add(Button3, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
wxButton *Button4 = new wxButton(Panel1, ID_BUTTON4, _("Integra"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON4"));
BoxSizer4->Add(Button4, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
wxButton *Button5 = new wxButton(Panel1, ID_BUTTON5, _("KGS"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON5"));
BoxSizer4->Add(Button5, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
wxButton *Button6 = new wxButton(Panel1, ID_BUTTON6, _("Mösli"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON6"));
BoxSizer4->Add(Button6, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
wxButton *Button8 = new wxButton(Panel1, ID_BUTTON8, _("Alle"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON8"));
BoxSizer4->Add(Button8, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
BoxSizer3->Add(BoxSizer4, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
BoxSizer5 = new wxBoxSizer(wxVERTICAL);
BoxSizer5->Add(StaticText4, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
BoxSizer6 = new wxBoxSizer(wxVERTICAL);
BoxSizer6->Add(StaticText5, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
wxListBox *ListBox2 = new wxListBox(Panel1, ID_LISTBOX2, wxDefaultPosition, wxSize(160,150), 0, 0, wxLB_MULTIPLE|wxLB_NEEDED_SB|wxLB_SORT|wxALWAYS_SHOW_SB, wxDefaultValidator, _T("ID_LISTBOX2"));
BoxSizer6->Add(ListBox2, 0, wxALL|wxEXPAND, 5);
wxButton *Button9 = new wxButton(Panel1, ID_BUTTON9, _("Entfernen"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON9"));
BoxSizer6->Add(Button9, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
BoxSizer6->Add(-1,0,1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
wxButton *Button10 = new wxButton(Panel1, ID_BUTTON10, _("Ausgewählte Drucker installieren"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON10"));
wxListBox *ListBox1 = new wxListBox(Panel1, ID_LISTBOX1, wxDefaultPosition, wxSize(160,89), 0, 0, wxLB_MULTIPLE|wxLB_NEEDED_SB|wxLB_SORT|wxALWAYS_SHOW_SB, wxDefaultValidator, _T("ID_LISTBOX1"));
//getPrinters(_User.UserSchuleinheit); //erstellt ein Array mit Strings (Druckernamen)
wxArrayString PrinterList;
PrinterList.Add("Printer 1");
PrinterList.Add("Printer 2");
PrinterList.Add("Printer 3");
PrinterList.Add("Printer 4");
for(int i = 0; i < PrinterList.GetCount(); i++ ) {
ListBox1->Append(_(PrinterList[i]));
}
BoxSizer5->Add(ListBox1, 1, wxALL|wxEXPAND, 5);
wxButton *Button7 = new wxButton(Panel1, ID_BUTTON7, _("Hinzufügen"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON7"));
Button10->SetDefault();
BoxSizer5->Add(Button7, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
BoxSizer6->Add(Button10, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
//if(_User.UserSchuleinheit == "Alpen")
// {
// Button1->SetFocus();
// }
// if(_User.UserSchuleinheit == "Bubental")
// {
// Button2->SetFocus();
// }
// if(_User.UserSchuleinheit == "Bürgli")
// {
// Button3->SetFocus();
// }
// if(_User.UserSchuleinheit == "Integra")
// {
// Button4->SetFocus();
// }
// if(_User.UserSchuleinheit == "KGS")
// {
// Button5->SetFocus();
// }
// if(_User.UserSchuleinheit == "Mösli")
// {
// Button6->SetFocus();
// }
BoxSizer3->Add(BoxSizer5, 1, wxALL|wxEXPAND, 5);
BoxSizer3->Add(BoxSizer6, 1, wxALL|wxEXPAND, 5);
BoxSizer2->Add(BoxSizer3, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Panel1->SetSizer(BoxSizer2);
// BoxSizer2->Fit(Panel1);
// BoxSizer2->SetSizeHints(Panel1);
BoxSizer1->Add(Panel1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
SetSizer(BoxSizer1);
BoxSizer1->Fit(this);
BoxSizer1->SetSizeHints(this);
Center();
Button3->SetFocus();
//*)
};
};
// ----------------------------------------------------------------------------
// the application class
// ----------------------------------------------------------------------------
// 'Main program' equivalent: the program execution "starts" here
bool MyApp::OnInit()
{
// call the base class initialization method, currently it only parses a
// few common command-line options but it could be do more in the future
if ( !wxApp::OnInit() )
return false;
// create the main application window
// MyFrame *frame = new MyFrame("Minimal wxWidgets App");
Printer_List *frame = new Printer_List(NULL, wxID_ANY);
// and show it (the frames, unlike simple controls, are not shown when
// created initially)
frame->Show(true);
// success: wxApp::OnRun() will be called which will enter the main message
// loop and the application will run. If we returned false here, the
// application would exit immediately.
return true;
}
// ----------------------------------------------------------------------------
// main frame
// ----------------------------------------------------------------------------
// frame constructor
MyFrame::MyFrame(const wxString& title)
: wxFrame(NULL, wxID_ANY, title)
{
// set the frame icon
SetIcon(wxICON(sample));
#if wxUSE_MENUBAR
// create a menu bar
wxMenu *fileMenu = new wxMenu;
// the "About" item should be in the help menu
wxMenu *helpMenu = new wxMenu;
helpMenu->Append(Minimal_About, "&About\tF1", "Show about dialog");
fileMenu->Append(Minimal_Quit, "E&xit\tAlt-X", "Quit this program");
// now append the freshly created menu to the menu bar...
wxMenuBar *menuBar = new wxMenuBar();
menuBar->Append(fileMenu, "&File");
menuBar->Append(helpMenu, "&Help");
// ... and attach this menu bar to the frame
SetMenuBar(menuBar);
#else // !wxUSE_MENUBAR
// If menus are not available add a button to access the about box
wxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
wxButton* aboutBtn = new wxButton(this, wxID_ANY, "About...");
aboutBtn->Bind(wxEVT_BUTTON, &MyFrame::OnAbout, this);
sizer->Add(aboutBtn, wxSizerFlags().Center());
SetSizer(sizer);
#endif // wxUSE_MENUBAR/!wxUSE_MENUBAR
#if wxUSE_STATUSBAR
// create a status bar just for fun (by default with 1 pane only)
CreateStatusBar(2);
SetStatusText("Welcome to wxWidgets!");
#endif // wxUSE_STATUSBAR
}
// event handlers
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
{
// true is to force the frame to close
Close(true);
}
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{
wxMessageBox(wxString::Format
(
"Welcome to %s!\n"
"\n"
"This is the minimal wxWidgets sample\n"
"running under %s.",
wxVERSION_STRING,
wxGetOsDescription()
),
"About wxWidgets minimal sample",
wxOK | wxICON_INFORMATION,
this);
}
Use the source, Luke!
-
- Ultimate wxWidgets Guru
- Posts: 670
- Joined: Tue Jul 26, 2016 2:00 pm
Re: Set focus on button - focuses two buttons
Maybe I'll have to explain:
What I want to is the following: In the window there is a listbox which shows printers of different schools. To the left of the box there are 5 buttons where you can change the school so that only these printers are shown in the box. What I want is that the buttons stay highlighted even if I select the printers in the listbox. No other button should be highlighted during this time. But I see the behavior that the focus changes to another button (the one I made default) whenever I click an item in the listbox. If I push the "Add" button this one is highlighted. That would be okay. But what would be best is: Whenever I check item in the listbox the "Add" button should get highlighted. Whenever I check an item in the second listbox (which contains the added printers) the "Delete" button should be highlighted. And all the time the button telling the school should remain highlighted as well.
Hope that isn't too complicated
Here is a picture of my window (in the previous post I only had one listbox):
What I want to is the following: In the window there is a listbox which shows printers of different schools. To the left of the box there are 5 buttons where you can change the school so that only these printers are shown in the box. What I want is that the buttons stay highlighted even if I select the printers in the listbox. No other button should be highlighted during this time. But I see the behavior that the focus changes to another button (the one I made default) whenever I click an item in the listbox. If I push the "Add" button this one is highlighted. That would be okay. But what would be best is: Whenever I check item in the listbox the "Add" button should get highlighted. Whenever I check an item in the second listbox (which contains the added printers) the "Delete" button should be highlighted. And all the time the button telling the school should remain highlighted as well.
Hope that isn't too complicated
Here is a picture of my window (in the previous post I only had one listbox):
Re: Set focus on button - focuses two buttons
Usually one would use wxRadioButtons for this.What I want is that the buttons stay highlighted even if I select the printers in the listbox. No other button should be highlighted during this time.
You could also use another wxListBox.
Both solutions would also make it easier to add or remove a school at a later time.
Use the source, Luke!
-
- Ultimate wxWidgets Guru
- Posts: 670
- Joined: Tue Jul 26, 2016 2:00 pm
Re: Set focus on button - focuses two buttons
Hm, I don't have the time to overdesign the wxDialog. I have to do other things and have the program finished by tonight. So I guess I'll just leave it as it is.