Click here to Skip to main content
15,917,005 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: Floating point error in .NET Pin
Nick Parker10-Feb-04 8:35
protectorNick Parker10-Feb-04 8:35 
GeneralRe: Floating point error in .NET Pin
Colin Angus Mackay10-Feb-04 12:47
Colin Angus Mackay10-Feb-04 12:47 
GeneralRe: Floating point error in .NET Pin
Nick Parker10-Feb-04 8:33
protectorNick Parker10-Feb-04 8:33 
GeneralDatabase connectivity for J# browser Controls Pin
8-Feb-04 23:08
suss8-Feb-04 23:08 
GeneralReal Time Loops in Managed C++ .NET Pin
Tank_Aviator8-Feb-04 11:49
Tank_Aviator8-Feb-04 11:49 
GeneralProblems with a text box & changing alignment in the leave event. Pin
adarobwpg7-Feb-04 21:03
adarobwpg7-Feb-04 21:03 
GeneralRe: Problems with a text box & changing alignment in the leave event. Pin
Gerald Leslie Jones10-Feb-04 1:32
Gerald Leslie Jones10-Feb-04 1:32 
GeneralRe: Problems with a text box & changing alignment in the leave event. Pin
Steve S10-Feb-04 1:40
Steve S10-Feb-04 1:40 
At a guess, the alignment is set to right by default, but on editing is set to left, then back to right in the leave event (somewhat erroneously).

The problem is most likely with the order of events.

When using the keyboard, the events are fired in the following order:
Enter
GotFocus (user enters data)
Leave (user has tabbed away)
Validating
Validated
LostFocus

When you use the mouse or call the Focus method, the events are fired in the following order:
Enter
GotFocus (user enters data)
LostFocus (user clicks on other control)
Leave
Validating
Validated

So, if you handle the Enter and LostFocus events, what you want works when using the keyboard. If you use the likely pairs together (like Enter and Leave), when you change the TextAlign property the handle for the text control is recreated. If it had the focus (which for keyboard events, it still does) the focus is again set to the TextBox.

The trick is to change the alignment at the correct time based on whether or not a mouse button was clicked:

// Hook-up event handlers.

myTextBox.Enter += new EventHandler(myTextBox_Enter);
myTextBox.Leave += new EventHandler(myTextBox_Leave);
myTextBox.LostFocus += new EventHandler(myTextBox_LostFocus);
// Handle events.
private void myTextBox_Enter(object sender, EventArgs e)
{
myTextBox.TextAlign = HorizontalAlignment.Left;
}
private void myTextBox_Leave(object sender, EventArgs e)
{
if (Control.MouseButtons != MouseButtons.None)
myTextBox.TextAlign = HorizontalAlignment.Right;
}
private void myTextBox_LostFocus(object sender, EventArgs e)
{
if (Control.MouseButtons == MouseButtons.None)
myTextBox.TextAlign = HorizontalAlignment.Right;
}


Hope this helps

Steve S
(One of these days I really must start using this stuff properly...)
GeneralProblem setting enum field value using Remoting Pin
claughlin6-Feb-04 6:16
claughlin6-Feb-04 6:16 
GeneralRe: Problem setting enum field value using Remoting Pin
Gerald Leslie Jones10-Feb-04 1:23
Gerald Leslie Jones10-Feb-04 1:23 
GeneralRe: Problem setting enum field value using Remoting Pin
ClarkLaughlin10-Feb-04 5:15
ClarkLaughlin10-Feb-04 5:15 
GeneralProblems with the .Net forms designer Pin
Christian Skovdal Andersen6-Feb-04 1:55
Christian Skovdal Andersen6-Feb-04 1:55 
Generalmaking a slow progam run faster Pin
Tank_Aviator5-Feb-04 19:31
Tank_Aviator5-Feb-04 19:31 
GeneralRe: making a slow progam run faster Pin
Corinna John8-Feb-04 21:27
Corinna John8-Feb-04 21:27 
GeneralRaw Sockets with TCP in C# Pin
Andy *M*5-Feb-04 13:00
Andy *M*5-Feb-04 13:00 
GeneralGUID_NULL identifier not found error... Pin
adonisv5-Feb-04 9:51
adonisv5-Feb-04 9:51 
GeneralWhy no more CDaoRecordset Class Wizard Pin
harwanegg4-Feb-04 22:37
harwanegg4-Feb-04 22:37 
GeneralRe: Why no more CDaoRecordset Class Wizard Pin
Steve S10-Feb-04 1:35
Steve S10-Feb-04 1:35 
GeneralPerformance Issues with C++ .NET Pin
Tank_Aviator4-Feb-04 11:09
Tank_Aviator4-Feb-04 11:09 
GeneralRe: Performance Issues with C++ .NET Pin
Roman Rodov11-Feb-04 14:50
Roman Rodov11-Feb-04 14:50 
GeneralComboBox SelectedIndex Pin
Mike Osbahr4-Feb-04 8:08
Mike Osbahr4-Feb-04 8:08 
GeneralRe: ComboBox SelectedIndex Pin
Gerald Leslie Jones8-Feb-04 23:41
Gerald Leslie Jones8-Feb-04 23:41 
GeneralCompact Framework and Remoting Pin
Bertrand Boichon4-Feb-04 6:20
Bertrand Boichon4-Feb-04 6:20 
GeneralSimple Problem With ListBoxes Pin
Pugman8123-Feb-04 17:31
Pugman8123-Feb-04 17:31 
GeneralRe: Simple Problem With ListBoxes Pin
John Kuhn3-Feb-04 19:19
John Kuhn3-Feb-04 19:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.