|
Ok, thanks for the explainations
Thanks
|
|
|
|
|
Heath, why are events in a derived class too slow?
First, i'm assuming the fact it's derived is a nonissue, your point is just that OnPaint is exposed directly for that purpose-- let me know if i misunderstand this.
But why would events be slow, aren't they just callbacks?
TIA.
________________________________________
Gosh, it would be awful pleas'n, to reason out the reason, for things I can't explain.
Then perhaps I'd deserve ya, and be even worthy of ya..
if I only had a brain!
|
|
|
|
|
Consider this: when you override such a method like OnPaint , the CLR will call your virtual method which uses the callvirt (as opposed to call ) IL instruction. This is polymorphism. This one call does it all. When you instead handle an event in the derived class from the base class (like handling the Paint ) event, there are several IL instructions (both in your implementation and in the event's add and remove accessors, not to mention whatever they require to add the handler to the callback chain) just to wire-up the event! When the event is fired, the collection of handlers is enumerated and each one is invoked with takes several more IL instructions (some to enumerate and jump back, and a couple to invoke the delegate). I hope this makes sense.
Besides, when you override the event handler like OnPaint , you don't need to know the sender because the current instance of your class is the sender. All you need is the EventArgs (or derivative, like PaintEventArgs ). It simplifies your class.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
i am sending a pdf file to printer (using streaming) but it gives binary output. anyone know why this is happening or is there an another way to print an existing pdf file in C#.
thanks
|
|
|
|
|
You can't just send a raw file to the printer (unless it's text or postscript and the driver is setup to recognize it correctly)! While a PDF is mostly PS, it is also compressed and mangled.
You need to have a program or library to print PDFs correctly. There is no support for this in the .NET base class library (has nothing to do with C#, which is only a language that targets the CLR), nor should there be (too specialized).
If Adobe Acrobat (including Reader) is installed, you can customize your Toolbox in VS.NET, click the COM tab, and add the Acrobat Control for ActiveX (which creates a couple interop assemblies and references them automatically). You can then use the LoadFile method to load a PDF then call the Print method. The out-of-process server for Acrobat (not Reader) doesn't appear to easily expose this type of access to the object model.
There are also libraries out there for .NET that can generate and print PDFs. Just http://www.google.com/search?&q=print+pdf+C%23[^]. One library that popuped up was http://itextsharp.sourceforge.net/[^].
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
thanks for your assistance. i tried to use Acrobat Control for ActiveX but gives "Catastrophic error".i searched for an example but could not found an example with "pdflib".
|
|
|
|
|
Worked fine for me in the past. What are you doing to the control?
Also, don't search for "pdflib". Use generic terms. I even gave you an example search string (you can even click on it to launch it) in which several solutions were returned.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hahaha, I know you would be laughing at me for this but anyways...
I'm a super n00b to programming in general, I saw all websites saying if you want to study C# you would need C/C++ or Java background but I didn't believe it, so I took a C# book for n00bs and read it and learned some basics of C# Programming but I want to study Managed DirectX so I can make games with C#, so I started reading "Sams Managed DirectX® 9 Kick Start Graphics and Game Programming" but it was little confusing and the book stated that it's not a book for n00b, I want to know if there's any book or websites that will teach you from the very basics of Managed DirectX from ground up, please don't tell me I have to study DirectX first before I go study Managed DirectX because I want to just go for C# + Managed DirectX and skip all the other stuff.
Please reply thank you ^^
http://www.shintasoft.com
Bring you English Version Super Robot Wars games
|
|
|
|
|
|
Thanks for the link, though it was from the other post below mine, is there anymore sources? like books? I used to think Sam's Teach Yourself serie books are good but they aren't, they suck, MS Press is hella better, at least the one I read.
http://www.shintasoft.com
Bring you English Version Super Robot Wars games
|
|
|
|
|
C# n00b wrote:
other post below mine
I didn't know you are the same persons.
C# n00b wrote:
I used to think Sam's Teach Yourself serie books are good but they aren't, they suck, MS Press is hella better, at least the one I read.
You can easily search on Amazon.com to find it. There are customer rating and feedback there which can help you to find out which book is beter for you.
Mazy
No sig. available now.
|
|
|
|
|
I have an application that uses a simple line printer, printDialog, and printDoc. I pass a string to the line printer, it prints it on the selected printer, and then grabs the next string...ect...
The question I have is, when there is a tab "\t" inside the string it is ignored by the printer. Is tehre a different escape sequence I should use for the printer to recoginize a tab?
Thanks in advance for your help.
I am a simple college student......be gentle
Joe
|
|
|
|
|
that the C# compiler does great diagnostics. (This is my first essay into C# enumerable classes so if I've missed something obvious be gentle with me.)
I've written a class like this.
public class FilterEnumerator : IEnumerator
{
#region IEnumerator Members
private int index = -1;
private ArrayList data;
public FilterEnumerator(ArrayList Data)
{
foreach (String s in Data)
data.Add(s);
Reset();
}
public void Reset()
{
index = -1;
}
public object Current
{
get
{
if (index >= 0 && index < data.Count)
return data[index];
else
return null;
}
}
public bool MoveNext()
{
return (++index < data.Count);
}
#endregion
}
It compiles but the compiler throws a warning at me for the
private ArrayList data;
member pointing out that this member variable is never assigned to and will always be null . It took a bit of headscratching until I realised that the compiler was noticing that I had never actually created something for data to refer to. What confused me (does this show I'm a c++ programmer learning a new language ?) was that I could quite clearly see that I had assigned to data in the constructor. Or so I thought.
The solution is of course to write the constructor thusly:
public FilterEnumerator(ArrayList Data)
{
data = new ArrayList;
foreach (String s in Data)
data.Add(s);
Reset();
}
Well I say the solution is 'of course' but I'm still thinking in c++ terms. Is there a better solution?
And why am I convinced that the c# compiler does better diagnostics? I'm a firm believer in compiling at the maximum error level and converting warnings to errors. I want to know if the compiler thinks my code is questionable before I even start to debug it. But this error would have slipped past the c++ compiler.
Rob Manderson
Paul Watson wrote:What sense would you most dislike loosing?
Ian Darling replied.
Telepathy
Then I'd no longer be able to find out everyones dirty little secrets The Lounge, December 4 2003
|
|
|
|
|
Rob Manderson wrote:
Is there a better solution?
With .NET 1.x, why not use a specialized collection : System.Collections.Specialized.StringCollection. It lets you clone an entire collection with one method call.
Rob Manderson wrote:
And why am I convinced that the c# compiler does better diagnostics?
Yeah, better infrastructure, I think it shows pretty well.
That said, practically 100% of interop issues will pass through the compiler without being seen.
RSS feed
|
|
|
|
|
|
Brian Delahunty wrote:
FxCOP can sometimes help there though.
Tried it, or only echoing the marketing brochure?
RSS feed
|
|
|
|
|
Stephane Rodriguez. wrote:
the marketing brochure?
Haven't seen any. Seriously.
Stephane Rodriguez. wrote:
Tried it
Yeah. But only recently. I've spent too much time tracking down issues when using COM and COM+ components in .NET applications and one of the guys in work was using FxCop so I pointed me in that area.... It's decent enough and it does help in a good few interop issues.
The main gripe I have with it is that it doesn't integrate into VS.NET... if it done that, and then donea quick scan each time as assembly was created then it would be excellent. But it's a free tool that has it's uses so I'm not going to complain too much about it.
Regards,
Brian Dela
http://www.briandela.com IE 6 required. http://www.briandela.com/pictures Now with a pictures section http://www.briandela.com/rss/newsrss.xml RSS Feed
|
|
|
|
|
Brian Delahunty wrote:
Haven't seen any (amrketing brochure). Seriously.
I am talking the MS weblogs and all that goes into that new marketing channel.
Brian Delahunty wrote:
It's decent enough and it does help in a good few interop issues.
I trust in you, unfortunately I can't figure out how an analyzer can show the issues with unmanaged code. By definition, it's not even possible for a managed code to be aware of anything that is unmanaged. For instance, a lot of the interop issues goes with what is supposed to be behind a LPTSTR. Such a parameter type doesn't say it's a [in] or a [out] parameter for instance. Since the caller never knows who holds the buffer, I think interop issues are pretty much doomed.
Also, given marshalling limitations when you are trying to interop complex structs, I wonder how FxCop can be of any help when you start using the interop services, allocating a buffer, and then start copying buffers back and forth.
Brian Delahunty wrote:
The main gripe I have with it is that it doesn't integrate into VS.NET
Yeah, I now think VS.NET lacks a lot of things, for instance the whole signing process. I can't think how Redmond manages to install 3.5 GB of binaries on some computer, and then fall short of such things.
Beyond me.
RSS feed
|
|
|
|
|
I have this drawing:
private System.Drawing.Graphics graphicsObj = null;
private System.Drawing.Pen penBlackWidth1 = new System.Drawing.Pen(System.Drawing.Color.Black,1);
private Point[] curvePoints = null;
private SolidBrush lightGrayBrush = new SolidBrush(Color.LightGray);
private Point point1;
private Point point2;
private Point point3;
private Point point4;
private SolidBrush blackBrush = new SolidBrush(Color.Black);
...................................................
try
{
graphicsObj = e.Graphics;
graphicsObj.DrawLine(penBlackWidth1, 45, 20, 175, 20);
graphicsObj.DrawLine(penBlackWidth1, 45, 20, 45, 120);
graphicsObj.DrawLine(penBlackWidth1, 175, 20, 175, 120);
graphicsObj.DrawLine(penBlackWidth1, 45,120,90,160);
graphicsObj.DrawLine(penBlackWidth1, 175, 120, 135, 160);
graphicsObj.DrawLine(penBlackWidth1, 90, 160, 135, 160);
graphicsObj.DrawLine(penBlackWidth1, 465, 335, 490, 335);
graphicsObj.DrawLine(penBlackWidth1, 580, 335, 605, 335);
graphicsObj.DrawLine(penBlackWidth1, 465, 335, 490, 335);
graphicsObj.DrawLine(penBlackWidth1, 580, 335, 605, 335);
graphicsObj.DrawLine(penBlackWidth1, 473, 345, 483, 345);
graphicsObj.DrawLine(penBlackWidth1, 473, 345, 478, 335);
graphicsObj.DrawLine(penBlackWidth1, 483, 345, 478, 335);
graphicsObj.DrawLine(penBlackWidth1, 587, 345, 597, 345);
graphicsObj.DrawLine(penBlackWidth1, 587, 345, 592, 335);
graphicsObj.DrawLine(penBlackWidth1, 597, 345, 592, 335);
point1 = new Point(592,335);
point2 = new Point(597,345);
point3 = new Point(587,345);
point4 = new Point(592,335);
curvePoints = new Point[]
{
point1,point2, point3, point4
};
graphicsObj.FillPolygon(blackBrush, curvePoints, FillMode.Alternate);
point1 = new Point(478,335);
point2 = new Point(483,345);
point3 = new Point(473,345);
point4 = new Point(478,335);
curvePoints = new Point[]
{
point1,point2, point3, point4
};
graphicsObj.FillPolygon(blackBrush, curvePoints, FillMode.Alternate);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
I want to fill the drawing with a color.
From buttom to top.
BUT the drawing must be filled accourding to a percent.
Is 50%, then only 50% of the drawing must be filled with the color.
Natural the fill must newer come outside the drawings edge.
Any help?
Thanks
|
|
|
|
|
correction:
if 50%, then only 50% of the drawing must be filled with the color.
|
|
|
|
|
Since you already have the coordinate points, create a region using these points and then use graphicsObj.ClipRgn() to set the clipping region. Then, you can draw a filled rectangle, without the fill color spilling out of the boundary.
Not so tough!!
|
|
|
|
|
Hi Shree
Can you give an example?
|
|
|
|
|
I'm having a problem which I'm not sure how to overcome. I've placed a listbox component inside a panel, that has autoscroll bars. When this listbox is partly outside the view of the panel, and it is clicked (i.e gets focus), the scrolling is adjusted so that the listbox is forced to be in view fully..
----------- CLICK => ------------
| panel | | |
| --| | -----|
| | |<-listbox | | ||
| --| | -----|
|<===== >| |< ======>|
----------- ------------
There are a couple of methods in the containercontrol that I believe have to do with this, one named ScrollActiveControlIntoView(). But of course it is private so I can't override it, can I?
Is there a suitable Windows message that I can capture and ignore in the wndproc for example, for this not to happen? What is the thread of action taken by windows when this happens, what messages are sent, etc. Does anyone know?
|
|
|
|
|
----------- CLICK => ------------
| panel | | |
| --| | -----|
| | |<-listbox | | ||
| --| | -----|
|<===== >| |< ======>|
----------- ------------
|
|
|
|
|
Nice ASCII!
Set AutoScroll to false . See the documentation for ScrollableControl.AutoScroll for more information.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|