Page 1 of 1

How can I make sure textctrl auto scrolling?

Posted: Thu May 26, 2005 11:53 am
by rayam
Vectical scroll bar of a muitline line wxTextCtrl disappeared after SetValue(); How can I make it show the v-scroll bar again?

Re: How can I make sure textctrl auto scrolling?

Posted: Fri May 27, 2005 10:30 pm
by Ryan Norton
rayam wrote:Vectical scroll bar of a muitline line wxTextCtrl disappeared after SetValue(); How can I make it show the v-scroll bar again?
Try refreshing it afterwards - also try adding the wxALWAYS_SHOW_SB to the window flags on its creation if you always want the scrollbars

Re: How can I make sure textctrl auto scrolling?

Posted: Mon May 30, 2005 8:12 am
by rayam
Ryan Norton wrote:
rayam wrote:Vectical scroll bar of a muitline line wxTextCtrl disappeared after SetValue(); How can I make it show the v-scroll bar again?
Try refreshing it afterwards - also try adding the wxALWAYS_SHOW_SB to the window flags on its creation if you always want the scrollbars
Thanks to Ryan!
But, I found that the problem is caused by the flat wxTE_AUTO_URL.
The following programme have two wxtextctrls with one have auto url style added. It shows that the v-scroll bar will not display properly after several clicking the button. May be it is just the problem of window's native dll.
I have BCC55, wxAll255 in windowXP.

Code: Select all

#include <wx/wxprec.h>

#ifdef __BORLANDC__
    #pragma hdrstop
#endif

#ifndef WX_PRECOMP
    #include <wx/wx.h>
#endif
#include <wx/splitter.h>

//
// MyFrame
//

class MyFrame: public wxFrame{
public:

  MyFrame(wxFrame *frame, const wxString& title);
  ~MyFrame();

private:

  wxTextCtrl* m_text;
  wxTextCtrl* m_text1;
  wxButton* m_button;
  wxPanel* m_panel; 

  void OnQuit(wxCommandEvent& event);
  void OnAbout(wxCommandEvent& event);
  void OnClick(wxCommandEvent& event);
  void OnClick1(wxCommandEvent& event);

//  
  DECLARE_EVENT_TABLE()
};

int idMenuQuit = wxNewId();
int idMenuAbout = wxNewId();
int idButton = wxNewId();

BEGIN_EVENT_TABLE(MyFrame, wxFrame)
  EVT_MENU(idMenuQuit, MyFrame::OnQuit)
  EVT_MENU(idMenuAbout, MyFrame::OnAbout)
  EVT_BUTTON(idButton, MyFrame::OnClick)
END_EVENT_TABLE()

MyFrame::MyFrame(wxFrame *frame, const wxString& title)
 : wxFrame(frame, -1, title){
  wxMenuBar* mbar = new wxMenuBar();
  wxMenu* fileMenu = new wxMenu("");
  fileMenu->Append(idMenuQuit, _("&Quit\tAlt-F4"), _("Quit the application"));
  mbar->Append(fileMenu, _("&File"));

  wxMenu* helpMenu = new wxMenu("");
  helpMenu->Append(idMenuAbout, _("&About\tF1"), _("Show info about this application"));
  mbar->Append(helpMenu, _("&Help"));
 
  SetMenuBar(mbar);
  m_panel=new wxPanel(this, -1);
  m_button=new wxButton(m_panel, idButton, "Test", wxPoint(1,1), wxSize(100,20));
  m_text=new wxTextCtrl(m_panel, -1, "", wxPoint(1,25), wxSize(180,150), wxTE_MULTILINE + wxTE_RICH + wxTE_AUTO_URL);
  m_text1=new wxTextCtrl(m_panel, -1, "", wxPoint(185,25), wxSize(180,150), wxTE_MULTILINE + wxTE_RICH);

}


MyFrame::~MyFrame(){
}

void MyFrame::OnQuit(wxCommandEvent& event){
  Close();
}

void MyFrame::OnAbout(wxCommandEvent& event){
  wxMessageBox(_("wxWindows Application Template"), _("Welcome to..."));
}

static int flag;
void MyFrame::OnClick(wxCommandEvent& event){
  if (flag%2) {
    m_text->SetValue("1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19");
    m_text1->SetValue("1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19");

  }
  else {
    m_text->SetValue("");
    m_text1->SetValue("");
  }
  flag++;
}


//
// MyApp
//

class MyApp : public wxApp {
public:
  virtual bool OnInit();
};
IMPLEMENT_APP(MyApp);

bool MyApp::OnInit(){
  MyFrame* frame = new MyFrame(0L, _("wxWindows Application Template"));
  frame->Show();
  return true;
}