|
a.fateme wrote: help me.
Based on your other replies...
1. Learn basic C# (or java)
2. Learn basic GUI coding.
3. Learn the basics of virtual reality programming.
4. Define the requirements of what you want to create.
5. Learn/research specifics virtual reality based on 3.
6. Learn/reserch specific virtual reality APIs that exist to support 5.
7. Implement something.
Steps 1, 2 and 7 are the only ones that have anything specific to general programming.
Note that if 6 does not turn up a specific API then you are going to need to need to learn more than just a basic understanding of programming language (and GUIs) to write your own.
|
|
|
|
|
Hi
This code here below allows only numbers and one decimal point to be typed on a textbox.
It does not prevent you from:
1. Saving nulls in the database
2. From pasting any other character(words, asterisks,numbers etc) to the textbox.
What do i have to add to the code to prevent the two problems from occurring??
Here is my code:
private void txtBalance_TextChanged(object sender, EventArgs e)
{
txtBalance.KeyPress += new KeyPressEventHandler(numbercheck_KeyPress);
}
private void numbercheck_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && e.KeyChar != '.')
{
e.Handled = true;
}
if (e.KeyChar == '.'
&& (sender as TextBox).Text.IndexOf('.') > -1)
{
e.Handled = true;
}
}
Please help me figure out
Thanks
|
|
|
|
|
First, you don't want to add the KeyPressEventHandler in the in the TextChanged event. Every time this event is fired it will add a new event handler, you only need it added once in your form load or in it method, or declaratively in the markup.
Before saving to the database you should validate the input, KeyPressEventHandler has nothing to do with this.
Failure is not an option; it's the default selection.
|
|
|
|
|
A simple example please??
|
|
|
|
|
You need an example of string.IsNullOrEmpty? Or how to validate a string
if so then you need more help than can be given here.
Failure is not an option; it's the default selection.
|
|
|
|
|
if(string.IsNullOrEmpty(TextBox1.Text)){}
|
|
|
|
|
If u only want to validate decimal, then you can try following code at textbox change event:
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (textBox1.Text.Trim() != "")
{
decimal j;
if (!decimal.TryParse(textBox1.Text, out j))
{
MessageBox.Show("Not allowed!!!");
textBox1.Text = "";
}
}
}
Here, replace "textBox1" with your textbox ID.
|
|
|
|
|
If u only want to validate decimal, then you can try following code at textbox change event:
void textBox1_TextChanged(object sender, EventArgs e)
{
if (textBox1.Text.Trim() != "")
{
decimal j;
if (!decimal.TryParse(textBox1.Text, out j))
{
MessageBox.Show("Not allowed!!!");
textBox1.Text = "";
}
}
}
private Here, replace "textBox1" with your textbox ID.
|
|
|
|
|
Rather than trying to prevent "wrong" input, you should check the data when the user has finished input. Even when you prevent copy/paste of invalid data, some other technology might be used to get a "wrong" input into the box, e.g. a WM_SETTEXT message (think of assistive technologies).
The "Validate" event of the textbox is a good place to do so.
|
|
|
|
|
The database is irrelevant to this question. Your database schema should prevent nulls, and you want a control that gives you a double.
A good numeric text box should:
- Hook TextChanged to make sure that the value can never be invalid, e.g. if you try to paste into it, set the text programatically (e.g. through data binding) or any other way of putting text in there. Note that 'valid content' isn't necessarily a valid number, because you need to allow intermediate input that someone will type while entering a number. For example '', '-', '3.', '6E' (if supporting exponential notation) and the like should be allowed. You can find or write a regex for this part.
- Hook the keyboard input events (KeyPress should be enough) to reject any characters that can never be allowed, e.g. anything but numbers, or a minus sign in an empty field, or a dot. This prevents the TextChanged handler from firing, wiping the invalid character but resetting the caret.
- Have a numeric Value property that you can read and write in code.
|
|
|
|
|
A NumericUpDown already has everything you need.
|
|
|
|
|
My Simple Numeric TextBox[^] may be a good place to start. It doesn't do everything you require but could with a little effort.
|
|
|
|
|
|
And neither is the article/source - all C#!
|
|
|
|
|
Hello,
is there any dotnet libary to read /change and write MAT files? I use MatLab 2010b and try to find some libs, but i found nothing about that. I found some posts about using com, but found nothing about reading MAT files. Have anybody an idea?
|
|
|
|
|
This[^] post implies you'll need to P/Invoke the MatLab Windows API.
/ravi
|
|
|
|
|
Thx for the answer. I will try this the next days.
Rene
|
|
|
|
|
I'm trying to look at the class diagrams generated from my code in VS2010 Express, but I don't see a toolbar or window under any of my menus. I checked online and found the following from MSDN:
http://msdn.microsoft.com/en-us/library/gg269474.aspx
Does anyone know if this works on the Express edition of VS? If not, can anyone recommend a (free) tool that can help? Thanks.
|
|
|
|
|
|
Following a C# book and working with Visual Studio 2008 Team Suite. The excercise is a contacts app and involves the introduction of a logo. Additionally, Clicking on the logo generates an "About" feature. Double clicking the logo in the excercise leads to the error " editing embeded resources directly is not supported. Do you wish to convert this item to a linked resource in order to edit it?
The inserted code to generate the "About" feature is: MessageBox.Show ("Contact List 1.0. \nWritten by: Maurice Newsome" , "About") ; Visual Studio flashed a notification about an expected
Three pages of the book and images of my efforts are uploaded to: [COLOR="#0000FF"]https://skydrive.live.com/?cid=4ad6aabd72471dbb&sc=documents&id=4AD6AABD72471DBB%216691#cid=4AD6AABD72471DBB&id=4AD6AABD72471DBB%216692&sc=documents [/COLOR]
I seek guidance on how to address the semi-colon placement issue and why the Logo does not yield the expected results
|
|
|
|
|
If what you are saying is that you need help getting the code provided with a book to work, then I would suggest finding their website or forum. Also, please tag your code so it displays as code. Also, don't you have the code about the expected semi colon? What is it?
"I have a theory that the truth is never told during the nine-to-five hours. "
— Hunter S. Thompson
|
|
|
|
|
|
Uh, you need to actually run the program to see the expected behaviour, not click things in the designer which is what your double click message sounds like.
|
|
|
|
|
Hi...I didnt get a proper reply thats why i m posting it again....there is problem in backup of database.Here i m providing the code..
try
{
DateTime Time = DateTime.Now;
int year = Time.Year;
int month = Time.Month;
int day = Time.Day;
int hour = Time.Hour;
int minute = Time.Minute;
int second = Time.Second;
int millisecond = Time.Millisecond;
//Save file to C:\ with the current date as a filename
string path ;
string p = saveFileDialog1.FileName;
path = p + year + "-" + month + "-" + day +
"-" + hour + "-" + minute + "-" + second + "-" + millisecond + ".sql";
StreamWriter file = new StreamWriter(path);
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = @"C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqldump.exe";
psi.RedirectStandardInput = false;
psi.RedirectStandardOutput = true;
psi.Arguments = string.Format(@"-u{0} -p{1} -h{2} {3}",
"root", "123456", "localhost", "userdb");
psi.UseShellExecute = false;
Process process = Process.Start(psi);
string output;
output = process.StandardOutput.ReadToEnd();
file.WriteLine(output);
process.WaitForExit();
file.Close();
process.Close();
MessageBox.Show("backup is created");
}
catch (IOException ex)
{
if (System.Diagnostics.Debugger.IsAttached())
{
Console.WriteLine(ex.ToString());
}
else
MessageBox.Show("Error , unable to backup!");
}
}
so the problem is when pointer reach to this line-
Process process = Process.Start(psi)
then an existing event is automatically called and i dont think that this event has to do anything with it....the event is this..
private void tabControl1_DrawItem(object sender, DrawItemEventArgs e)
{
// if (tabControl1.TabPages.Count != 1)
{
e.Graphics.DrawString("x", e.Font, Brushes.Black, e.Bounds.Right - 15, e.Bounds.Top + 4);
e.Graphics.DrawString(this.tabControl1.TabPages[e.Index].Text, e.Font, Brushes.Black, e.Bounds.Left + 12, e.Bounds.Top + 4);
e.DrawFocusRectangle();
}
}
so because of this i m unable to create a proper backup file...so plz give some suggestion....
|
|
|
|
|
Your code calls MessageBox.Show , which obscures (part of) (one of) your app's windows; when you close the MessageBox, whatever was obscured needs repainting, that seems like why you are getting such event(s).
Test the hypothesis by writing your messages to a file, or to a ListBox on your Window, rather than using MessageBox. In fact, I recommend to do that anyway, MessageBoxes are pretty annoying, while logging is very useful during development and afterwards.
And please start using <PRE> tags (e.g.use the "code" widget) when showing code; it preserves formatting and improves readability.
|
|
|
|