Custom search for AutoCompleteStringCollection - c#

Is there anyway to change the search function for the AutoCompleteStringCollectionclass for the TextBox class? Right now, I have it on the default search function where the beginning letters of my suggestions match the letters of the user input? My suggestions come from a custom source.

You can make your own AutoComplete search - by using TextChange
Here is answer: C# winforms combobox dynamic autocomplete
Code:
string[] data = new string[] {
"Absecon","Abstracta","Abundantia","Academia","Acadiau","Acamas",
"Ackerman","Ackley","Ackworth","Acomita","Aconcagua","Acton","Acushnet",
"Acworth","Ada","Ada","Adair","Adairs","Adair","Adak","Adalberta","Adamkrafft",
"Adams"
};
public Form1()
{
InitializeComponent();
}
private void comboBox1_TextChanged(object sender, EventArgs e)
{
HandleTextChanged();
}
private void HandleTextChanged()
{
var txt = comboBox1.Text;
var list = from d in data
where d.ToUpper().StartsWith(comboBox1.Text.ToUpper())
select d;
if (list.Count() > 0)
{
comboBox1.DataSource = list.ToList();
//comboBox1.SelectedIndex = 0;
var sText = comboBox1.Items[0].ToString();
comboBox1.SelectionStart = txt.Length;
comboBox1.SelectionLength = sText.Length - txt.Length;
comboBox1.DroppedDown = true;
return;
}
else
{
comboBox1.DroppedDown = false;
comboBox1.SelectionStart = txt.Length;
}
}
private void comboBox1_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Back)
{
int sStart = comboBox1.SelectionStart;
if (sStart > 0)
{
sStart--;
if (sStart == 0)
{
comboBox1.Text = "";
}
else
{
comboBox1.Text = comboBox1.Text.Substring(0, sStart);
}
}
e.Handled = true;
}
}

Related

Adding a new line when checking a checkbox

When I click on a checkbox I want the next checkbox information to be displayed on a new line, I know how to do this with "\r\n" however when unchecking the box and rechecking the box, it adds a new line above the text moving the original text down by 1 line. https://imgur.com/a/IHDDG85
I've tried "\r\n" and Environment.NewLine
private void chkHamburger_CheckedChanged(object sender, EventArgs e)
{
if (chkHamburger.Checked == true)
{
txtHamburger.Enabled = true;
txtHamburger.Text = "";
txtHamburger.Focus();
txtOrder.Text += ("Hamburger");
}
else
{
txtHamburger.Enabled = false;
txtHamburger.Text = "0";
}
if (chkHamburger.Checked == false)
{
txtOrder.Text = txtOrder.Text.Replace("Hamburger", "");
}
}
private void chkCheeseBurger_CheckedChanged(object sender, EventArgs e)
{
if (chkCheeseBurger.Checked == true)
{
txtCheeseBurger.Enabled = true;
txtCheeseBurger.Text = "";
txtCheeseBurger.Focus();
txtOrder.Text += ("Cheese Burger");
}
else
{
txtCheeseBurger.Enabled = false;
txtCheeseBurger.Text = "0";
}
if (chkCheeseBurger.Checked == false)
{
txtOrder.Text = txtOrder.Text.Replace("Cheese Burger", "");
}
}
I want the text of a checkbox to be displayed on a new line but when rechecking the box a whitespace should not appear above it.
I suggest you to use a List<string> where you add or remove your orders. Then it is easy to rebuild the txtOrder data with a single line of code using string.Join
List<string> orders = new List<string>();
private void chkHamburger_CheckedChanged(object sender, EventArgs e)
{
txtHamburger.Enabled = chkHamburger.Checked;
if (chkHamburger.Checked)
{
txtHamburger.Text = "";
txtHamburger.Focus();
orders.Add("Hamburger");
}
else
{
txtHamburger.Text = "0";
orders.Remove("Hamburger");
}
UpdateOrders();
}
private void chkCheeseBurger_CheckedChanged(object sender, EventArgs e)
{
txtCheeseBurger.Enabled = chkCheeseBurger.Checked;
if (chkCheeseBurger.Checked)
{
txtCheeseBurger.Text = "";
txtCheeseBurger.Focus();
orders.Add("Cheese Burger");
}
else
{
txtCheeseBurger.Text = "0";
orders.Remove("Cheese Burger");
}
UpdateOrders();
}
private void UpdateOrders()
{
txtOrders.Text = string.Join(Environment.NewLine, orders);
}
The best way to do this is to have a routine that builds the contents of the text independent of what just happened -- this you could use join or a loop to create the text contents.
Make this a function and call it when the check boxes change. The function loops over all your items and adds them to the output with the formatting and totals etc.

No row can be added to a DataGridView control that does not have columns. Columns must be added first.'

So, I'm creating a program to check names of a client. But I get this error.
"No row can be added to a DataGridView control that does not have columns. Columns must be added first.'"
I'm unsure of what to do at this point, as it's all coded correctly. and I just, I don't understand why it's not working. A friend of mine is running the EXACT same code, and his build worked flawlessly.
Here's my code.
private void PopulateDataGrideView(string Name, string Status)
{
if (base.InvokeRequired)
{
base.BeginInvoke(new MethodInvoker(() => {
DataGridViewRow dataGridViewRow = new DataGridViewRow();
if (Status == "Yes")
{
dataGridViewRow.DefaultCellStyle.BackColor = Color.LightGreen;
Status = "Name Available";
}
else if (Status == "No")
{
dataGridViewRow.DefaultCellStyle.BackColor = Color.Red;
Status = "Not Available";
if (this.VisibilityBx.Checked)
{
dataGridViewRow.Visible = false;
}
}
dataGridViewRow.CreateCells(this.checkedNames, new object[] { Name, Status });
this.checkedNames.Rows.Add(dataGridViewRow);
if (scrollBx.Checked)
{
this.checkedNames.FirstDisplayedScrollingRowIndex = this.checkedNames.RowCount - 1;
}
this.progressBar1.Increment(1);
}));
}
}
private void saveAvailableNamesToolStripMenuItem_Click(object sender, EventArgs e)
{
List<string> strs = new List<string>();
if (this.checkedNames.Rows.Count > 0)
{
foreach (DataGridViewRow row in (IEnumerable)this.checkedNames.Rows)
{
if (row.Cells[1].Value.Equals("Name Available"))
{
strs.Add(row.Cells[0].Value.ToString());
}
}
if (strs.Count > 0)
{
string currentDirectory = Environment.CurrentDirectory;
DateTime now = DateTime.Now;
File.WriteAllLines(string.Concat(currentDirectory, "\\Available Names ", now.ToString("dd-MM-yyyy HH.mm.ss tt"), ".txt"), strs);
}
}
}
private void saveTakenNamesToolStripMenuItem_Click(object sender, EventArgs e)
{
List<string> strs = new List<string>();
if (this.checkedNames.Rows.Count > 0)
{
foreach (DataGridViewRow row in (IEnumerable)this.checkedNames.Rows)
{
if (row.Cells[1].Value.Equals("Not Available"))
{
strs.Add(row.Cells[0].Value.ToString());
}
}
if (strs.Count > 0)
{
string currentDirectory = Environment.CurrentDirectory;
DateTime now = DateTime.Now;
File.WriteAllLines(string.Concat(currentDirectory, "\\Taken Names ", now.ToString("dd-MM-yyyy HH.mm.ss tt"), ".txt"), strs);
}
}
}
private void scrollBx_CheckedChanged(object sender, EventArgs e)
{
if (this.checkedNames.RowCount > 0)
{
if (this.scrollBx.Checked)
{
this.checkedNames.FirstDisplayedScrollingRowIndex = this.checkedNames.RowCount - 1;
}
else if (!this.scrollBx.Checked)
{
this.checkedNames.FirstDisplayedScrollingRowIndex = 0;
}
}
}
private void VisibilityBx_CheckedChanged(object sender, EventArgs e)
{
if (this.checkedNames.Rows.Count > 0)
{
foreach (DataGridViewRow row in (IEnumerable)this.checkedNames.Rows)
{
if (!this.VisibilityBx.Checked)
{
if (!row.Visible)
{
row.Visible = true;
}
}
else if (this.VisibilityBx.Checked)
{
if ((string)row.Cells[1].Value == "Not Available")
{
row.Visible = false;
}
}
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void CheckedNames_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
}
}
Use:
DataGridViewRow row = (DataGridViewRow)YOURDATAGRIDVIEW.Rows[0].Clone();
to create a new row to be added, instead of:
DataGridViewRow dataGridViewRow = new DataGridViewRow();
This preserves the column names in the new row.
You should no longer need this line of code:
dataGridViewRow.CreateCells(this.checkedNames, new object[] { Name, Status });
Also ensure that data grid view has columns, which is an often cause of this error.

Deleting items from listbox raises exception

I need to be able to delete items from a listbox but when I press the delete function and say yes I want to delete I get this exception: Items collection cannot be modified when the DataSource property is set.
Now I want to know what to do about this.
namespace Flashloader
{
public partial class Form1 : Form
{
private controllerinifile _controllerIniFile;
private toepassinginifile _toepassingIniFile;
// private Toepassinglist _toepassingList;
private StringList _comPorts;
public Form1()
{
InitializeComponent();
backgroundWorker1.WorkerReportsProgress = true;
backgroundWorker1.WorkerSupportsCancellation = true;
button4.Visible = false;
_controllerIniFile = new controllerinifile();
_toepassingIniFile = new toepassinginifile(_controllerIniFile.Controllers);
// _toepassingList = new Toepassinglist(_controllerList).FromIniFile();
_comPorts = new StringList();
_applicationListBox.DataSource = _toepassingIniFile.ToePassingen;
_controllercombobox.DataSource = _controllerIniFile.Controllers;
_applicationListBox.Refresh();
_controllercombobox.Refresh();
Settings settings = _toepassingIniFile.Settings;
textBox3.Text = settings.Port;
textBox4.Text = settings.Baudrate;
}
// File select Button and file directory
private void button2_Click(object sender, EventArgs e)
{
appfile.Filter = "Srec Files (.a20; .a21; .a26; .a44)|*.a20; *.a21; *.a26; *.a44|All files (*.*)|*.*";
{
if (appfile.ShowDialog() == DialogResult.OK)
{
System.IO.StreamReader sr = new
System.IO.StreamReader(appfile.FileName);
sr.Close();
}
}
String filedata = appfile.FileName;
appfile.Title = ("Choose a file");
appfile.InitialDirectory = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Application.ExecutablePath), #"C:\\\\Projects\\flashloader2013\\mainapplication\\");
textBox1.Text = string.Format("{0}", appfile.FileName);
}
// textbox for the bootfile
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
// start button for sending appfiles
private void button1_Click(object sender, EventArgs e)
{
backgroundWorker1.RunWorkerAsync();
serialPort1.Open();
if (MessageBox.Show(appfile.FileName + " is selected and ready to be send,Are you sure you want to send the selected file?", "", MessageBoxButtons.YesNo) == DialogResult.No)
{
MessageBox.Show("The selected file will not be send.", "", MessageBoxButtons.OK);
}
else
{
button1.Visible = false;
button4.Visible = true;
}
try
{
using (FileStream inputstream = new FileStream(OpenBoot.FileName, FileMode.Open, FileAccess.Read, FileShare.Read, 32 * 1024 * 1024, FileOptions.SequentialScan))
{
byte[] buffer = new byte[8 * 1024 * 1024];
long bytesRead = 0, streamLength = inputstream.Length;
inputstream.Position = 0;
while (bytesRead < streamLength)
{
long toRead = streamLength - bytesRead;
if (toRead < buffer.Length)
buffer = new byte[(int)toRead];
if (inputstream.Read(buffer, 0, buffer.Length) != buffer.Length)
throw new Exception("File read error");
bytesRead += buffer.Length;
serialPort1.Write(buffer, 0, buffer.Length);
}
}
}
catch
{
MessageBox.Show("No file selected");
}
StringList list = new StringList().FromFile(appfile.FileName);
// Read file and put it in a list that will be sorted.
foreach (String line in list)
{
list.Sort();
serialPort1.Write(line);
}
MessageBox.Show("Bootfile and Applicationfile are send succesfully.");
}
// abort button for sending files
private void button4_Click(object sender, EventArgs e)
{
backgroundWorker1.CancelAsync();
button4.Visible = false;
button1.Visible = true;
progressBar1.Value = 0;
timer1.Enabled = false;
serialPort1.Close();
}
// backgroundworkers
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
DateTime start = DateTime.Now;
e.Result = "";
for (int i = 0; i < 100; i++)
{
System.Threading.Thread.Sleep(50);
backgroundWorker1.ReportProgress(i, DateTime.Now);
if (backgroundWorker1.CancellationPending)
{
e.Cancel = true;
return;
}
}
TimeSpan duration = DateTime.Now - start;
e.Result = "Duration: " + duration.TotalMilliseconds.ToString() + " ms.";
}
private void backgroundWorker1_ProgressChanged(object sender,
ProgressChangedEventArgs e)
{
progressBar1.Value = e.ProgressPercentage;
DateTime time = Convert.ToDateTime(e.UserState);
}
private void backgroundWorker1_RunWorkerCompleted(object sender,
RunWorkerCompletedEventArgs e)
{
if (e.Cancelled)
{
MessageBox.Show("The task has been cancelled");
}
else if (e.Error != null)
{
MessageBox.Show("Error. Details: " + (e.Error as Exception).ToString());
}
else
{
MessageBox.Show("The task has been completed. Results: " + e.Result.ToString());
}
}
private void Boot_button_Click(object sender, EventArgs e)
{
OpenBoot.Filter = "Binary Files (.BIN; .md6; .md7)|*.BIN; *.md6; *.md7|All Files (*.*)|*.*";
{
if (OpenBoot.ShowDialog() == DialogResult.OK)
{
System.IO.StreamReader sr = new
System.IO.StreamReader(appfile.FileName);
sr.Close();
}
}
String filedata = OpenBoot.FileName;
OpenBoot.Title = ("Choose a file");
OpenBoot.InitialDirectory = "C:\\Projects\\flashloader2013\\mainapplication\\Bootfiles";
textBox2.Text = string.Format("{0}", OpenBoot.FileName);
}
// Saving the settings to the INI file.
private void SaveSettings()
{
Toepassing toepassing = GetCurrentApplication();
if (toepassing == null)
{
MessageBox.Show("No Application selected");
return;
}
toepassing.Controller = (Controller)_controllercombobox.SelectedItem;
toepassing.Lastfile = textBox1.Text;
// toepassing.TabTip =
_toepassingIniFile.Save();
}
private Controller GetCurrentController()
{
int index = _controllercombobox.SelectedIndex;
if (index < 0)
return null;
return _controllerIniFile.Controllers[index];
}
private Toepassing GetCurrentApplication()
{
int index = _applicationListBox.SelectedIndex;
if (index < 0)
return null;
return _toepassingIniFile.ToePassingen[index];
}
private void typelistbox_SelectedIndexChanged(object sender, EventArgs e)
{
Toepassing toepassing = GetCurrentApplication();
if (toepassing == null)
{
// TODO velden leegmaken
}
else
{
// appfile.InitialDirectory = Path.GetDirectoryName(controller.Lastfile);
appfile.FileName = toepassing.Lastfile;
textBox1.Text = toepassing.Lastfile;
_controllercombobox.SelectedItem = toepassing.Controller;
}
}
private void _controllercombobox_SelectedIndexChanged(object sender, EventArgs e)
{
Controller controller = GetCurrentController();
if (controller == null)
{
// TODO velden leegmaken
}
else
{
textBox2.Text = controller.Bootfile;
}
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
private void changeCurrentControllerToolStripMenuItem_Click(object sender, EventArgs e)
{
var controlleredit = new Controlleredit(_controllerIniFile);
controlleredit.Show();
Refresh();
}
private void addControllerToolStripMenuItem_Click(object sender, EventArgs e)
{
var controllersettings = new Newcontroller(_controllerIniFile);
controllersettings.ShowDialog();
_controllercombobox.DataSource = null;
_controllercombobox.DataSource = _controllerIniFile.Controllers;
// Refresh();
// _controllercombobox.Refresh();
}
private void newapplicationBtton_Click(object sender, EventArgs e)
{
var newapplication = new NewApplication(_toepassingIniFile);
newapplication.ShowDialog();
_applicationListBox.DataSource = null;
_applicationListBox.DataSource = _toepassingIniFile.ToePassingen;
}
/////////////////////////////The Error is down here /////////////////////////////
private void button3_Click(object sender, EventArgs e)
{
if (MessageBox.Show("You are about to delete application: "+ Environment.NewLine + _applicationListBox.SelectedItem +Environment.NewLine + " Are you sure you want to delete the application?", "", MessageBoxButtons.YesNo) == DialogResult.No)
{
MessageBox.Show("The application will not be deleted.", "", MessageBoxButtons.OK);
}
else if (this._applicationListBox.SelectedIndex >= 0)
this._applicationListBox.Items.RemoveAt(this._applicationListBox.SelectedIndex);
}
}
}
The error says it quite clearly: you have to remove the item from the underlying datasource, you can't delete it manually. If you want to remove/add items manually, you shouldn't use databinding but build the list by hand.
As exception say you can't delete items directly from ListBox - you have to remove it from underlying DataSource and then rebind control (if it is not bound to BindingSource for example)
private void button3_Click(object sender, EventArgs e)
{
if (MessageBox.Show("You are about to delete application: "+ Environment.NewLine + _applicationListBox.SelectedItem +Environment.NewLine + " Are you sure you want to delete the application?", "", MessageBoxButtons.YesNo) == DialogResult.No)
{
MessageBox.Show("The application will not be deleted.", "", MessageBoxButtons.OK);
}
else if (this._applicationListBox.SelectedIndex >= 0)
{
var item = this.GetCurrentApplication();
_toepassingIniFile.ToePassingen.Remove(item);
_applicationListBox.DataSource = null;
_applicationListBox.DataSource = _toepassingIniFile.ToePassingen;
}
}
Your code is hard to read so I was a bit guessing with classes etc, but it should work.
Try to remove from datasource itself as below:
string myobj = this._applicationListBox.SelectedValue.ToString();
data.Remove(myobj );
_applicationListBox.DataSource = null;
_applicationListBox.DataSource = data;
As others have said. You must have a list that is bound to the listbox. You cannot delete from the listbox directly.
You should delete from the List
private Toepassinglist _toepassingList
That is the datasource for your listbox.
Delete the item you want like so...
this._toepassingList.Items.RemoveAt(this._applicationListBox.SelectedIndex);
You can delete from list:---
ListName.Items.RemoveAt(postion);

Change the mouse drag cursor in WPF

I have to disply the number of dragged files count on mouse cursor while dragging document from file system to my form.
I have done the following code, but I can not change the drag cursor. Please let me know the best way to do this
private void tbDisplayFileContents_PreviewDragOver(object sender, DragEventArgs args)
{
if (IsSingleFile(args) != null)
{
tbDisplayFileContents_PreviewDrop(sender, args);
}
else
{
// args.Effects = DragDropEffects.None;
}
Mouse.SetCursor(Cursors.Hand);
Icon ico = new Icon(string.Concat("1365516094_10371.ico"));
tbDisplayFileContents.Cursor = GenerateCursor.CreateCursor(ico, true, new System.Drawing.Color());
args.Handled = true;
}
private void tbDisplayFileContents_PreviewDrop(object sender, DragEventArgs args)
{
args.Handled = true;
string files = string.Empty;
string[] fileName = IsSingleFile(args);
if (fileName == null) return;
isDrag = true;
DoEvents();
for (int i = 0; i < fileName.Length; i++)
{
if (i == 0)
{
files = string.Concat("1] ", fileName[i]);
}
else
{
int j = i + 1;
files = string.Concat(files, Environment.NewLine, j, "] ", fileName[i]);
}
}
lblfileName.Content = files;
}
private string[] IsSingleFile(DragEventArgs args)
{
if (args.Data.GetDataPresent(DataFormats.FileDrop, true))
{
string[] fileNames = args.Data.GetData(DataFormats.FileDrop, true) as string[];
if (fileNames.Length != 0)
{
if (File.Exists(fileNames[0]))
{
// At this point we know there is a single file.
return fileNames;
}
}
}
return null;
}
#endregion
#region -------Events--------
private void btnClear_Click(object sender, RoutedEventArgs e)
{
lblfileName.Content = string.Empty;
}
#endregion
private void tbDisplayFileContents_PreviewDragEnter(object sender, DragEventArgs e)
{
e.Effects = DragDropEffects.None;
}
public static void DoEvents()
{
Application.Current.Dispatcher.Invoke(DispatcherPriority.Background,
new Action(delegate
{
Icon ico = new Icon(string.Concat("1365516094_10371.ico"));
Mouse.OverrideCursor = GenerateCursor.CreateCursor(ico, true, new System.Drawing.Color());
}));
}
I have used GiveFeedBack event as follows
private void tbDisplayFileContents_GiveFeedback(object sender, GiveFeedbackEventArgs e)
{
if (e.Effects == DragDropEffects.Copy)
{
e.UseDefaultCursors = false;
// Mouse.SetCursor(Cursors.Hand);
Icon ico = new Icon(string.Concat("1365516094_10371.ico"));
//Mouse.Cursor = GenerateCursor.CreateCursor(ico, true, new System.Drawing.Color());
Mouse.SetCursor(GenerateCursor.CreateCursor(ico, true, new System.Drawing.Color()));
}
else
e.UseDefaultCursors = true;
e.Handled = true;
}
It is working for form to form dragging but it is not working for the contents(file) which is dragged from outside form e.g files from Desktop.
I miss the GiveFeedback event in your code, which is used to modify the Mouse cursor while drag and drop operations.

Showing virtual keyboard when clicking on a textbox inside WebControl

I have created a virtual keyboard, the keyboard pops up for wpf textbox controls. How can I make the keyboard pops out when clicking on a textbox inside a web page?
the logic for displaying a textbox is given below:
static void TouchScreenKeyboardPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
FrameworkElement host = sender as FrameworkElement;
if (host != null)
{
host.GotFocus += new RoutedEventHandler(OnGotFocus);
host.LostFocus += new RoutedEventHandler(OnLostFocus);
}
}
static void OnGotFocus(object sender, RoutedEventArgs e)
{
Control host = sender as Control;
if (sender == typeof(TextBox))
{
_PreviousTextBoxBackgroundBrush = host.Background;
_PreviousTextBoxBorderBrush = host.BorderBrush;
_PreviousTextBoxBorderThickness = host.BorderThickness;
host.Background = Brushes.Yellow;
host.BorderBrush = Brushes.Red;
host.BorderThickness = new Thickness(4);
}
_CurrentControl = host;
if (_InstanceObject == null)
{
FrameworkElement ct = host;
while (true)
{
if (ct is Window)
{
((Window)ct).LocationChanged += new EventHandler(TouchScreenKeyboard_LocationChanged);
((Window)ct).Activated += new EventHandler(TouchScreenKeyboard_Activated);
((Window)ct).Deactivated += new EventHandler(TouchScreenKeyboard_Deactivated);
break;
}
if(ct.Parent != null)
ct = (FrameworkElement)ct.Parent;
}
_InstanceObject = new TouchScreenKeyboard();
_InstanceObject.AllowsTransparency = true;
_InstanceObject.WindowStyle = WindowStyle.None;
_InstanceObject.ShowInTaskbar = false;
_InstanceObject.ShowInTaskbar = false;
_InstanceObject.Topmost = true;
host.LayoutUpdated += new EventHandler(tb_LayoutUpdated);
}
}
static void TouchScreenKeyboard_Deactivated(object sender, EventArgs e)
{
if (_InstanceObject != null)
{
_InstanceObject.Topmost = false;
}
}
static void TouchScreenKeyboard_Activated(object sender, EventArgs e)
{
if (_InstanceObject != null)
{
_InstanceObject.Topmost = true;
}
}
static void TouchScreenKeyboard_LocationChanged(object sender, EventArgs e)
{
syncchild();
}
static void tb_LayoutUpdated(object sender, EventArgs e)
{
syncchild();
}
static void OnLostFocus(object sender, RoutedEventArgs e)
{
Control host = sender as Control;
host.Background = _PreviousTextBoxBackgroundBrush;
host.BorderBrush = _PreviousTextBoxBorderBrush;
host.BorderThickness = _PreviousTextBoxBorderThickness;
if (_InstanceObject != null)
{
_InstanceObject.Close();
_InstanceObject = null;
}
}
#endregion
}
private static void syncchild()
{
if (_CurrentControl != null && _InstanceObject != null)
{
Point virtualpoint = new Point(0, _CurrentControl.ActualHeight + 3);
Point Actualpoint = _CurrentControl.PointToScreen(virtualpoint);
if (WidthTouchKeyboard + Actualpoint.X > SystemParameters.VirtualScreenWidth)
{
double difference = WidthTouchKeyboard + Actualpoint.X - SystemParameters.VirtualScreenWidth;
_InstanceObject.Left = Actualpoint.X - difference;
}
else if (!(Actualpoint.X > 1))
{
_InstanceObject.Left = 1;
}
else
_InstanceObject.Left = Actualpoint.X;
_InstanceObject.Top = Actualpoint.Y;
_InstanceObject.Show();
}
}
private static void SetKeyInBrowser(string key)
{
var elementName = (((mshtml.HTMLDocument)(dom)).activeElement).id;
if (elementName != null)
{
var existingText = dom.getElementById(elementName).getAttribute("value");
if (existingText == null)
{
existingText = "";
}
//if it's a backspace.
if (isBackspace)
{
existingText = existingText.ToString().Remove(existingText.ToString().Length - 1);
dom.getElementById(elementName).setAttribute("value", existingText.ToString());
}
else if (key.Length != 0)
{
dom.getElementById(elementName).setAttribute("value", existingText.ToString() + key[key.Length - 1]);
}
}
isBackspace = false;
}
You need to use javascript for that. You need to know when that textfield is focused like this:
Check if focus is on a textfield
And then once the focused event is fired on JavaScript you should call your WPF function for showing the keyboard up. Here's useful hints:
How to programmaticaly check if a text input box inside a web page loaded in WPF Browser has focus?

Categories

Resources