Click here to Skip to main content
15,944,136 members
Home / Discussions / C#
   

C#

 
AnswerRe: Manipulating controls in C#2005 Pin
Bekjong9-Jan-07 1:40
Bekjong9-Jan-07 1:40 
GeneralRe: Manipulating controls in C#2005 Pin
Mr.Sam9-Jan-07 2:13
Mr.Sam9-Jan-07 2:13 
GeneralRe: Manipulating controls in C#2005 Pin
Bekjong9-Jan-07 2:23
Bekjong9-Jan-07 2:23 
GeneralRe: Manipulating controls in C#2005 Pin
Mr.Sam9-Jan-07 2:49
Mr.Sam9-Jan-07 2:49 
GeneralRe: Manipulating controls in C#2005 Pin
Bekjong9-Jan-07 2:59
Bekjong9-Jan-07 2:59 
AnswerRe: Manipulating controls in C#2005 Pin
Luc Pattyn9-Jan-07 2:12
sitebuilderLuc Pattyn9-Jan-07 2:12 
GeneralRe: Manipulating controls in C#2005 Pin
Mr.Sam9-Jan-07 2:19
Mr.Sam9-Jan-07 2:19 
GeneralRe: Manipulating controls in C#2005 Pin
Luc Pattyn9-Jan-07 2:38
sitebuilderLuc Pattyn9-Jan-07 2:38 
Hi,

assume a text editor with most operations running on main (= UI) thread, but with search capabilities running on a background thread. When search thread has found what it was
looking for, it calls UpdateSelection() methode to update several things in the user
interface.

Since UpdateSelection is not called from UI thread and needs to access some
controls, we make it such that it calls itself again, this time on UI thread:

public delegate void UpdateSelectionDelegate(int start, int length);
private TextBox textBox;
private MenuItem menuCopy;
private MenuItem menuCut;
 
public void UpdateSelection(int start, int length) {
	if (InvokeRequired) {
		// this method calls itself, in order for it run on UI thread
		Invoke(new UpdateSelectionDelegate(UpdateSelection),
			new object[]{start, length});
	} else {
		// adjust here whatever control needs updated on the user interface
		textBox.Select(start, length);
		menuCopy.Enabled=length!=0;
		menuCut.Enabled=length!=0;
	}
}


In the example three controls get updated by implementing and executing only one Invoke.

Smile | :)






Luc Pattyn

GeneralRe: Manipulating controls in C#2005 Pin
Mr.Sam9-Jan-07 2:51
Mr.Sam9-Jan-07 2:51 
GeneralRe: Manipulating controls in C#2005 Pin
Luc Pattyn9-Jan-07 4:05
sitebuilderLuc Pattyn9-Jan-07 4:05 
QuestionContextSwitchDeadlock Pin
Nooie8-Jan-07 21:46
Nooie8-Jan-07 21:46 
AnswerRe: ContextSwitchDeadlock Pin
Stefan Troschuetz8-Jan-07 22:29
Stefan Troschuetz8-Jan-07 22:29 
GeneralRe: ContextSwitchDeadlock Pin
Nooie8-Jan-07 22:38
Nooie8-Jan-07 22:38 
AnswerRe: ContextSwitchDeadlock Pin
Nooie9-Jan-07 17:41
Nooie9-Jan-07 17:41 
QuestionDevExpress ApplicationMenu - Status Ba Pin
John S Mangam8-Jan-07 21:32
John S Mangam8-Jan-07 21:32 
AnswerRe: DevExpress ApplicationMenu - Status Ba Pin
Pete O'Hanlon8-Jan-07 23:09
mvePete O'Hanlon8-Jan-07 23:09 
GeneralRe: DevExpress ApplicationMenu - Status Ba Pin
John S Mangam9-Jan-07 0:45
John S Mangam9-Jan-07 0:45 
QuestionDevExpress ApplicationMenu - Status Ba Pin
John S Mangam8-Jan-07 21:28
John S Mangam8-Jan-07 21:28 
QuestionSetSystemTime Return Parameters Pin
Tyler458-Jan-07 20:52
Tyler458-Jan-07 20:52 
AnswerRe: SetSystemTime Return Parameters Pin
Mircea Puiu8-Jan-07 22:35
Mircea Puiu8-Jan-07 22:35 
QuestionRe: SetSystemTime Return Parameters Pin
alefaga8-May-09 4:56
alefaga8-May-09 4:56 
AnswerRe: SetSystemTime Return Parameters Pin
Tyler458-May-09 4:59
Tyler458-May-09 4:59 
QuestionSending Email in .Net 2.0 Pin
Sarika Wake8-Jan-07 20:35
Sarika Wake8-Jan-07 20:35 
AnswerRe: Sending Email in .Net 2.0 Pin
Chris Buckett8-Jan-07 22:04
Chris Buckett8-Jan-07 22:04 
QuestionMIME Type in c# Pin
aruna_koride8-Jan-07 19:15
aruna_koride8-Jan-07 19:15 

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.