|
if i change it, the cursor will change as soon as mouse enters in the PrintPreviewControl, thats not solving my problem, i want it to change only on the document that is displayed inside the control. meaning, there exist some vacant area inside the control that is not been occupied by the displayed document, in that area cursor should have default value. It should change on the area occupied by the document.
regards
|
|
|
|
|
THe PrintPreview Control doesn't expose this kind of functionality. You'd have to extend the control and add this functionality yourself. Calculating the screen coordinates of the page 'image' is going to be the hard part. Since the underlying control does all the painting, your going to have a ruff time doing this. You could at least use the OnEnter and OnLeave events of the control to know when the mouse is actually in the control. From there, you'd have to figure out the coordinates relative to the page image rectangle(s).
No, I haven't done it before, and don't know exactly how. I have no source code or sample to give you...
RageInTheMachine9532
"...a pungent, gastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
More over can we decide the layout of the document to be displayed, meaning can we decide like A4 or Letter size layout for the document?
|
|
|
|
|
Yes. See the PageSettings property, which sets the default page size, though you can change it if desired while printing each page. It's all documented in the .NET Framework SDK.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I think I did't get your answer, there is no such property in the property list of PrintPreviewControl.
Please elaborate more, also guide me about the first question
regards
|
|
|
|
|
The PageSettings doesn't belong to PrintPreview... It belongs to the PrintDocument that the PrintPreview control is using as a source.
A simple search in the documentation would have told you this. All you had to do is type 'PageSettings' into the Index...
RageInTheMachine9532
"...a pungent, gastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
How to sence click even on the document when two pages are displayed in PrintPreviewControl.
How to identify which page is clicked?
|
|
|
|
|
The PrintPreviewControl doesn't expose this functionality. You'd have to extend the PrintPreviewControl class and write the functionality in yourself. Getting the screen coordinates of the page 'images' will be the ruff part (Good Luck!). Once you have that, it's not too hard to figure out if the mouse cursor is inside those rectangles to determine which page is clicked.
A better bet would be to look into a 3rd party PrintPreviewControl.
RageInTheMachine9532
"...a pungent, gastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi All
I have a problem where i am reading in a csv file but within the file each field within a line has double quotes surrounding the data, and occassionally the data will have commas in it eg: "01","test","this,is the,problem","test"
What i want to do is remove the commas within the quotes, and leave everything else.
If any one has an idear please help.
regards Odyssey
|
|
|
|
|
Actually, the real problem is how you're parsing the file. Instead of simply using String.Split to split using commas, enumerate the characters in the line and keep track of when you come across a double quote. Increment a counter or set a boolean. When you run into another quote, decrement your counter or reset a boolean. When the counter is 0 or your boolean is false, then you can parse a comma-dilimited field. The typical CSV (there really isn't a standard) uses double quotes to signify that a delimited field may contain the actual delimiters. Simply removing the delimiters within those quotes would be corrupting the data.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
You can either use regular expression or odbc connection using microsoft text driver to parse csv files.
//Start of joke
Never comment ur code. If it was hard to write, it should be hard to understand !!!
//End of joke
|
|
|
|
|
|
Uwe Keim wrote:
How would such a RX look like?
A nice article[^] on 4GuysFromRolla for parsing csv files.
Uwe Keim wrote:
you have to use something similar to YACC or LEXX
Any pointers would be great.
//Start of joke
Never comment ur code. If it was hard to write, it should be hard to understand !!!
//End of joke
|
|
|
|
|
<br />
string s = "\"01\",\"test\",\"this,is the,problem\",\"test\"";<br />
string[] values = Regex.Split(s, @"(?<=\x22)\s*,\s*(?=\x22)");<br />
foreach (string val in values)<br />
Console.WriteLine(val);
OUTPUT:
"01"
"test"
"this,is the,problem"
"test"
Note that this solution requires every field to be delimited with double-quotes. If some fields are not (as often the case with CSV numeric data) the Split above will not work. However, such data is still certainly within the capabilities of a RE parse … instead of the RE Split , you would capture the desired data in the Groups collection using Match … the RE would describe the values you want; and not the space between them (as in the split above).
Also note that I used zero-width look-ahead and look behind assertions to keep the double quotes on the values. If you did not want them as part of the value, the Split RE would look as follows: @"\x22\s*,\s*\x22" . You would then have to remove a double quote at the beginning of the first value and one at the end of the last.
|
|
|
|
|
Hi
I tryed to use the RTF codes in RtfBox, doesnt work
How can i bold a text in a RTFBox without the "SELECT Method"(Select the text, and the Selection Font and Color ) ?
only \b doesnt work, appers a square
Thanks.
|
|
|
|
|
First off, you're getting the square because you're trying to set RTF codes using the Text property, which has no knowledge of RTF codes. (And you're not using the @ symbol in front of your string, so C# thinks "\b" is an escape character. Either make it a string literal or escape the backslash "\\b".)
If you want direct access to the RTF codes in a RichTextBox , you should use the Rtf or SelectedRtf properties.
However, I don't think that's what you're looking for, as it will make it quite a bit more difficult than using SelectionFont , SelectionColor , etc. The Rtf and SelectedRtf properties will give you the entire Rtf formatting string for the contents of the control or selection, respectively. There are intended more for pasting RTF from other sources. You can't use them to simply turn bold or color on or off.
Charlie
if(!curlies){ return; }
|
|
|
|
|
Hi,
I'm populating a DataTable in a DataGrid via asynchronous callbacks. Right now my program is single-threaded and I add each "event" (actually a MSMQ msg) to a Queue using lock in the PeekCompletedHandler. I process MSMQ peeks by firing a timer every 3 seconds and, if the queue has events, dequeue the msgs with lock.
Sometimes the program will run for hours with no problems. Sometimes I get an exception saying a Generic GDI+ error has occurred and the DataGrid's screen real-estate is blanked-out and has a big red "X" throught it.
I can't figure out what it causing this. Does anybody what is wrong and how I fix this?
TIA,
Matt
|
|
|
|
|
If you're setting (and even getting sometimes) properties or calling methods on controls from your asynchronous callbacks, are you using Control.Invoke ? It's important that when modifying a control from another thread (which async calls are on) that you make the changes in the thread on which the control was created. See the Control.Invoke method and Control.InvokeRequired property documentation in the .NET Framework SDK for more information.
Why does it works sometimes? It's not absolute behavior to fail or succeed (well, not in all cases) if you do modify a control from a different thread than what it was created on. It basically comes down to the Windows messaging system that is used for Windows Forms and the threads that the message pumps are running on. More information can be found in the .NET Framework SDK.
Another possibility is that you're not disposing disposable objects. While you'll typically run into memory problems, other strange things can happen as well (like depleating available handles). Telling us exact what the error was may help.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath,
Thanks for your reply. Re: InvokeRequired; my program does not start any threads. My PeekCompletedHandler function is appended to the end of my post. Also, when I get the "Generic GDI+ exception" I don't see any specific info about the error in the MessageBox. How do I get that info so I can post it here?
-Matt
=============================================================
private static void MQPeekCompletedHandler(Object source, PeekCompletedEventArgs peekArgs)
{
MessageQueue mq = null;
try
{
mq = (MessageQueue) source;
if(mq == null)
{
MessageBox.Show("Source was null", "MQPeekCompletedHandler()");
return;
}
if(peekArgs.AsyncResult.IsCompleted == false)
{
MessageBox.Show("IsCompleted=false", "MQPeekCompletedHandler()");
return;
}
System.Messaging.Message msg = mq.EndPeek(peekArgs.AsyncResult);
IceEvent oEvent = new IceEvent(mq, msg);
if((oEvent.IsEventValid) && (s_nvcMsgsSeen[oEvent.Identifier] == null))
{
s_nvcMsgsSeen[oEvent.Identifier] = "Y";
lock(s_MQEventQueue.SyncRoot)
{
s_MQEventQueue.Enqueue(oEvent);
}
}
}
catch(System.Messaging.MessageQueueException smmqe)
{
// The IOTimeouts occur because, as per the MS MSMQ Best Practices, we timeout our
// Asnychronous BeginPeek() methods.
if(smmqe.MessageQueueErrorCode != System.Messaging.MessageQueueErrorCode.IOTimeout)
{
throw new System.Exception("Unexpected MessageQueue exception", smmqe);
}
}
catch(System.Exception se)
{
MessageBox.Show(se.GetType().ToString() + ": " + se.Message, "Exception occurred in MQPeekCompletedCallback()");
}
finally
{
if(mq != null)
{
mq.BeginPeek(new TimeSpan(0,1,0));
}
}
}
==============================================================
|
|
|
|
|
Again, asynchronous calls - which you said you used - run in a different thread. How else do you think they are not blocking calls? You invoke the call on a different thread, whether you know it or not (and you really should). What I said about Control.Invoke still applies.
You should read Including Asynchronous Calls[^] in the .NET Framework SDK for more information.
As far as the GDI+ error, when and where in your code do you see it? You should step through and determine where it's being thrown. If it's not, it's probably thrown from the message pump I mentioned before. Certain errors like that are difficult to trace.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath,
Thank you for your assistance. I was aware (from a previous problem that you helped me with on CodeProject) the need for Control.Invoke and multiple threads. I was not aware that the asynchronous callback was implicitly its own thread althought this makes sense now. I do need to read "Including Asnych Calls" in .NET SDK... thanks for the link.
@@@@ 1 More question @@@@@
I guess my job as a programmer is not to know at compile time which thread a given method is executing in and, hence, the need for InvokeRequired and Control.Invoke. Finally, my question. Why can't .NET make the "InvokeREquired" check for?
Granted programmer's would get "generic" processing but then they could override the default .NET processing. Or am I missing something here?
TIA,
Matt
|
|
|
|
|
For synchronous execution in a single-threaded application, that would be a complete waste of time.
You could something like I did, however. Have a method that accepts some information about what method you want to call or what property you want to get/set. Also accept a delegate (Delegate - nothing specific). That method would check InvokeRequired and conditionally execute that Delegate either using Control.Invoke (to execute it on the creation thread) or Delegate.Invoke (to execute it on the calling thread).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I ran into a similar problem before. I understood that I had to update the control on the thread that created it and I wrote a queue mechanism to do this. However, I was surprised to see that the asynchronous callback from the event ran on different thread. (Now its obvious but it was unclear to me then.) Try setting the thread name property on the form where you create your datagrid. Then do a simple debug assert against this thread name property in the asynchronous callback to ensure that you are updating your datagrid on the correct thread. This will at least tell you whether or not your async callback is on the same thread. (My guess is that it isn’t but I’m still new to this .Net stuff)
//Place this in the form init
Thread.CurrentThread.Name ="UI thread";
//Place this in the async callback
Debug.Assert(Thread.CurrentThread.Name =="UI thread");
Heath’s recommendation about Invoke is sound advice.
|
|
|
|
|
Is there an equivalent to sprintf in C#? Basically I have some C# "value types" (floats, decimals) that I would like to format into a string variable. Also, I have a DateTime variable that I would like to format into a string variable. What is the best way to do this?
Thanks.
|
|
|
|
|
See String.Format in the .NET Framework SDK documentation. Many types - like the primitive types - implement IFormatProvider and have an overloaded ToString method which accepts the same format specifiers as you'd pass in String.Format :
double d = 1.5;
string a = string.Format("{0:C}", d);
string b = d.ToString("C");
Console.WriteLine(a == b); Other methods like StringBuilder.AppendFormat and Console.WriteLine can also accept format specifiers with parameter indexes.
For more information, also see my article, Custom String Formatting in .NET[^]. I also mention several reasons why String.Format and all the classes, methods, and interfaces that comprise formatting in .NET are better than any printf -like function.
Microsoft MVP, Visual C#
My Articles
|
|
|
|