wx.TextCtrl Class Reference

Inheritance diagram for wx.TextCtrl:

wx.Control wx.Window wx.EvtHandler wx.Object wx.MaskedEdit.DateTimeEdit wx.MaskedEdit.MaskedEdit

List of all members.

Public Member Functions

void AppendFormat (string format, params object[] args)
void AppendText (wxString text)
void AppendText (string text)
bool CanCopy ()
bool CanCut ()
bool CanPaste ()
bool CanRedo ()
bool CanUndo ()
void Clear ()
void Copy ()
void Cut ()
void DiscardEdits ()
bool EmulateKeyPress (KeyEvent evt)
bool Enable (bool enable)
override void Freeze ()
TextAttr GetDefaultStyle ()
int GetLastPosition ()
string GetLineText (int lineNo)
int GetNumberOfLines ()
string GetRange (int from, int to)
void GetSelection (out int from, out int to)
bool GetStyle (int position, ref TextAttr style)
TextCtrlHitTestResult HitTest (Point pt, out int col, out int row)
TextCtrlHitTestResult HitTest (Point pt, out int pos)
int LineLength (int lineNo)
bool LoadFile (wxString file)
bool LoadFile (string file)
bool LoadFileNET (string file)
void MarkDirty ()
virtual void OnDropFiles (Event evt)
void Paste ()
System.Drawing.Point PositionToXY (int pos)
bool PositionToXY (int pos, out int x, out int y)
void Redo ()
void Remove (int from, int to)
void Replace (int from, int to, wxString value)
void Replace (int from, int to, string value)
bool SaveFile (wxString file)
bool SaveFile (string file)
bool SaveFileNET (string file)
override bool ScrollLines (int lines)
override bool ScrollPages (int pages)
void SelectAll ()
bool SetDefaultStyle (TextAttr style)
void SetEditable (bool editable)
void SetInsertionPointEnd ()
void SetSelection (int from, int to)
bool SetStyle (int start, int end, TextAttr style)
void ShowPosition (int pos)
 TextCtrl (Window parent, string value, Point pos, Size size, uint style, string name)
 TextCtrl (Window parent, string value, Point pos, Size size)
 TextCtrl (Window parent, string value, Point pos, Size size, WindowStyles style)
 TextCtrl (Window parent, string value)
 TextCtrl (Window parent, int id, wxString value, Point pos, Size size, WindowStyles style, wxString name)
 TextCtrl (Window parent, int id, string value, Point pos, Size size, WindowStyles style, string name)
 TextCtrl (Window parent, int id, string value, Point pos, Size size)
 TextCtrl (Window parent, int id, string value, Point pos, Size size, WindowStyles style)
 TextCtrl (Window parent, int id, string value)
 TextCtrl (Window parent, int id)
 TextCtrl (Window parent)
 TextCtrl (IntPtr wxObject)
override void Thaw ()
void Undo ()
void WriteText (wxString text)
void WriteText (string text)
int XYToPosition (System.Drawing.Point position)
int XYToPosition (int x, int y)

Properties

override Colour BackgroundColour [get, set]
override Font Font [get, set]
override Colour ForegroundColour [get, set]
int InsertionPoint [get, set]
bool IsEditable [get]
bool IsModified [get]
bool IsMultiLine [get]
bool IsSingleLine [get]
int MaxLength [set]
string Value [get, set]

Events

event EventListener Enter [add, remove]
override event
EventListener 
UpdateUI [add, remove]


Detailed Description

Control to display and edit text.

wxTE_PROCESS_ENTERThe control will generate the event wxEVT_COMMAND_TEXT_ENTER (otherwise pressing Enter key is either processed internally by the control or used for navigation between dialog controls).
wxTE_PROCESS_TABThe control will receive wxEVT_CHAR events for TAB pressed - normally, TAB is used for passing to the next control in a dialog instead. For the control created with this style, you can still use Ctrl-Enter to pass to the next control from the keyboard.
wxTE_MULTILINEThe text control allows multiple lines.
wxTE_PASSWORDThe text will be echoed as asterisks.
wxTE_READONLYThe text will not be user-editable.
wxTE_RICHUse rich text control under Win32, this allows to have more than 64KB of text in the control even under Win9x. This style is ignored under other platforms.
wxTE_RICH2Use rich text control version 2.0 or 3.0 under Win32, this style is ignored under other platforms
wxTE_AUTO_URLHighlight the URLs and generate the wxTextUrlEvents when mouse events occur over them. This style is only supported for wxTE_RICH Win32 and multi-line wxGTK2 text controls.
wxTE_NOHIDESELBy default, the Windows text control doesn't show the selection when it doesn't have focus - use this style to force it to always show it. It doesn't do anything under other platforms.
wxHSCROLLA horizontal scrollbar will be created and used, so that text won't be wrapped. No effect under wxGTK1.
wxTE_LEFTThe text in the control will be left-justified (default).
wxTE_CENTREThe text in the control will be centered (currently wxMSW and wxGTK2 only).
wxTE_RIGHTThe text in the control will be right-justified (currently wxMSW and wxGTK2 only).
wxTE_DONTWRAPSame as wxHSCROLL style: don't wrap at all, show horizontal scrollbar instead.
wxTE_CHARWRAPWrap the lines too long to be shown entirely at any position (wxUniv and wxGTK2 only).
wxTE_WORDWRAP Wrap the lines too long to be shown entirely at word boundaries (wxUniv and wxGTK2 only).
wxTE_BESTWRAP Wrap the lines at word boundaries or at any other character if there are words longer than the window width (this is the default).
wxTE_CAPITALIZE On PocketPC and Smartphone, causes the first letter to be capitalized.

Note that alignment styles (wxTE_LEFT, wxTE_CENTRE and wxTE_RIGHT) can be changed dynamically after control creation on wxMSW and wxGTK. wxTE_READONLY, wxTE_PASSWORD and wrapping styles can be dynamically changed under wxGTK but not wxMSW. The other styles can be only set during control creation.

wx.TextCtrl text format

The multiline text controls always store the text as a sequence of lines separated by
characters, i.e. in the Unix text format even on non-Unix platforms. This allows the user code to ignore the differences between the platforms but at a price: the indices in the control such as those returned by GetInsertionPoint or GetSelection can not be used as indices into the string returned by GetValue as they're going to be slightly off for platforms using "\r\n" as separator (as Windows does), for example.

Instead, if you need to obtain a substring between the 2 indices obtained from the control with the help of the functions mentioned above, you should use GetRange. And the indices themselves can only be passed to other methods, for example SetInsertionPoint or SetSelection.

To summarize: never use the indices returned by (multiline) wxTextCtrl as indices into the string it contains, but only as arguments to be passed back to the other wx.TextCtrl methods.

wx.TextCtrl styles

Multi-line text controls support the styles, i.e. provide a possibility to set colours and font for individual characters in it (note that under Windows wxTE_RICH style is required for style support). To use the styles you can either call SetDefaultStyle before inserting the text or call SetStyle later to change the style of the text already in the control (the first solution is much more efficient).

In either case, if the style doesn't specify some of the attributes (for example you only want to set the text colour but without changing the font nor the text background), the values of the default style will be used for them. If there is no default style, the attributes of the text control itself are used.

So the following code correctly describes what it does: the second call to SetDefaultStyle doesn't change the text foreground colour (which stays red) while the last one doesn't change the background colour (which stays grey):

        text.SetDefaultStyle(wxTextAttr(wx.Colour.wxRED));
        text.AppendText("Red text\n");
        text.SetDefaultStyle(wx.TextAttr(null, wx.Colour.wxLIGHT_GREY));
        text.AppendText("Red on grey text\n");
        text.SetDefaultStyle(wxTextAttr(wx.Colour.wxBLUE);
        text.AppendText("Blue on grey text\n");

Event handling

The following commands are processed by default event handlers in wxTextCtrl: wxID_CUT, wxID_COPY, wxID_PASTE, wxID_UNDO, wxID_REDO. The associated UI update events are also processed automatically, when the control has the focus.

To process input from a text control, use these event handler macros to direct input to member functions that take a wxCommandEvent argument.
EVT_TEXT(id, func)Respond to a wxEVT_COMMAND_TEXT_UPDATED event, generated when the text changes. Notice that this event will be sent when the text controls contents changes - whether this is due to user input or comes from the program itself (for example, if SetValue() is called); see ChangeValue() for a function which does not send this event.
EVT_TEXT_ENTER(id, func)Respond to a wxEVT_COMMAND_TEXT_ENTER event, generated when enter is pressed in a text control (which must have wxTE_PROCESS_ENTER style for this event to be generated).
EVT_TEXT_URL(id, func)A mouse event occurred over an URL in the text control (wxMSW and wxGTK2 only)
EVT_TEXT_MAXLEN(id, func)User tried to enter more text into the control than the limit set by SetMaxLength.


Constructor & Destructor Documentation

wx.TextCtrl.TextCtrl ( IntPtr  wxObject  ) 

wx.TextCtrl.TextCtrl ( Window  parent  ) 

wx.TextCtrl.TextCtrl ( Window  parent,
int  id 
)

wx.TextCtrl.TextCtrl ( Window  parent,
int  id,
string  value 
)

wx.TextCtrl.TextCtrl ( Window  parent,
int  id,
string  value,
Point  pos,
Size  size,
WindowStyles  style 
)

wx.TextCtrl.TextCtrl ( Window  parent,
int  id,
string  value,
Point  pos,
Size  size 
)

wx.TextCtrl.TextCtrl ( Window  parent,
int  id,
string  value,
Point  pos,
Size  size,
WindowStyles  style,
string  name 
)

wx.TextCtrl.TextCtrl ( Window  parent,
int  id,
wxString  value,
Point  pos,
Size  size,
WindowStyles  style,
wxString  name 
)

wx.TextCtrl.TextCtrl ( Window  parent,
string  value 
)

wx.TextCtrl.TextCtrl ( Window  parent,
string  value,
Point  pos,
Size  size,
WindowStyles  style 
)

wx.TextCtrl.TextCtrl ( Window  parent,
string  value,
Point  pos,
Size  size 
)

wx.TextCtrl.TextCtrl ( Window  parent,
string  value,
Point  pos,
Size  size,
uint  style,
string  name 
)


Member Function Documentation

void wx.TextCtrl.AppendFormat ( string  format,
params object[]  args 
)

This appends the expanded format to the text as presented by this control. The format string is due to string.Format().

void wx.TextCtrl.AppendText ( wxString  text  ) 

This appends text to the text presented in the control.

void wx.TextCtrl.AppendText ( string  text  ) 

This appends text to the text presented in the control. Cf. AppendFormat().

bool wx.TextCtrl.CanCopy (  ) 

bool wx.TextCtrl.CanCut (  ) 

bool wx.TextCtrl.CanPaste (  ) 

bool wx.TextCtrl.CanRedo (  ) 

bool wx.TextCtrl.CanUndo (  ) 

void wx.TextCtrl.Clear (  ) 

void wx.TextCtrl.Copy (  ) 

void wx.TextCtrl.Cut (  ) 

void wx.TextCtrl.DiscardEdits (  ) 

bool wx.TextCtrl.EmulateKeyPress ( KeyEvent  evt  ) 

bool wx.TextCtrl.Enable ( bool  enable  ) 

override void wx.TextCtrl.Freeze (  )  [virtual]

Reimplemented from wx.Window.

TextAttr wx.TextCtrl.GetDefaultStyle (  ) 

int wx.TextCtrl.GetLastPosition (  ) 

string wx.TextCtrl.GetLineText ( int  lineNo  ) 

int wx.TextCtrl.GetNumberOfLines (  ) 

string wx.TextCtrl.GetRange ( int  from,
int  to 
)

void wx.TextCtrl.GetSelection ( out int  from,
out int  to 
)

bool wx.TextCtrl.GetStyle ( int  position,
ref TextAttr  style 
)

TextCtrlHitTestResult wx.TextCtrl.HitTest ( Point  pt,
out int  col,
out int  row 
)

TextCtrlHitTestResult wx.TextCtrl.HitTest ( Point  pt,
out int  pos 
)

int wx.TextCtrl.LineLength ( int  lineNo  ) 

bool wx.TextCtrl.LoadFile ( wxString  file  ) 

bool wx.TextCtrl.LoadFile ( string  file  ) 

bool wx.TextCtrl.LoadFileNET ( string  file  ) 

void wx.TextCtrl.MarkDirty (  ) 

virtual void wx.TextCtrl.OnDropFiles ( Event  evt  )  [virtual]

void wx.TextCtrl.Paste (  ) 

System.Drawing.Point wx.TextCtrl.PositionToXY ( int  pos  ) 

bool wx.TextCtrl.PositionToXY ( int  pos,
out int  x,
out int  y 
)

void wx.TextCtrl.Redo (  ) 

void wx.TextCtrl.Remove ( int  from,
int  to 
)

void wx.TextCtrl.Replace ( int  from,
int  to,
wxString  value 
)

void wx.TextCtrl.Replace ( int  from,
int  to,
string  value 
)

bool wx.TextCtrl.SaveFile ( wxString  file  ) 

bool wx.TextCtrl.SaveFile ( string  file  ) 

bool wx.TextCtrl.SaveFileNET ( string  file  ) 

override bool wx.TextCtrl.ScrollLines ( int  lines  )  [virtual]

Scrolls the window by the given number of lines down (if lines is positive) or up.

Parameters:
lines Number of lines to scroll down (positive) or up (negative)
Returns:
Returns true if the window was scrolled, false if it was already on top/bottom and nothing was done.

Reimplemented from wx.Window.

override bool wx.TextCtrl.ScrollPages ( int  pages  )  [virtual]

Scrolls the window by the given number of pages down (if pages is positive) or up.

Parameters:
pages Number of pages to scroll down (positive) or up.
Returns:
This function is currently only implemented under MSW and wxGTK.

Reimplemented from wx.Window.

void wx.TextCtrl.SelectAll (  ) 

bool wx.TextCtrl.SetDefaultStyle ( TextAttr  style  ) 

void wx.TextCtrl.SetEditable ( bool  editable  ) 

void wx.TextCtrl.SetInsertionPointEnd (  ) 

void wx.TextCtrl.SetSelection ( int  from,
int  to 
)

bool wx.TextCtrl.SetStyle ( int  start,
int  end,
TextAttr  style 
)

void wx.TextCtrl.ShowPosition ( int  pos  ) 

override void wx.TextCtrl.Thaw (  )  [virtual]

Reimplemented from wx.Window.

void wx.TextCtrl.Undo (  ) 

void wx.TextCtrl.WriteText ( wxString  text  ) 

void wx.TextCtrl.WriteText ( string  text  ) 

int wx.TextCtrl.XYToPosition ( System.Drawing.Point  position  ) 

int wx.TextCtrl.XYToPosition ( int  x,
int  y 
)


Property Documentation

override Colour wx.TextCtrl.BackgroundColour [get, set]

Reimplemented from wx.Window.

override Font wx.TextCtrl.Font [get, set]

Reimplemented from wx.Window.

override Colour wx.TextCtrl.ForegroundColour [get, set]

Reimplemented from wx.Window.

int wx.TextCtrl.InsertionPoint [get, set]

bool wx.TextCtrl.IsEditable [get]

bool wx.TextCtrl.IsModified [get]

bool wx.TextCtrl.IsMultiLine [get]

bool wx.TextCtrl.IsSingleLine [get]

int wx.TextCtrl.MaxLength [set]

string wx.TextCtrl.Value [get, set]

Reimplemented in wx.MaskedEdit.DateTimeEdit.


Event Documentation

event EventListener wx.TextCtrl.Enter [add, remove]

override event EventListener wx.TextCtrl.UpdateUI [add, remove]

Adds a listener to the wx.Event.wxEVT_UPDATE_UI.

Reimplemented from wx.Window.


Manual of the wx.NET   (c) 2003-2011 the wx.NET project at   Get wx.NET at SourceForge.net. Fast, secure and Free Open Source software downloads