|
By changing the system sounds or turning the volume off, I guess.
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
Thank you,How can I do that ?
|
|
|
|
|
That's not a question becoming a programming forum. I believe that it's sufficiently described in the windows help.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thank you Guffa.
You're right, but I want to do that by C# programming
modified on Sunday, August 31, 2008 10:40 AM
|
|
|
|
|
Then you have to surrender some more information about what you have done. What method did you use to enable ctrl+A?
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thank you Guffa.
This is my method :
private void textBox_KeyDown(object sender, KeyEventArgs e)
{
try
{
if (e.Control && e.KeyCode == Keys.A)
((TextBox)sender).SelectAll();
}
catch
{ }
}
|
|
|
|
|
How to create format string for decimal data type
which shows blank if number is zero and otherwize in default format?
I tried format string f;;# but this shows f for nonzero numbers.
Is it possible to create such string for .NET decimal ToString() ?
Andrus.
using System.Windows.Forms;
class AppMainEntry
{
static void Main()
{
// Expected: 0.40 actual: f
MessageBox.Show((0.40m).ToString("f;;#"));
// expected: 123.40 actual: f
MessageBox.Show((123.40m).ToString("f;;#"));
// expected: 123.4 actual: f
MessageBox.Show((123.4m).ToString("f;;#"));
// OK: expected: empty actual: empty
MessageBox.Show((0m).ToString("f;;#"));
}
}
Andrus
|
|
|
|
|
AFAIK you cannot mix standard format elements (f) in custom format so you'll have to create the whole format string. For example
(0.40m).ToString("###,##0.00###;-###,##0.00###;#")
|
|
|
|
|
For 1.1m your format shows 2 places after comma, but I want only 1 place as F.
Which custome format is exactly equivalent to F format ?
Andrus.
Andrus
|
|
|
|
|
If you want just one zero after comma, change the 0 to #:
(1.1m).ToString("###,##0.00###;-###,##0.00###;#") to
(1.1m).ToString("###,##0.0####;-###,##0.0####;#")
I'm not sure about F's format since I believe that it is affected by number settings in control panel. For more info Standard Numeric Format Strings[^] and Custom Numeric Format Strings[^]
Mika
|
|
|
|
|
F format behaviour on decimal is not affected by any settings:
0m returns 0
1.10m returns 1.10
1.1m returns 1.1
1.123m returns 1.123
How to obtain same behaviour with format string except zero is converted to blank string ?
Andrus
|
|
|
|
|
From the manual:
If format is null or an empty string, the return value of this instance is formatted with the general numeric format specifier ("G").
Simple test case:
System.Diagnostics.Debug.WriteLine("-------");
System.Diagnostics.Debug.WriteLine("Using F");
System.Diagnostics.Debug.WriteLine("-------");
System.Diagnostics.Debug.WriteLine("(0m).ToString(\"F\") => " + (0m).ToString("F"));
System.Diagnostics.Debug.WriteLine("(1.10m).ToString(\"F\") => " + (1.10m).ToString("F"));
System.Diagnostics.Debug.WriteLine("(1.1m).ToString(\"F\") => " + (1.1m).ToString("F"));
System.Diagnostics.Debug.WriteLine("(1.123m).ToString(\"F\") => " + (1.123m).ToString("F"));
System.Diagnostics.Debug.WriteLine("------------------");
System.Diagnostics.Debug.WriteLine("Using empty string");
System.Diagnostics.Debug.WriteLine("------------------");
System.Diagnostics.Debug.WriteLine("(0m).ToString() => " + (0m).ToString(""));
System.Diagnostics.Debug.WriteLine("(1.10m).ToString() => " + (1.10m).ToString(""));
System.Diagnostics.Debug.WriteLine("(1.1m).ToString() => " + (1.1m).ToString(""));
System.Diagnostics.Debug.WriteLine("(1.123m).ToString() => " + (1.123m).ToString(""));
System.Diagnostics.Debug.WriteLine("-------");
System.Diagnostics.Debug.WriteLine("Using G");
System.Diagnostics.Debug.WriteLine("-------");
System.Diagnostics.Debug.WriteLine("(0m).ToString(\"G\") => " + (0m).ToString("G"));
System.Diagnostics.Debug.WriteLine("(1.10m).ToString(\"G\") => " + (1.10m).ToString("G"));
System.Diagnostics.Debug.WriteLine("(1.1m).ToString(\"G\") => " + (1.1m).ToString("G"));
System.Diagnostics.Debug.WriteLine("(1.123m).ToString(\"G\") => " + (1.123m).ToString("G"));
results:
-------
Using F
-------
(0m).ToString("F") => 0,00
(1.10m).ToString("F") => 1,10
(1.1m).ToString("F") => 1,10
(1.123m).ToString("F") => 1,12
------------------
Using empty string
------------------
(0m).ToString() => 0
(1.10m).ToString() => 1,10
(1.1m).ToString() => 1,1
(1.123m).ToString() => 1,123
-------
Using G
-------
(0m).ToString("G") => 0
(1.10m).ToString("G") => 1,10
(1.1m).ToString("G") => 1,1
(1.123m).ToString("G") => 1,123
So are yuo actually looking for "G" like behaviour? AFAIK you must implement your own converter which has the knowledge of the actual input string.
|
|
|
|
|
Yes. I'm sorry my previous letter was wrong, f format cannot used.
I want that result string contains as may decimal places after comma as
decimal value actually contains
*except* zero must be converted to empty string.
ToString() without argument, with empty format string or with G format as you demostrated produces this output
except it outputs 0m as 0 :
0.400m is converted to 0.400
123.40m is converted to 123.40
123.4m is converted to 123.4
0m is converted to 0
How to create format string which works as above except 0m, 0.00m etc is converted to empty string ?
I tried ";;#" format string but this does not output any digits.
I'm using FYI RDL report engine which allows to use only .NET format strings, no code.
Andrus
|
|
|
|
|
Sorry to say, but don't know any solution by using only format strings.
If you are using this Project RDL - Open Source Report Definition Language implementation in C#[^] I noticed that expressions and user written functions are supported (for example iif). Perhaps using these would help you.
Another option could be to preformat the numbers before they are given to report engine (converting them to strings) in which case you can control the output in your code.
|
|
|
|
|
Hi
I want to start a console app from a windows form(VS 2005) and show messages sent by the console app in a textbox, so I've used CommandLineProcess.
I declared an instance like this:
CommandLineProcess cmdLP = new CommandLineProcess();
then, I attached an event handler to the outputline event in the constuctor like this:
cmdLP.OutputLine += new CommandLineProcess.OutputLineEventHandler(OnOutputLine)
The OnOutputLine method looks like this:
private void OnOutputLine(object sender, CommandLineProcess.OutputLineEventArgs e)
{
try
{
if ((e.Text == null) || (e.Text.Length == 0))
{
return;
}
Form1.txtDepDetails.Text = e.Text;
}
catch (Exception ex)
{
throw ex;
}
}
The error i get when i try to run this line
Form1.txtDepDetails.Text = e.Text;
"Source = Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack."
I have searched the web but found solutions for web apps, not for win forms.
And i have already made sure that the app is starting in debug mode and that Supress JIT optimization is checked.
Could you give me some suggestions?
Thank you very much.
|
|
|
|
|
netDeveloper wrote: "Source = Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack."
That just means that the debugger could not evaluate something because a native frame (in this case, the set_Text call) is on top of the stack.
The error is something different: Windows Forms is not thread-safe, but asynchronous events like this run on a separate thread. You need to use Form.Invoke / Form.BeginInvoke to access Windows Forms controls from another thread:
form1.BeginInvoke(new MethodInvoker(delegate { form1.txtDepDetails.Text = e.Text; }));
Note that I've made form1 a reference that you'll have to pass to the class containing OnOutputLine. Don't make text boxes "static"!
|
|
|
|
|
The weird thing is that it doesn't even see form1.
This fails
if (Program.form1.InvokeRequired)
|
|
|
|
|
I'm trying to set my program in a way that before the program or I mean the form is to be closed, the program checks whether a text box has a value. So what I did is to make use of the closing event of the form... ok so when the form is closing, the program checks if there is a value on the text box and if empty the program asks the user through a dialog box like "You left that #)($*#$ blank.". When i run the program, the message box pops out so now the next thing to do is to stop the closing of the form if the textbox doesn't have any value.. is there a way to do that? well of course there are other alternatives for validation but on the FORM i'm dependent on the CANCEL (the x button on the upper right) for the closing of the form and nothing else.
|
|
|
|
|
In the closing event if you set e.Cancel = true; then the form will not close.
My current favourite word is: Nipple!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
Just Do This !!!
private void Form1_FormClosing(object sender, FormClosingEventArgs e)<br />
{<br />
if (textBox1.Text == "")<br />
{<br />
MessageBox.Show("Please Fill Details");<br />
e.Cancel = true;<br />
}<br />
else<br />
{<br />
MessageBox.Show("Thanks You !!!");<br />
}<br />
}
|
|
|
|
|
Check out the ErrorProvider[^] class/component.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Expect everything to be hard and then enjoy the things that come easy. (code-frog)
|
|
|
|
|
Hi,
I am trying to change the background color of the listview items depending on their text.
The problem is, the items don't keep their background color after every repaint. I tried the refresh() and update() function to make the items keep their color, but that didn't work.
I don't see any other function or property which might fix this problem i'm having.
I have heard about 'onwerdraw' but i have no idea how to use that, googeling this up hasn't showed a few interesting examples or if it fixes this problem for that matter.
If anyone has a success story about 'onwerdraw' with an example code, i'd really appreciate it. Or a suggestion about how to fix this issue.
Thanks in advance!
|
|
|
|
|
|
Hi,
Is there no alternative than to use ownerdraw?
It would be nice to catch the repaint event and put there the coloring stuff.
|
|
|
|
|
Setting BackColor for each item is another way (which you have used). I made a little test and forcing refresh didn't make the items to loose their color. In what situation you face the problem?
Test was (two buttons on a form and a listview):
private void button1_Click(object sender, EventArgs e) {
ListViewItem lvItem;
for (int i = 0; i < 10; i++) {
lvItem = new ListViewItem();
lvItem.Text = lvItem.GetHashCode().ToString();
lvItem.BackColor = Color.LightBlue;
listView1.Items.Add(lvItem);
}
lvItem = new ListViewItem();
lvItem.Text = lvItem.GetHashCode().ToString();
lvItem.BackColor = Color.Red;
listView1.Items.Add(lvItem);
}
private void button2_Click(object sender, EventArgs e) {
this.Refresh();
}
|
|
|
|