|
ok for System.Drawing.SystemColors...
But I don't get it for the derived control.
What I wanna do is to write my own control that will get some methods. these methods will control the drawing.
|
|
|
|
|
bouli wrote:
What I wanna do is to write my own control that will get some methods. these methods will control the drawing
public class myControl : System.Windows.Forms.UserControl
{
public myControl()
{
}
....
private void Control_Paint(object sender,PaintEventHandler e)
{
}
}
Mazy
No sig. available now.
|
|
|
|
|
ok, thanks!
|
|
|
|
|
Hi,
Just one last question about this thread...
Can you show me how can I use the control in the main form?
I have inserted a label and? how can I link it to my new control?
Best regards.
Thanks.
|
|
|
|
|
bouli wrote:
I have inserted a label and? how can I link it to my new control?
What do you mean exactly? You mean you add that label to your UserControl? It is now in your .cs file as a private member. You can use it like this there:
lbale1.Text = "Hello";
User the search textbox at the top of this page to find articles in this site about UserControl for motr information.
Mazy
No sig. available now.
|
|
|
|
|
I want to use my new created control... this control graphically shows the content of an array
|
|
|
|
|
bouli wrote:
I want to use my new created control
Right click on your ToolBox and select 'Customize ToolBox' option. From .NET Component tab, with Browse button , select assembly of your control and click OK. It is now added to your toolbox and you can drag and drop it on your form.
Mazy
No sig. available now.
|
|
|
|
|
ok
I understood how to use and draw my own controls in C#
It's very different from MFC...
|
|
|
|
|
For one thing, you didn't hook-up your Paint event handlers. Remember, he's a n00b.
Also, never use events in a derived class - it's too slow and doesn't provide the control you might need (such as NOT calling the base class's OnPaint handler). Instead, always override the related method for an event when deriving from a class:
public class MyControl : UserControl
{
public MyControl()
{
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
}
}
-----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-----
|
|
|
|
|
Heath Stewart wrote:
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); // Allows base class to paint and raise the Paint event. // Draw }
Yah, Thanks for correction.
Mazy
No sig. available now.
|
|
|
|
|
Ok, it works!!
Thanks
|
|
|
|
|
Ok, it works that way... it's almost like MFC... just override the event...;P
|
|
|
|
|
Point of clarification: OnPaint is not an event. It's a method that, in the defining class, raises the Paint event before or after optionally performing some action (like any default painting). When you override this, you pre-empt the event being raised (which is why you call base.OnPaint ) and actually override all the functionality of that method since it's virtual. If you don't call base.OnPaint , any painting that the base class, or its base class, etc., need to do won't be performed.
For more information about events in delegates in .NET, see Handling and Raising Events[^] in the MSDN Online Library.
-----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-----
|
|
|
|
|
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
|
|
|
|