found the thing: for all who is interested: the Remove method caused the whole thing to be colored out with the same color the right code is: richTextBox1.Focus(); richTextBox1.Select(richTextBox1.Text.Length, 0); //richTextBox1.AppendText(s); richTextBox1.SelectionStart = richTextBox1.Text.Length - 2; richTextBox1.SelectionLength = 2; richTextBox1.SelectionColor = Color.Red; richTextBox1.SelectedText = s; richTextBox1.DeselectAll(); richTextBox1.Select(richTextBox1.Text.Length, 0);
gericooper
Posts
-
Richtextbox color change dinamically -
Richtextbox color change dinamicallyUp! also, There may be a way which work (1st: getting the proper string from the array 2nd: coloring all matching string in the textbox) but I guess this would be time & resource consuming. any idea?
-
Richtextbox color change dinamicallyhi task: there's a string array with 1 & 2 char strings. If user strikes the chars matches among one in the array, the prog changes user input for example from "aa"(=user input) to "aA"(in array). It is all done handling the textchanged event of the richtextbox. (last 1 or last 2 chars input) but: the "one char string" would be nice to be presented by blue color the "2 char string" for example with red. Still cannot figure out why the code below doesn't work but it changes all chars red, it only correct for the first & second recognized thing like so: "aA"s" but when input again "aA" the whole thing is changed to red (but "s" should be remained blue) thx for your ideas the event handling
private void richTextBox1_TextChanged(object sender, EventArgs e) { if (richTextBox1.Text.Length >= 2 && !boolfound) { Array.Find(mnames, FindM); } }
invokes this(1 & 2 chars matching section):private bool FindM(String s) { if (s.Equals(richTextBox1.Text.Substring(richTextBox1.Text.Length - 2, 2), StringComparison.CurrentCultureIgnoreCase)) { richTextBox1.Text= richTextBox1.Text.Remove(richTextBox1.Text.Length - 2,2); richTextBox1.Focus(); richTextBox1.Select(richTextBox1.Text.Length, 0); richTextBox1.AppendText(s); richTextBox1.SelectionStart = richTextBox1.Text.Length - 2; richTextBox1.SelectionLength = 2; richTextBox1.SelectionColor = Color.Red; richTextBox1.DeselectAll(); richTextBox1.Select(richTextBox1.Text.Length, 0); boolfound = false; return true; } if(s.Equals(richTextBox1.Text.Substring(richTextBox1.Text.Length - 1, 1), StringComparison.CurrentCultureIgnoreCase)) { richTextBox1.Text=richTextBox1.Text.Remove(richTextBox1.Text.Length - 1,1); richTextBox1.Focus(); richTextBox1.Select(richTextBox1.Text.Length, 0); richTextBox1.AppendText(s); richTextBox1.SelectionStart = richTextBox1.Text.Length - 1; richTextBox1.SelectionLength = 1; richTextBox
-
writing to a text filestill don't understand why to use a fixed size (do you mean fixed size, when you write fixed width?): an idea to your code: it 's always useful to close your writer in a finally block like: binarywriter.close();
-
How to have program respond to code created buttonat least 3-4 articles popped up in "C# event handling" on Codeproject It is worth the time reading through. 1-2 hour & you'll be fine....
-
writing to a text fileI guess from the code, your thing would be much easier to handle as a SQL (or simply a Database) task. Still, I have question: Why is it important the size you stated in your 1st post? to avoid strange chars: you can use streamwriter instead of binarywriter with proper encoding (eg.: Encoding.UTF-16 - as a parameter-) if you expect other than eng. characters. cheers, geri
-
Handles eventif this question is as simple as I think you may register a public bool buttonclicked =false and somewhere in your program logic if you set the value to true, a separate procedure would be called (what would normally be called upon a button click event) sg like: void buttonclicked() { //do something... }
-
.Net frame work in windows 98according to MSDN: you can install 1.1 redist cheers, geri
-
Regex - specify a max. length?so I would do sg like
int count=0; if(Char.IsNumber(e.KeyChar)) { count++; } if(count==10) e.Handled=true; //no more chars allowed to be preesed in.
& count-- if user deletes.....(so presses like: e.KeyChar = '\u0008' >> backspace, i guess ) geri -- modified at 2:46 Thursday 29th November, 2007 -
Regex - specify a max. length?handle keypress event count the pressed in chars. if =10 e.Handled = true. Hope this helps cheers, geri
-
getting data back the order as it appears in datagridviewThanks Dave problem solved
-
getting data back the order as it appears in datagridviewthx that gives me the idea.... now only 1 question left.for the accomplish of the above is it OK to have an [int-increment 1 ] identity (primary key)column for this?
-
getting data back the order as it appears in datagridviewhi, It would be quite an important thing for the user to get the data back in the order as it appears in the datagridview. rows of data are got from other gridviews (user clicks on other grids' rows and rows are copied to the gridview in question) so... no problem until user adds rows from the beginning(0 rows), and then saves his data, but: if user add rows the deletes rows then adds the same row again and save, the newly added row appears the first, however it was added the last. (BindingSource.Endedit is called each operation) any idea?? I also tried the BindingSource.ResetBindings() method, but that didn't helped. for saving tableadapter.update() is called. thx, g
-
row doesn't get deletedHi row adding (after adding + saving, reloading the form) is OK to 1 of my table but delete is not... Here's what I've done: since DeleteCommand didn't exist to that table I defined a simple one (at dataset designer mode to the tableadapter):
DELETE FROM Felhaszn_Egyeb
WHERE (TetelArId = @TetelArId) AND (EgyebId = @EgyebId) AND (Mennyiseg = @Mennyiseg)similarly UpdateCommand is defined as follows:
UPDATE Felhaszn_Egyeb
SET TetelArId = @TetelArId, EgyebId = @EgyebId, Mennyiseg = @Mennyiseg
WHERE (TetelArId = @Original_TetelArId) AND (EgyebId = @Original_EgyebId)upon the user clicks the delete button, the bindingsource.removecurrent() & bindinsource.endedit() & [dataset].acceptchanges() are invoked row is deleted from the datagridview upon user clicks save the well known invoked (thistableadapter.update(thisdataset.thisdatatable) upon reloading the form it still fills the table with 1 row, which shouldn't be there thx for your thread...g
-
can't find childrows....Think I got it I forgot to fill the child table, upon the load event of the form whose control is bound to parent table. so the classic: childtableadapter.fill (dataset.childtable)
-
can't find childrows....Hi Don't know what's wrong with my code(below), it runs but doesn't return any childrows( however exists -childrows.length=0- & identified by parent rows ID). Dataset was created by wizard, table & nested table in the dataset browser exist. I don't have any idea left... Thanks for your posts in advance, g
private void bindingNavigatorDeleteItem_Click(object sender, EventArgs e) { if (Validate() && uzemanyagBindingSource != null) { bool deleteRow = true; DataRowView rowView = uzemanyagBindingSource.Current as DataRowView; if (rowView == null) { return; } Debmut9DataSet.UzemanyagRow row = rowView.Row as Debmut9DataSet.UzemanyagRow; Debmut9DataSet.GepRow[] ChildRows = row.GetGepRows(); if (ChildRows.Length > 0) { DialogResult userChoice = MessageBox.Show("All records in this & realted table will be deleted.Continue?", "Delete...", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (userChoice == DialogResult.Yes) { foreach (Debmut9DataSet.GepRow childuzemanyag in ChildRows) { childuzemanyag.Delete(); } } else { deleteRow = false; } } if (deleteRow) uzemanyagBindingSource.RemoveCurrent(); uzemanyagBindingSource.EndEdit(); Array.Resize(ref uzemanyagregiar, uzemanyagBindingSource.List.Count); }
-
anonymous method runs "too many times"Hi Luc, Thanks for your post Gonna go & read your article. Cheers
-
anonymous method runs "too many times"Greetings, Below code would do the following upon user clicks the button: if user clicks on a specific cell on the instantiated form's datagridview, the appropriate row's data is copied into the caller form's datagridview. Problem is: the anonym method is fired as many times as user clicks "this" form's button (in order to show up the other form, whose datagridview contains the data to be copied onto "this" form' gridview) BUT I'd like it to be fired only ONCE at a time. thanks for any thread, g (placing "return" didn't help) :confused:
public int I = 0; private void btnHozzaadas_Click(object sender, EventArgs e) { Guid[] array = new Guid[15]; tetelArErAnSzerk.Owner = this; tetelArErAnSzerk.anyagDataGridView.CellClick += delegate { if (tetelArErAnSzerk.anyagDataGridView.CurrentCell.OwningColumn.DataPropertyName == "AnyagHozzaadas") { DataView datatableView = felhasznAnyagSzallitasBindingSource.List as DataView; DataRowView rowView = datatableView.AddNew(); Debmut9DataSet.Felhaszn_AnyagSzallitasRow felhasznaltanyagdatarow = (felhasznaltanyagszallitasDataGridView.Rows[I].DataBoundItem as DataRowView).Row as Debmut9DataSet.Felhaszn_AnyagSzallitasRow; rowView["TetelArId"] = (tetelArBindingSource.Current as DataRowView)["TetelArId"]; felhasznaltanyagdatarow.AnyagId = new Guid(); Guid anyagid = ((tetelArErAnSzerk.anyagDataGridView.CurrentRow.DataBoundItem as DataRowView).Row as Debmut9DataSet.AnyagRow).AnyagId; array[I] = anyagid; if (I == 0) { felhasznaltanyagdatarow.AnyagId = anyagid; } if (I > 0) { for (int J = 0; J < felhasznaltanyagszallitasDataGridView.Rows.Count - 1; J++) { for (int K = 1; K < felhasznaltanyagszallitasDataGridView.Rows.Count - 1; K++) { if (J == K) { K++; } if (array[J] == array[K]) {