Don't insert new line on clicking outside the editor window

I have a Syncfusion EditControl in a winforms application. Whenever I click outside the editor window, it inserts a new line in the editor and moves the cursor position to the end of the line. I need to disable this behavior as I want to insert certain text from another control to wherever the cursor was on the editor, not necessarily on the new line. 
 
I looked at the api of EditControl, and I am able to trigger an event handler for CursorPositionChanged event. However, it doesn't tell me how/when that event was triggered. I don't see any other methods/properties which would disable this behaviour. 

TL;DR: I don't want to insert a new line when user clicks outside the editor control window. Is this possible? Thanks! 

3 Replies

VR Venkateshwaran Ramdoss Syncfusion Team July 10, 2018 12:15 PM UTC

Hi Akshay, 
 
Thank you for contacting Syncfusion Support. 
 
Query 1: Whenever I click outside the editor window, it inserts a new line in the editor and moves the cursor position to the end of the line I want to insert certain text from another control to wherever the cursor was on the editor, not necessarily on the new line.  
 
We suspect that you are using AppendText method to insert the text. It will append the specified text to the end of the existing content of the EditControl. Please refer the below link for more details about AppendText method. 
 
 
We can achieve your requirement using InsertText method. We have prepared a sample for your reference. In this, we have used InsertText method and get the current position of the Cursor using current line and current column. Please refer the below code snippet. 
 
Code snippet 
 
this.editControl1.InsertMode = true; 
 
this.editControl1.InsertText(this.editControl1.CurrentLine, this.editControl1.CurrentColumn, "Inserting Text"); 
 
// Toggle the insert mode. 
this.editControl1.ToggleInsertMode(); 
 
Please refer the below link for more details about InsertText method. 
 
 
 
Query 2: I looked at the api of EditControl, and I am able to trigger an event handler for CursorPositionChanged event. However, it doesn't tell me how/when that event was triggered. I don't see any other methods/properties which would disable this behaviour. 
 
The CursorPositionChanged event will be triggered when the cursor position changed. Please refer the below link for the same. 
 
 
And this event can be disabled by return it. Please find the code snippet for the same in the below.  
 
Code snippet 
 
this.editControl1.CursorPositionChanged += EditControl1_CursorPositionChanged; 
 
private void EditControl1_CursorPositionChanged(object sender, EventArgs e) 
{ 
     return; 
} 
 
We have prepared a sample for your reference and it can be downloaded from the below link. 
 
 
Please check the above solution and let us know if it is helpful. 
 
Regards, 
Venkateshwaran V.R. 
 
 
 
 



AK Akshay Khot July 10, 2018 07:57 PM UTC

Hi Venkateshwaran,

Thank you for your prompt reply. I am using InsertText() method, as you show in your example. However, the problem is not appending/inserting at wrong position. 

The problem is this:
  1. I have cursor on a random position in the editor, 
  2. I need to add text on the editor by double-clicking a control(located outside the editor)
  3. I click on the control, and at the same time the editor moves the cursor to the end location
  4. So even if I use the snippet provided by you, it will get the current cursor position, which is now at the end, and insert text at the end, resulting in the same behavior as Append. 
I need to prevent  the editor from moving the cursor to the new line, when I click outside the editor. 

However, I was able to get around this problem by storing the last cursor position by attaching a handler on control_click. 
So, whenever user clicks on the editor, I store the cursor position. When I need to insert text, I use this last position, instead of the current position(which was moved to the end of the editor)

So effectively this problem is solved. Thank you for your help. 


VR Venkateshwaran Ramdoss Syncfusion Team July 11, 2018 08:52 AM UTC

Hi Akshay, 

Thank you for your update. 

We are glad that your problem has been resolved at your end. Please follow up the incident created under your name for more details. Please log on to our support website to check for further updates. 


Regards, 
Venkateshwaran V.R. 


Loader.
Up arrow icon