|
Hi,
I have problem in graphics
in this code no compiletime error occurs.
private void Lines(System.Windows.Forms.PaintEventArgs e)<br />
{<br />
Graphics g = e.Graphics;<br />
Pen pen = new Pen(Color.Red,4);<br />
g.DrawLines(pen,10,10,25,25); <br />
}
But when i call this method with Onclick event of a button this error occurs in runtime:
"Object refrence not set a instance of an object."
and when i want to use his code
Graphics g = new Graphics();
this error occurs :
No overloaded method 'Graphics' takes '0' arguments
I want to call a method and paint some lines in my form but i dont want to override OnPaint method of form
like this :
protected override void OnPaint(<br />
PaintEventArgs paintEvent )<br />
<br />
{<br />
Graphics g = paintEvent.Graphics;<br />
Pen pen = new Pen(Color.Red,4);<br />
g.DrawLines(pen,10,10,25,25); <br />
}
How i can do this ?
---------------------
Areff Bahrami(KAVEH)
Areff.HB@Gmail.com
---------------------
|
|
|
|
|
Areff wrote: I want to call a method and paint some lines in my form but i dont want to override OnPaint method of form
That's the problem. You want to do it all wrong. You're getting that error as you're passing null as the argument, or you're passing a PaintEventArgs that doesn't contain a Graphics object. Either way, not overriding the paint method means you want to write bad code that won't work properly. Why would you want to do that ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
with .Net
---------------------
Areff Bahrami(KAVEH)
Areff.HB@Gmail.com
---------------------
|
|
|
|
|
I have no idea what you mean by that. Using C# means you'll be using .NET. That doesn't change what I said.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Christian Graus wrote: not overriding the paint method means you want to write bad code that won't work properly
I always use the Graphics.FromHandle function to get the Graphics object, why should this be bad code?
|
|
|
|
|
You can get a Graphics object from a windows (or control) handle.
I think the syntax is: Graphics.FromHandle(...);
Pass it a handle from a panel or button, or whatever tot draw on that control...
Hope this helps...
|
|
|
|
|
Use
Graphics g = this.CreateGraphics() in your constructor, and declare g as a class member so you can use it elsewhere. I've used this approach a few times to support custom double buffering on a control. If you want your control to display everything flickerfree you should implement this too (draw into a bitmap and flip it over to your graphics now and then), this can be handy for controls that need a high refresh rate (30fps). If you're not doing that, use OnPaint().
|
|
|
|
|
Hi,
What can i do if an ObjectDisposedException ocures?
I have 2 forms, 1 is calling 2. If i close 2 and restart it again from form1 i get that Exception.
I want to be able to restart the form2 again through from1.
This exception is pointing to the line which starts with:
Show();
Any suggestions?
Thanks in advance!
|
|
|
|
|
You have disposed of the form, you need to create a new instance of form2, as in use new to reassign the variable, or change the code so it does not get disposed.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hi,
That worked, thank you!
|
|
|
|
|
Use the Hide method instead of Close, if you intend to reuse it.
--------
"I say no to drugs, but they don't listen."
- Marilyn Manson
|
|
|
|
|
I don't understand why anyone would intentionally use a partial class. Keep in mind I'm a C++ programmer who occasionally has to work on .Net crap.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
It's used primarily for:
1) Breaking up large class files to allow parallel development, which might be otherwise prevented in a single file.
2) Splitting up designer code from user code to allow MS to modify its code without disturbing yours (and visa versa).
And I would hardly think .NET is crap...since C++ is just the predecessor of C#.
|
|
|
|
|
Andrew Rissing wrote: since C++ is just the predecessor of C#.
Rubbish. C# is based on Java. It, like Java, has C++ like syntax to try and get C++ programmers to use it, but they are chalk and cheese.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Well, I don't disagree that C# and Java are similiar, but C# is more like the marriage of C++ and Java.
Personally, a language is a language is a language. If it gets you to what you want with the least amount of pain/effort all the better. They're all just appropriate tools for certain tasks.
|
|
|
|
|
Andrew Rissing wrote: but C# is more like the marriage of C++ and Java.
How ?
Andrew Rissing wrote: If it gets you to what you want with the least amount of pain/effort all the better. They're all just appropriate tools for certain tasks.
I don't disagree, I use C++ and C# equally, and am happy with both. But, C# is *not* an evolution of C++, it's very different.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
C# is C++ style with Java's managed environment (if you consider Java being the 'originator' of such).
And yes, C# is very different from C++. It was from the ground up a new language (compiler/design/etc.). But the point was merely that many of the constructs/ideas from C++ found their way into C#. They designed C# to be a natural transition for C/C++ programers into the managed world. Hence, why I said it was predecessor.
I just think it was funny for someone who's a C++ programmer to knock C# because of what it was partly designed off of.
|
|
|
|
|
Christian Graus wrote: C# is based on Java.
C# is influenced by Java, C++, Delphi, Visual Basic and a few other things, according to one of the co-designers.
Kevin
|
|
|
|
|
You've never broken a C++ class into multiple cpp files, so that different areas can be checked out to different people at the same time ?
It is in fact a C++ feature that was late arriving to C#.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Christian Graus wrote: You've never broken a C++ class into multiple cpp files, so that different areas can be checked out to different people at the same time ?
Never, in 17 years of C++ development, have I ever done that. Of course, the largest team I've ever been on was comprised of just three programmers, but still, the apps we were developing consisted of as many as 720,000 lines of code (a medical records database app consistig of over 4700 source files - the team has never been larger than three programmers) with the smallest app being just 175,000 lines (a federal and state estate tax calculation and flowcharting app with just over 1200 source files - the team was two programmers).
We weren't religiously adhering to strict OOP design/coding, but we tried to plan each class as carefully as we could before implenting it. In all that time, I've used multiple inheritance just twice, and never needed to make "friend" classes or use the "goto" keyword.
Now, back to the original question (and beyond what Christian provided), what are partial classes good for?
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Andrew answered your question just fine.
Just because you don't use something that way, it doesn't mean that it's not it's intended use. It's just like the goto command, it's there even if you never use it.
---
b { font-weight: normal; }
|
|
|
|
|
John Simmons / outlaw programmer wrote: Never, in 17 years of C++ development, have I ever done that
I have to admit, the place it was most used the app was poorly designed, too much stuff going on in the View and Document classes of an MFC app. It's still a valid approach IMO, but not the way I saw it done.
But in .NET, the big thing is hiding the auto generated code, which just gets edited by newbies and clutters the class. I also used them recently, I have an app that has four threads running, I broke the code used by each thread into a partial class, to help me organise my thoughts in how it all worked.
John Simmons / outlaw programmer wrote: Now, back to the original question (and beyond what Christian provided), what are partial classes good for?
I've given another example. Any example will relate to organisation of code. The files get turned into one class, so there's no benefit beyond ways they help to organise code for the benefit of humans.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Got my 5, only to level out. I don't see why you got down voted for asking a question ( even one with a little attitude... )
Not that I expect you care too much about post voting
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
*All* of my questions ahve a little attitude.
I don't care about post voting, but article voting based on politics just pissees me off.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Little attitude?
Posting about .Net crap in a C# forum is a clear "Vote me down!" invitation.
Robert
|
|
|
|