|
You would get it the same way you would any where else in the .Net world. How does "it fail"? Is an exception thrown? If so, what does it say? If no data is returned, are you sure there is data on the clipboard?
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Hi,
I'm doing a printing range option, allow user type the print range like in the Microsoft Word. for example, the range can be (1,2,4-8,10-12)
now, I would like to do a validation, prevent any non-useful character inside this string (i.e. except digit, "," and "-")
any faster way to do this?
Thanks for your help.
|
|
|
|
|
Yes, write a KeyPress event handler for the TextBox.
private void tbPages_KeyPress ( object sender , System.Windows.Forms.KeyPressEventArgs e )
{
if ( "0123456789,-\b".IndexOf ( e.KeyChar ) == -1 )
{
e.Handled = true ;
}
return ;
}
(\b is backspace)
|
|
|
|
|
Thanks so much PIEBALDconsult ~
|
|
|
|
|
|
I have not had the pleasure (or pain as some may see it) of working w/Pointers in C#. However, I remember reading a question someone had asked a few days ago regarding pointers in C# 2005 where they mentioned that in order to use pointers you had to go to the project properties and check the 'Allow Unsafe Code' check box.
Not sure if it'll help, but figured I'd try and give it a shot...
|
|
|
|
|
Yup, you now have to 'Allow Unsafe code' and mark the class / method / block of code as unsafe, like so:
unsafe class myClass
{}
unsafe void myMethod()
{}
static void main(string[] args)
{
unsafe {
}
}
My current favourite word is: Bauble!
-SK Genius
|
|
|
|
|
Hello,
I have a form set up so that it auto-magically resizes its controls when a horizontal splitter is moved. However, when the user resizes the form it is possible for some controls to end up being too small, or pushed out of the form's visible area altogether.
I have found that just a click on the horizontal splitter fixes everything up. So I thought I would just add code to do invoke the splitter in the form's resize event. Only I can't find a way to do that.
Is there a way to fake having the user move the splitter?
Clive Pottinger
Victoria, BC
|
|
|
|
|
Sorry I haven't got an answer but i *HAD* to congratualte you on the word 'auto-magically'!
|
|
|
|
|
DaveyM69 wrote: the word 'auto-magically'!
It's been around since the '70s. See this[^] link, for one.
/ravi
|
|
|
|
|
cpotting wrote: Is there a way to fake having the user move the splitter?
Would an Invalidate() followed by an Update() work instead? Looks like the window needs to be completely refreshed in order for the controls to render properly. This bug is in the Win32 layer and has been around for years.
/ravi
|
|
|
|
|
Hello, this may be a stupid question but I'm curious. I have a class I've created (that extends the FORM class) that runs as a child form of my main application. The purpose and nature of the form is such that it doesn't matter if it closes...the parent form monitors and will reopen it if necessary. I am handling several types of exceptions and closing the child form when they occur. However, I occasionally get an unhandled exception (in the child form) that causes it to crash.
I'm looking for a way to catch all unhandled exceptions in my custom class and run an event accordingly. Is there a way to do this? I see a method for any unhandled exceptions for the whole app, but I don't want that. I also see how to handle all exceptions when my child form is initialized, but that doesn't help if it's already initialized and running.
All I want now is to handle all exceptions in my custom class. Is this possible?
Thanks,
Alan
|
|
|
|
|
You can put a try block where your form gets started.
<br />
<br />
try<br />
{<br />
Application.Run(new Form1());<br />
}<br />
catch (Exception ex)<br />
{<br />
LogException(ex);<br />
Application.Exit();<br />
}<br />
<br />
|
|
|
|
|
eggs,
thanks for the suggestion! i believe that code will catch any unhandled exceptions generated by my entire app (parent form, and my custom child form). i'm trying to just catch errors in the child form.
the child form is being added something like this:
<br />
frmCustomForm = new MyCustomForm();<br />
<br />
this.Controls.Add(frmCustomForm);
i would like any unhandled exception that occurs within that custom form to cause it to trigger an event.
alan
|
|
|
|
|
Here's an idea of what you could do (although I make no assurances as to the quality of the the design! ) -
In your custom form you'll need to surround any potentially error producing blocks of code in a standard try...catch block. What you'll also need in the custom class is an event, perhaps call it OnError or similar (have a google for how events are implemented in C#), and when an error is caught by the try...catch mechanism, fire off the OnError event.
Then from your main app you can subscribe to this event with something like the following:
{...
frmCustomForm = new MyCustomForm();
frmCustomForm.OnError += new EventHandler(yourMethodHere);
this.Controls.Add(frmCustomForm);
...}
private void yourMethodHere()
{
code that runs when the event is fired an recieved.
}
Now a word of warning It sounds as if there's a lot of logic contained in your custom form that might suit being refactored out... something for you to have a think about!
"On one of my cards it said I had to find temperatures lower than -8. The numbers I uncovered were -6 and -7 so I thought I had won, and so did the woman in the shop. But when she scanned the card the machine said I hadn't.
"I phoned Camelot and they fobbed me off with some story that -6 is higher - not lower - than -8 but I'm not having it."
-Tina Farrell, a 23 year old thicky from Levenshulme, Manchester.
|
|
|
|
|
|
|
Thanks for all of the suggestions. I ended up using pretty much all of them in some form or another. I've isolated this custom class to run as a Windows service, and handle all UI and non UI unhandled exceptions with global handlers under Main().
Alan
|
|
|
|
|
Hi All,
I can't find any good examples of throwing exceptions. I have the following code. I want to include all the possible exceptions i can. Help me out on this. I am just moving away from console object and moving towards exception object.
public int DeleteFilesOlderThan(int Days, int Hrs, int Mins, string filter)
{
DateTime dt = GetRelativeDateTime(Days, Hrs, Mins);
ArrayList oldFilePaths = FilesOlderThan(dt, filter);
int count = 0;
string message = null;
foreach (string filePath in oldFilePaths)
{
try
{
File.Delete(filePath);
count++;
}
//* System.Exception is too general..I want something more like FileNotFoundException...any exception that can be related to my code
catch (Exception e)
{
message = "Unable to delete " + filePath + "\r\n";
message += String.Format("Reason: {0}", e.Message);
MessageBox.Show(message);
}
}
return count;
}
// Using GetRelativeDateTime as a private method instead of public however as it is only to be used internally
private static DateTime GetRelativeDateTime(int days, int hours, int minutes)
{
return DateTime.Now.AddDays(-days).AddHours(-hours).AddMinutes(-minutes);
}
public ArrayList FilesOlderThan(DateTime dt, string filter)
{
//m_FolderPath = @"C:\CsharpTempFolder";
// Using the supplied path
//DirectoryInfo directory = new DirectoryInfo(Directory.GetCurrentDirectory())
DirectoryInfo directory = new DirectoryInfo(m_FolderPath);
// Filter is applied to the directory.GetFiles method to get files of given extension
// get FileInfos for the files in the current directory matching the filter expression
FileInfo[] files = directory.GetFiles(filter);
//list to hold the result
ArrayList older = new ArrayList();
foreach (FileInfo file in files)
{
//if smaller (older) than the relative time
if (file.CreationTime < dt)
older.Add(file.FullName); //add it to the list
}
return older;
}
|
|
|
|
|
A try block can have multiple catch blocks. These should be arranged t-b in decdending order of specificity. You could have a block to specifically catch the FileNotFoundException exception, followed by a general block to catch any exceptions that derive from System.Exception . If an exception is raised, execution will branch into the first relevent catch block.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
So, is that it then?
catch (FileNotFoundException e)
{
message = "Unable to delete " + filePath + "\r\n";
message += String.Format("Reason: {0}", e.Message);
MessageBox.Show(message);
}
catch (DirectoryNotFoundException e)
{
message = "Unable to delete " + filePath + "\r\n";
message += String.Format("Reason: {0}", e.Message);
MessageBox.Show(message);
}
catch (Exception e)
{
message = "Unable to delete " + filePath + "\r\n";
message += String.Format("Reason: {0}", e.Message);
MessageBox.Show(message);
}
|
|
|
|
|
Yes, that looks OK. Try it out and judge for yourself.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
How can i fail my program so this works?
|
|
|
|
|
Shani Aulakh wrote: How can i fail my program so this works?
What do you mean? Why would you want cause your program to deliberately fail?
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
Sorry for the confusing question. I meant to say, what should i do to see if it actually handle all exceptions
|
|
|
|