What's the size of the window

K

K Viltersten

Just for fun i tested to draw a diagonal
line and discovered that
int w = this.Width, h = this.Height;
g.drawLine (0, 0, w, h);
doesn't shoot right. It seems that the
line start at the right position but it
reaches the bottom part before it comes
to touch the right edge...

In Swing there was an actual set of
components constituting a window. Is
this the case with C# as well? How do i
obtain the actual limits of what i see
as the drawable part of the form?
 
J

Jeroen Mostert

K said:
Just for fun i tested to draw a diagonal
line and discovered that int w = this.Width, h = this.Height;
g.drawLine (0, 0, w, h);
doesn't shoot right. It seems that the
line start at the right position but it
reaches the bottom part before it comes
to touch the right edge...
..Width gives the total width of a control, including the non-client area
(title bar, scrollbars, edges, etc.) Since you're only painting in the
client area, you'll want that instead: Control.ClientRectangle.Width and
Control.ClientRectangle.Height, respectively.
 
J

Jeroen Mostert

K said:
Great! Thank you.

Of course, i needed to retract the height of the
status strip but that one was obvious, once i've
seen the image appearing.
If I can be Captain Obvious for a moment: why don't you just use an
auto-resize Image control instead of molesting the Form directly? That way
you know exactly what the size of your area is and don't need to factor in
other controls. If an Image is too heavy for you, you could still use a
Panel or custom control or somesuch. The basic point is that your job is a
lot easier if your entire area is dedicated to painting.
 
K

K Viltersten

Just for fun i tested to draw a diagonal
.Width gives the total width of a control, including
the non-client area (title bar, scrollbars, edges,
etc.) Since you're only painting in the client area,
you'll want that instead: Control.ClientRectangle.
Width and Control.ClientRectangle.Height,
respectively.

Great! Thank you.

Of course, i needed to retract the height of the
status strip but that one was obvious, once i've
seen the image appearing.
 
J

Jeroen Mostert

K Viltersten wrote:
Also - "auto-resize Image control" seems not to be
there on my toolbar. Do i miss it or was it just a
description of a functionality that can be applied
for an e.g. panel?
I'm sorry, I'm getting my frameworks confused. What I'm talking about is
called a PictureBox in .NET (Image is the class that actually represents
images; PictureBox is a control for holding images). It's commonly used for
static or loaded images, but it works just as well for dynamic images.

However, it's not as appropriate for images that need to dynamically repaint
if they're resized (PaintBox can do bitmap-based resizing, but that's
usually not pretty). For continuous repainting it's easier to just
appropriate the client area of a Panel control, or write your own control if
you really want to get fancy. Directly painting on the Form, while an
obvious technique, is not as comfortable.
 
K

K Viltersten

Jeroen Mostert said:
If I can be Captain Obvious for a moment: why don't you just use an
auto-resize Image control instead of molesting the Form directly? That way
you know exactly what the size of your area is and don't need to factor in
other controls. If an Image is too heavy for you, you could still use a
Panel or custom control or somesuch. The basic point is that your job is a
lot easier if your entire area is dedicated to painting.

Mostly, because i started that way and i WILL show
the stupid computer that it CAN be done.

After that, i'll extend a panel, yes. Never the less,
than you for the observation.

Also - "auto-resize Image control" seems not to be
there on my toolbar. Do i miss it or was it just a
description of a functionality that can be applied
for an e.g. panel?
 
K

K Viltersten

Also - "auto-resize Image control" seems not to be
I'm sorry, I'm getting my frameworks confused. What
I'm talking about is called a PictureBox in .NET.
It's commonly used for static or loaded images, but
it works just as well for dynamic images.

I believe we're talking about different kind of
painting. I'll be performing computations and the
results of these will be graphically presented to the
user. So, it's not so much a photo i'll be drawing
but rather two, three axis and a graph.

As far i've seen, there are no packages available for
charting that are open source and will do what i wish
them to do. So, i'll be writing an own.
Directly painting on the Form, while an obvious
technique, is not as comfortable.

I agree bu tas i pointed out above, there will be no
other way, as far as my current understanding is.
Please feel welcome to correct me if i'm mistaken.
 
J

Jeroen Mostert

K said:
I believe we're talking about different kind of
painting.

I don't think so. "Painting" is just the general Windows term for "drawing
stuff on the screen whenever Windows asks you to". The source of what you're
painting doesn't matter.
I'll be performing computations and the results of these will be
graphically presented to the user. So, it's not so much a photo i'll be
drawing but rather two, three axis and a graph.
Yes, but you could draw that on an Image in a PictureBox exactly as you
would draw it on a Form (they're both just "things to draw on", and they
both use a Graphics to draw). However, like I said, if your image needs to
change every time you resize it (and if you're drawing a chart, that seems
likely) then using an Image in a PictureBox isn't appropriate, because
resizing that all the time is inefficient.
As far i've seen, there are no packages available for charting that are
open source and will do what i wish them to do.

Did you run down the entire list at
http://csharp-source.net/open-source/charting-and-reporting? :)
So, i'll be writing an own.
That's fine, but then you'll definitely want to create a ChartControl or
something along those lines, so you can draw to your heart's content without
bothering other controls. This control will have its own client area, so you
won't have to bother with computing effective areas anymore.

It's then a matter of dropping that ChartControl on your form and away you
go. It won't matter whether the form has scrollbars, strips, status areas or
whatever.
I agree bu tas i pointed out above, there will be no
other way, as far as my current understanding is.
Please feel welcome to correct me if i'm mistaken.
I think you are. At the very least, you could draw on a control that's fully
dedicated to displaying your content, rather than a Form. Like I said, you
could also abuse a separate empty Panel for this, which is at least
marginally easier.
 
C

christery

I think you are. At the very least, you could draw on a control that's fully
dedicated to displaying your content, rather than a Form. Like I said, you
could also abuse a separate empty Panel for this, which is at least
marginally easier.

I agree, I wrote a chart drawing program from scratch, comparing it
with ms chart for a school project, and just get it to scale right as
in 5-73 are the value span it should do 0-100 or 0- 75 and then the
spacing, 5,10 for the axis and so on is easy
but if 0,1-0,73 then zero at 0, top at 1, and the dividers at 0,1...
opps forgot about that (said in the project)
got it mostly right but it was not that easy with the maths...
logics, twips, deadline...
//CY
 
K

K Viltersten

Did you run down the entire list at

Yes. I didn't exactly went to the verge of
extreme scrutiny but as far i could see,
not what i need. Thanks for trying, though.
That's fine, but then you'll definitely want
to create a ChartControl or something...

I'll inherit a Panel and give it some methods
and instance variables for data handling and
storing. Would that be wise in your opinion?
I think you are. At the very least, you could draw on
a control that's fully dedicated to displaying your
content, rather than a Form. Like I said, you could
also abuse a separate empty Panel for this, which is
at least marginally easier.

I ment: correct me if i'm wrong in my view that
there are no advanced charting tools with open
source code. The ones that would fit are
provided expensively or at least only compiled.
 
J

Jeroen Mostert

K said:
I'll inherit a Panel and give it some methods
and instance variables for data handling and
storing. Would that be wise in your opinion?
No, since your chart is not a Panel. You'll want to inherit from a base
class like Control or ScrollableControl instead. Luckily, there's lots of
information out there on creating custom controls.
I ment: correct me if i'm wrong in my view that
there are no advanced charting tools with open
source code. The ones that would fit are provided expensively or at
least only compiled.
Oh, yes, I'm sure you checked that well enough. There are probably some
great open source solutions in C++ or Java, which will be of little use to
you since you're using C# -- the latest new thing we can all rewrite our
existing code in. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top