|
You would just need to use the "TextChanged" event of the textbox, then if the entered number(s) fall within the range for an ASCII character, cast the integer to char.
Something like this would work.
private void textBox1_TextChanged(object sender, EventArgs e)
{
textBox2.Text = string.Empty;
string text = string.Empty;
string[] chars = textBox1.Text.Split(' ');
foreach (string str in chars)
{
if (str.Length > 0)
{
int num = Convert.ToInt32(str);
textBox2.Text += (char)num + " ";
}
}
}
|
|
|
|
|
But if I enter a char the program will falls.
How to eliminate this.
Vasildb
|
|
|
|
|
The other solution was better.
Instead of Convert.ToInt32, use int.TryParse to see if it's a number. Or make the text box accept numbers only.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
hi i want to sent the cursor from one textbox to another textbox or button just pressing ENTER key all time. but i am not getting any way so that i can perform this job which i can do very easily in vb just using keypress event and keyenter(keyascii). i will be grateful if somebody sent me this solution zelane
|
|
|
|
|
1- Handle the TextBox.KeyDown event.
2- In the handler call NextTextBox.Focus() method;
Regards
|
|
|
|
|
i am new in C# so that can't understand how to get help from your hints. request u to explain a little. showing just two textbox (like textbox1 and textbox2)
|
|
|
|
|
Alright! I guess atleast you know the PropertiesGrid, right?
1- Select TextBox1. Open PropertiesGrid. Open Events tab -little lightning button to the top-. DoubleClick on KeyDown event.
2- The code should show. Add these lines
if (e.KeyData == Keys.Enter)
TextBox2.Focus();
3- Err... That's it!
Regards
|
|
|
|
|
adding to what Nader said,
you can further fine-tune by querying TabStop and TabIndex properties of the
text boxes (controls where applicable) and compare TabIndex to dynamically set focus to the control which is next in the TabIndex order.
regards.
|
|
|
|
|
I want to implement a progressbar that indicates the progress of a thread going on
I've got a
public void F1(Object o)
which has the thread body
and a button which start the thread
and when I want to make things like
progressBar1.Maximum = 100;
in the F1 a get a cross-thread error
can anyone help?
|
|
|
|
|
Sure. Controls are not thread safe. You should use Invoke to update your progressbar:
1- Make a method in your form that has the progressbar. Let's say
public void UpdateProgress(int NewPosition)
{
MyProgressBar.Value = NewPosition;
}
2- Declare your delegate in the form:
public delegate void MyDelegate(int NewPosition);
3- Now in your Thread, just invoke it like this:
public void MyThreadMethod()
{
MyDelegate MyProgressDelegate = new MyDelegate(UpdateProgress);
Invoke(MyProgressDelegate, new object[] { 10 });
Invoke(MyProgressDelegate, new object[] { 20 });
Invoke(MyProgressDelegate, new object[] { 30 });
}
Regards
|
|
|
|
|
Hi,
I didn't know where I should post this, but because it is in C# I thought this would be the best place, even though it is ADO.NET stuff.
Anyway, I have a question, I have created a datasource to the northwind database and created a simple windows form. With the first name, last name textboxes etc. and to select the employees I use the listbox with the employees last names in it. I have added an the TextBox_Validate Event to each textbox with the code:
private void TextBox_Validated(object sender, EventArgs e)<br />
{<br />
employeesTableAdapter.Update(northwndDataSet1.Employees);<br />
<br />
employeesTableAdapter.Fill(northwndDataSet1.Employees);<br />
}
Yet, when I change a name, and then tab or click somewhere else, it doesn't update the database with the new name.
What am I doing wrong?
Thanks,
Any reply is appreciated
|
|
|
|
|
I've used ADO myself for sometime and have seen alot of errr.... Surperises you'd call them?!
Anyway, I'm sure the code is called, and that it's excuted without errors. From your code it looks like you've used the designer. Why didn't you use it to make the textboxes. It would update them automatically using a DataNavigator?
Regards
|
|
|
|
|
Blekk wrote: What am I doing wrong?
It would appear you did not look at the MANY database articles here on CodeProject. Give it a shot, I imagine it will help.
led mike
|
|
|
|
|
Hi,
I wish to have a magnify function in my program (C#) to view the form,
like that program in Windows XP (/Accessories/Accessibility/Magnifier).
How do I get the forms current view (appearance), and how do I show that in another form?
Can anyone help out?
Thanks in advance!
Gywox
|
|
|
|
|
1- Get current mouse position using Form.MousePosition property
2- Copy the area of the screen you desire using Graphics.CopyFromScreen()
3- scale it using Graphics.Scale() method.
3- Draw it into a Bitmap
4- View the bitmap in the other form inside a PictureBox for example.
Regards
|
|
|
|
|
I have a unique situation. I need to selectively play some mpeg videos in different sequences depending on the state of my main App. I have been able to add WMP to my form and play videos by setting URL = @"C:\path\filename.mpg". However, in the release version I cannot store the videos on the customers drive, so they must be embedded in the resources of the app. That's not the problem though.
I would like to be able to create a MemoryStream and dynamically build the "file" which will reside in memory. However, there is no way to tell the WMP control to play my System.IO.MemoryStream. I would have to save to disk and set URL = the new temporary file, and that isn't allowed.
Is there a way to point the URL at a resource in an assembly ?
If not, can I tell WMP to play a System.IO.Stream ?
|
|
|
|
|
Both are possible, I'm quite sure. But telling WMP to play a Stream would involve writing a shell extension that pretends your stream is a file.
An easier option might be the embedded resource route. Does this article[^] help you?
|
|
|
|
|
I have a windows form that inherits numerous controls from a parent form. Whenever I open the child form in the designer, I immediately get an asterisk that the file has unsaved changes, before I have changed anything. When I look at the .designer.cs file, numerous lines have been added, such as below:
Infragistics.Win.Appearance appearance1 = new Infragistics.Win.Appearance();
Infragistics.Win.Appearance appearance2 = new Infragistics.Win.Appearance();
this.ultraGridValidator.DisplayLayout.Appearance = appearance1;
...
And numerous lines have changed throughout the designer file (mostly locations and sizes):
this.configTab.Size = new System.Drawing.Size(766, 295);
When I open the base form in the designer, I get the asterisk, but usually nothing has changed. Sometimes locations / sizes have changed, even though I haven't moved anything. Obviously we're using Infragistics, but I don't know if that's the cause of the problem. I only suspect it because most of the lines added are related to the grid. I am also suspicous of the toolbar we recently added, just because of the timing. I have read msdn articles regarding problems with editing complex controls on inherited forms, but we're not trying to edit anything. We're just trying to keep things from randomly changing!
Has anyone seen anything like this? And any suggestions on how to fix it? It's killing productivity on our gui.
This is .NET 2.0 with Infragistics 6.1. I tried the latest VS service pack, but no luck.
Any help would be appreciated.
Thanks in advance.
|
|
|
|
|
I've noticed this when I'm working with files via sourcesafe, and I switch to design mode or html mode.
|
|
|
|
|
Thanks for the reply. I do remember this happening when I've used sourcesafe in the past, but we are using svn.
And just to clarify, this is a windows form.
Thanks.
|
|
|
|
|
I'm programming for a Symbol CE device (WT4070) with reduced key board, no mouse, and no touch screen. As such, I have to tab from button to button on the form to get the focus on the button i want. Then to invoke the button with focus i have to hit two keys on the key board (blue and backspace) to send a space in order to "click" the button. I want to just hit one key, the enter key, instead.
So, how do i trap the enter and turn it into a space?
I tried putting the following code in my form class, but it failed to compile saying "no suitable method found to override. Note I have "using System.Windows.Forms at the top and the object browser shows the ProcessDialogKeys is in there.
Any Ideas?
Here is the code that doesn't work:
protected override bool ProcessDialogKey(Keys keyData)
{
switch (keyData)
{
case Keys.Enter:
case Keys.Space:
return base.ProcessDialogKey(Keys.Space);
}
return base.ProcessDialogKey(keyData);
}
|
|
|
|
|
Hi coders
I'm doing some advanced calculations mostly on sound, but I'm relative new to C#...so
I was wondering if anyone has some advice on how I can (if possible) speed up the more primitive part of my code...e.g when I want to multply to arrays colmnwise. In Matlab this would look like Z=X.*Y but I cannot figure out a smart way to do this without using a for-loop in C# like
for (int i = 0; i < length; i++)
{
Z[i]=x[i]*Y[i];
}
As you can see, this takes a long time if the array consist of a sound segment of e.g 3 seconds which is 132300 samples. Do you know of any better way how this can be done...
Best regards
AL
|
|
|
|
|
|
Behind the scenes, Matlab is creating a for loop for you. If you want a faster implementation that avoids the .net bounds checking, you could try writing the innermost layer of your code in c++ (with optional processor specific asm optimizations to use MMX/SSE instructions) and then using pinvoke to call it from the main c# portion of your app.
--
Rules of thumb should not be taken for the whole hand.
|
|
|
|
|
Unsafe C# can get around bounds checking as well, and would be a lot easier that having to code up a separate C++ lib and invoke that from C#.
|
|
|
|