Home » C# Programming

writing messages to textBox

i have created a windows form application which includes a from and a class .

the form include a textBox to whom i'm writing messages through some process.

Form1.cs looks someting like this -



delegatevoidsetStatusCallBack(String str);


publicvoid setStatus(String str)


txtControl.Text = 



private void someMethod()




Class1 cls=new Class1();




and Class1 looks like-

class Class1



privatesetStatusCallBack callback;

public void OtherMethod()

{ //doing something

callback("some message");



the problem is that all the messages appears in the textBox after the application finish to do everything.

i wan't the messages to appears through the process.

meaning i want first thing to see the message "start." and the the application to do it's work and only then to see "some message".

how can  i do that? why it's not working as it is?

thanks in advance. 


4 Answers Found


Answer 1

Welcome to MSDN Forums.

You can use Application.DoEvents (http://msdn.microsoft.com/en-us/library/system.windows.forms.application.doevents.aspx) whenever you need to refresh GUI.




Answer 2

I am not very sure about this but can you try this:




txtControl.Text = 





Answer 3

thanks , it's working now

Answer 4

You are most welcome :)

Please mark the post an answer that solved your issue.



How do I read text from a textbox and write the text in another application?

I'm using Windows Form as my GUI with a textBox. I wish to know that any method to read the text the user input and output it in another application. I'm making a dll to inject into the certain program.




If I have a couple of buttons and the output of these buttons is displayed in a double lined textbox. The output is always diplayed in the top line. How can I make sure that the input is displayed in the bottom line?

Thankts in advance,



Hi how do I insert the textbox values to a datatable,using insert command. Later I need to update the datatable values to my database db5.mdb . (Options >>Dataset also preferred instead of datatable)


Thanks in Advance.


I want to write one text character to a textbox control on a Windows Form application.  I have tried this and it doesn't work.

TextBox13.Text = "5"
Suggestion?  (I using VB2010.)

How to write French accent characters such as - é - in ASP/HTML text box? I can copy and paste it in the text box like I did now - so there is nothing wrong with the encoding - but the problem is how to type it (write it!).

I also know that é in HTML mean é but cant know how this may help!

Appreciate your help! Thanks,


Hi all,

I want to write text in a textbox and then sent it on serialport. Text may have some control caracter like \001B <ESC> or \0002 <STX>. I'm not able to write \u001B, VisualStudio change that string for \\u001B so my program only send ascii caracter. I use VS2010

Any idea?



I have developed a sizeable Wpf application to target the XP Tablet PC 2005, running on a UMPC. However I have hit a serious issue with the TextBox MaxLength property when using the Tablet Input panel to input hand writing recognition to my application.

When using keyboard or Input Panel text input, the MaxLength property is enforced as you might expect. However if the writing pad is used and the MaxLength is exceeded an Exception of type 'System.ExecutionEngineException' is thrown, and the application terminates.

Code Snippet

<TextBox Name="textBox1" MaxLength="25" />

I have built a simple test application to demonstrate that the problem is not isolated to my particular application.

I would be grateful if anyone has any ideas as I can't think of a workaround .


Ian Bates

please help me in writing ip address in textbox of vb 2008.

Hi All

I'm trying to write the contents of a TextBox to a file but can't seem to find the right method.

Whats wrong with this code?

Dim FileName AsHtmlGenericControl = TryCast(DetailsView1.FindControl("TextBox2"), HtmlGenericControl)

Dim newFilePath AsString = Server.MapPath("/myXML/" + FileName.InnerHtml)

If I replace FileName.InnerHtml with "myXML.xml" it works.

What am I misunderstanding?


I have a  RadgridView having in which  textbox & Time pickerare placed in first & second Columns  written in CellEdit template of radgrid view in silverlight .now i want to update them, for which i want to find cotrol of textboxes and Time picker's values in  rad grid view ,how to find their control or access their values.
what code can i use to write in Georgian language?

Got a question. I got a browse button to work, but now I need that the file selected gives information.

The Browse button code:

Dim dlg AsNew Microsoft.Win32.OpenFileDialog()
    dlg.FileName = "File"
    dlg.DefaultExt = ".txt"' Default file extension
    dlg.Filter = "Text documents (.txt)|*.txt"Dim result? AsBoolean = dlg.ShowDialog()

    If result = TrueThenDim filename AsString = dlg.FileName

What I need, are the first 3 lines in that file. Its a .txt.

Line 1 goes to Textbox1.text

Line 2 goes to Textbox2.text

Line 3 goes to Textbox3.text

How to do that?


Hi all

I have created a WCF service.

using System.Diagnostics;
public class TestService : ITest

public int Add(int a, int b){

Trace.WriteLine("Start in Add Method");

//Trace.TraceWarning("Test Information23");
// Trace.TraceInformation("InfoTrace");

int c = a+b;

Trace.WriteLine("End in Add Method");
return c;

I am calling this method from aspx page.

It also generates Test.csvLog file but I didn't find any message that i have written in Trace.WriteLine Method .

Following are my settings in web.config file of WCF service

      <source name="System.ServiceModel"
             propagateActivity="true" >
          <add name="xml"/>
      <source name="myUserTraceSource"
              switchValue="Warning, ActivityTracing">
          <add name="xml"/>
      <add initializeData="C:\logs\Test.svclog " type="System.Diagnostics.XmlWriterTraceListener"
        name="xml" />
    <trace autoflush="true" />

    <diagnostics wmiProviderEnabled="true">

My Question

1. I want to write my custom message in trace file?
2.  How do I check trace is enabled in WCF service?




I am trying to write in Event Log on windows 2008 server with a windows service application. But I got this error:

Service cannot be started. System.ComponentModel.Win32Exception: The parameter is incorrect at System.Diagnostics.EventLog.InternalWriteEvent(UInt32 eventID, UInt16 category, EventLogEntryType type, String[] strings, Byte[] rawData, String currentMachineName) at System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData) at System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType type) at Siemens.SHS.Utilities.Common.LogManager.LogToEvent(String pLogName, String pSource, String logEntry, EventLogEntryType type) at Siemens.SHS.PEP.TaskCore.StartTask(String pPluginFilePath) at Siemens.SHS.PEP.TaskCore.RecurseStart(String pPluginPath) at Siemens.SHS.PEP.TaskCore.RecurseStart(String pPluginPath) at Siemens.SHS.PEP.TaskCore.StartTasks() at Siemens.SHS.PEP.PlugnExecute.OnStart(String[] args) at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object state)

How can I write to Event Log on x64 platform as Windows 2008 server?

Any help appreciated, thanks in advance,




We are trying to leverage FileStream feature in Sql Server 2008 to  implement attachment functionality in our application.  We use streaming API (SQLFileStream) to read and write files to Sql Storage from WCF service and service runs under domain account.  Unless this service account is given sysadmin privileges on Sql Server , write operation fails. It is actually the following line which opens the stream for writing fails with “Access denied exception”.

 SqlFileStream objSqlFileStream = newSqlFileStream(path, objContext, FileAccess.Write);

Steps tried:

1) Service account is given read/write access as well db_owner on the database where file stream table/columns reside

2) Service account is part of database role which has access to the attachment table containing the file stream columns.

3) Service account is given full control to the File Stream folder on the database server

Environment details:

Sql Server is running on Windows 2008 R2

Sql Server build/version: 10.0.2531

Server is up to date on Windows updates.

Note: Read operation is successful without giving sysadmin rights for the accounts. It is only when the stream is opened for write it fails and once sysadmin rights are granted, it works.

I would like to know what permissions are required for the service account to successfully upload the files (except sysadmin rights). It is not possible to give sysadmin rights for the account in production environment.




I've come across something strange and can't quite figure out what could be going wrong. I have a windows service which processes queue items in a threadpool (default 5 threads).

So, during testing, i "debug, start new instance" and spin up about 4-5 instances of the service, and on average there is about 25 threads going at same time.

My trace code:
Trace.WriteLineIf(traceOutput.TraceVerbose, string.Format("processing Item for {0}", item.id));


this seems to work for a while and writes the trace code to the output window, but after a while, the trace output just stops being output to the window.. has anyone else experienced this before or could know what might be going wrong?





Hello again,

My basics:

Multiple receive locations where BTS receives messages in different formats (xml or flat file) and disassemble it. One send port with WCF-SQL adapter which puts messages into database. In send pipeline I have xml Assembler component which wraps message in OutboxInsert.xsd schema. Also I have custom transformation component which transforms OutboxInser to InsertOutboxMessage.xsd generated for WCF-SQL adapter

As you can see flat file messages stores in database as xml data. Now I have a requirement to store flat files in native format.

Do you have any thoughts how I can modify existing design for this?

Thanks a lot.


I am trying to set up a basic text box validator, but I'm getting an error message that I can't explain.


<TextBox x:Name="Box">
      <Binding Path="ValueInBox" UpdateSourceTrigger="PropertyChanged">
            <local:TestValidation Min="0.5" Max="10"/>


I am getting an error message that says

'System.Windows.Controls.TextBox.Text' property has already been set and can be set only once.

As you can see I'm not setting the text property on the TextBox twice. Can anyone help me out with this?





I want to write a program to track clipboard content, and list them in a customized list box  one by one.

I follow sample in thread: http://social.msdn.microsoft.com/Forums/en/wpf/thread/df74a24e-d06c-4fe1-b303-3d7135289493 to track clipboard.

But I find that if I copy text from a WPF TextBox, WM_DRAWCLIPBOARD message are received twice, while if  Winform TextBox, it  is only once.

This is really a trouble, because I don't want user to see such scenario: press Ctrl+C when focusing WPF textBox, then my listBox will have 2 items with same content.

Investigate more, I see that Clipboard.SetText(string text) always trigger this message twice.  Debug more with help of Reflector, root cause is in Clipboard.CriticalSetDataObject. This method invokes OleServicesContext.CurrentOleServicesContext.OleSetClipboard and OleServicesContext.CurrentOleServicesContext.OleFlushClipboard , and each of them can trigger WM_DRAWCLIPBOARD message.

I tried on Win7(x64) & WinXp, .NetFx35 and .NetFX40, they all happen.

Is this by design? Is there anyway to workaround this?

Thanks a lot.




i don't know, how to make change maxlength in textbox with change a written in textbox?
for example: i have 1 textbox, and 1 button then in textbox i set maxlength=10.
i write in textbox 10 character, tehn i click textbox, maxlength in textbox set 5 and text in textbox change be 5 character (10 disappear into 5)

please give me solution?



<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure