473,703 Members | 4,345 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How To center a logical drawing space much bigger than your screen?

I have a logical drawing space much bigger than the viewport (the
screen) and I'd like to center the viewport (the screen) to be at the
center of the logical drawing space. After following the excellent
transforms specified on Bob Powell's site, I still wonder if there's
an easier way of centering it than the following procedure?

Here is what I do now (it's awkward but it works):

1) I follow the transforms specified on Bob Powell's site, which are
required to get the scroll bars to work correctly, and the mouse
coordinates to work with the viewport (screen) and also to zoom.

2) to get the scrollbars to zoom to the very end of the logical
drawing space, I create a series of three tiny buttons (size (1,1) and
invisible) in the constructor of the form (make sure they are declared
before InitializeCompo nent(); in your partial class or you might get a
runtime error): button 1 = Top left corner of logical drawing space;
button 2 = bottom right corner, and button 3 = midway of your logical
drawing space, which you have to know the dimensions of your logical
drawing space in pixels ahead of time. I also adjusted the button 3 a
bit using some logic to center it better, especially if you are, as
here, using a split panel.

3) In the constructor, and ONLY in the constructor (I have no idea
why), you do this:

button3Center = new Point(xCenterof Board, yCenterofBoard) ; //calculate
center of board from your logical drawing space ahead of time
button1= new Point(0,0);
button1= new Size(1,1);
//etc for button2...

this.mySplitCon tainer1.Panel2. Controls.Add(th is.button1);
this.splitConta iner1.Panel2.Co ntrols.Add(this .button3Center; )
this.splitConta iner1.Panel2.Co ntrols.Add(this .button2);

//need next two if statements together to ensure stable
behavior
//you can also add the below if statements when resizing, in a On
Resize handler, but only the two below if statements, not any of the
above

if (button1.CanFoc us)
{
button1.Focus() ;
}

if (button3Center. CanFocus)
{
button3Center.F ocus();
}
//

//now, the form when it loads up will have the logical drawing space
that is near button3Center show up on the screen. This way the
viewport (screen) is 'centered' at around the middle or center of the
logical drawing space.

For some reason you cannot put this logic anywhere else (like Resize
or Scroll). Further, you cannot set any 'anchor' properties for your
three buttons, such as: button1.Anchor =
System.Windows. Forms.AnchorSty les.None; // this will mess up your
centering.

Anyway, the above works fine, though I'd like to know if somebody has
a cleaner way. I tried playing around in the OnPaint handler with
Matrix mx = new Matrix (1,0,0,0,client size.Width/2, clientsize.Heig ht/
2); and variations (such as making clientsize negative, which had
promise as it shifted the logical drawing space but I could not quite
get the mouse coordinates to work, see Bob Powell's site on this).

RL
Nov 10 '08 #1
7 3556
On Nov 9, 5:31*pm, raylopez99 <raylope...@yah oo.comwrote:
button3Center = new Point(xCenterof Board, yCenterofBoard) ; //calculate
center of board from your logical drawing space ahead of time
button1= new Point(0,0);
button1= new Size(1,1);
//etc for button2...
Small correction: above should read:

button3Center.l ocation = new Point(xCenterof Board, yCenterofBoard) ;
button1.locatio n = new Point(0,0);

//etc

RL

Nov 10 '08 #2
Further, if you have several resolutions, such as with Zoom (i.e. 50%,
75%, 100%, 150%), you have to set up a complicated Case statement and
setup buttons for each such resolution every time you switch
resolution, using :
this.mysplitCon tainer.Panel`.C ontrols.Add(But ton1);
and .Controls.Remov e(...), for each pairs of these buttons.

There has to be a better way of doing this I would imagine.

RL
Nov 10 '08 #3
You're working too hard..
What is that with the buttons all about? I have no clue what you're
explaining...

How can percentages require a complicated case statement?? you divide by 100
and multiply by whatever percentage you like...

See after my signature for some inspiration...
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

/// <summary>
/// The canvas class
/// </summary>
[
ToolboxItem(tru e),
ToolboxBitmap(t ypeof(Canvas)," CanvasIcon.bmp" )
]
public class Canvas : ScrollableContr ol
{

/// <summary>
/// Constructor
/// </summary>
public Canvas()
{
this.SetStyle(
ControlStyles.A llPaintingInWmP aint |
ControlStyles.U serPaint |
ControlStyles.R esizeRedraw ,true);
}

private bool _doubleBuffer;

[
Category("Behav ior"),
Description("Se t true to enable double buffering")
]
public bool DoubleBuffer
{
get{return _doubleBuffer;}
set
{
_doubleBuffer=v alue;
if(value)
{
SetStyle(Contro lStyles.DoubleB uffer,true);
}
else
{
SetStyle(Contro lStyles.DoubleB uffer,false);
}
Invalidate();
}
}

private Color _pageColor=Colo r.White;

[
Category("Appea rance"),
Description("Th e base color of the page")
]
public Color PageColor
{
get{return _pageColor;}
set
{
_pageColor=valu e;
Invalidate();
}
}

private bool _clipToPage;

[
Category("Behav ior"),
Description("Ge ts or sets the clipping flag. When true no drawing is
allowed outside page boundaries")
]
public bool ClipToPage
{
get{return _clipToPage;}
set
{
_clipToPage=val ue;
Invalidate();
}
}

private Size _pageSize=new Size(640,480);

[
Category("Appea rance"),
Description("Th e size of the virtual page")
]
public Size PageSize
{
get{return _pageSize;}
set
{
_pageSize=value ;
OnPageSizeChang ed(EventArgs.Em pty);
}
}

protected virtual void OnPageSizeChang ed(EventArgs e)
{
CalcScroll();
if(PageSizeChan ged!=null)
PageSizeChanged (this,e);
}

public event EventHandler PageSizeChanged ;

private float _zoom=1.0f;

[Category("Behav ior"),
Description("Th e multiplying factor for the zoom level"),
DefaultValue(1. 0f)]
public float Zoom
{
get{return _zoom;}
set{
_zoom = value;
//A zoom may not be negative
if(_zoom<0)
_zoom=Math.Abs( _zoom);
//a zoom may be very small but never zero.
if(_zoom==0)
_zoom=0.000001f ;
//The scrollbars should be recalculated
CalcScroll();
//and the host application code informed if needs be
OnZoomChanged(E ventArgs.Empty) ;
}
}

void CalcScroll()
{
Size cs = new
Size((int)(this ._pageSize.Widt h*_zoom),(int)( this._pageSize. Height*_zoom));
this.AutoScroll MinSize=cs;
Invalidate();
}

protected override void OnSizeChanged(E ventArgs e)
{
CalcScroll();
base.OnSizeChan ged(e);
}

protected override void OnPaint(PaintEv entArgs e)
{
base.OnPaintBac kground(e);

Matrix mx=new Matrix(_zoom,0, 0,_zoom,0,0);

Size s=new
Size((int)(this .ClientSize.Wid th*(1f/_zoom)),(int)(t his.ClientSize. Height*(1f/_zoom)));

if(s.Width>Page Size.Width)
mx.Translate((s .Width/2)-(_pageSize.Widt h/2),0);
else
mx.Translate((f loat)this.AutoS crollPosition.X *(1f/_zoom),0);

if(s.Height>Pag eSize.Height)
mx.Translate(0, (s.Height/2)-(this._pageSize .Height/2)+(this.AutoSc rollPosition.Y) );
else
mx.Translate(0, (float)this.Aut oScrollPosition .Y*(1f/_zoom));

e.Graphics.Tran sform=mx;

SolidBrush b=new SolidBrush(Colo r.FromArgb(64,C olor.Black));
e.Graphics.Fill Rectangle(b,new Rectangle(new Point(20,20),Pa geSize));
b.Color=PageCol or;
e.Graphics.Fill Rectangle(b,new Rectangle(new Point(0,0),Page Size));

if(ClipToPage)
e.Graphics.SetC lip(new Rectangle(0,0,P ageSize.Width,P ageSize.Height) );

base.OnPaint(e) ;

}

public event EventHandler ZoomChanged;

protected virtual void OnZoomChanged(E ventArgs e)
{
if(this.ZoomCha nged!=null)
ZoomChanged(thi s,e);
Invalidate();
}

protected virtual MouseEventArgs BacktrackMouse( MouseEventArgs e)
{
Matrix mx=new Matrix(_zoom,0, 0,_zoom,0,0);

Size s=new Size( (int)(this.Clie ntSize.Width*(1 f/_zoom)),
(int)(this.Clie ntSize.Height*( 1f/_zoom)));

if(s.Width>Page Size.Width)
mx.Translate((s .Width/2)-(_pageSize.Widt h/2),0);
else
mx.Translate((f loat)this.AutoS crollPosition.X *(1f/_zoom),0);

if(s.Height>Pag eSize.Height)
mx.Translate(0, (s.Height/2)-(this._pageSize .Height/2)+
(this.AutoScrol lPosition.Y));
else
mx.Translate(0, (float)this.Aut oScrollPosition .Y*(1f/_zoom));

mx.Invert();

Point[] px=new Point[]{new Point(e.X,e.Y)} ;

mx.TransformPoi nts(px);

MouseEventArgs et=new
MouseEventArgs( e.Button,e.Clic ks,px[0].X,px[0].Y,e.Delta);

return et;
}

protected override void OnMouseMove(Mou seEventArgs e)
{
MouseEventArgs et=this.Backtra ckMouse(e);
base.OnMouseMov e(et);
}

protected override void OnMouseUp(Mouse EventArgs e)
{
MouseEventArgs et=this.Backtra ckMouse(e);
base.OnMouseUp( et);
}

protected override void OnMouseDown(Mou seEventArgs e)
{
MouseEventArgs et=this.Backtra ckMouse(e);
base.OnMouseDow n(et);
}
}


"raylopez99 " <ra********@yah oo.comwrote in message
news:1c******** *************** ***********@q26 g2000prq.google groups.com...
Further, if you have several resolutions, such as with Zoom (i.e. 50%,
75%, 100%, 150%), you have to set up a complicated Case statement and
setup buttons for each such resolution every time you switch
resolution, using :
this.mysplitCon tainer.Panel`.C ontrols.Add(But ton1);
and .Controls.Remov e(...), for each pairs of these buttons.

There has to be a better way of doing this I would imagine.

RL
Nov 12 '08 #4
On Nov 10, 3:00*pm, "Bob Powell [MVP]" <bob@_spamkille r_bobpowell.net >
wrote:
You're working too hard..
What is that with the buttons all about? I have no clue what you're
explaining...

How can percentages require a complicated case statement?? you divide by 100
and multiply by whatever percentage you like...

See after my signature for some inspiration...

--
Bob Powell [MVP]
Visual C#, System.Drawing

WOW! Bob Powell has emailed me! This is cool. Bob you are a real
inspiration and my program would not work without your BacktrackMouse
method, which I got from your site. I notice in your example above
(which I will compile and examine later) it's also present.

WHat I notice (just looking at your code) is that the OnPaint and
Mouse handlers have the same matrix transform, which is great, and
same as in my program. You have to sync screen and mouse.

What I do, which you also do with different and better logic, is to
try and get the scroll bars to work to scroll past my drawing object:
a big rectangle. I have a huge rectangle that is bigger than the
screen. How to get to the bottom of this rect? Well as you know if
you just paint it, it will be truncated (only the upper left corner
will be shown). So to get to the lower right corner, I do the
following: place a small invisible button (create it, add it) at the
lower right corner. This works. But, if you change the _zoom factor
(I have a series of set zooms, e.g. a normal, a small, a large, extra
large, etc), you must .remove this button and .add it again to the new
rect., otherwise you cannot scroll to the lower right corner of the
new rectangle.

It's complicated (involving numerous enums and bit flags) but it
works. I can add any number of fixed (set) resolutions this way:
i.e., 25% of normal, 75% of normal, 100% (default) and 200%, etc, but
I cannot do a "variable" resolution using a slider bar for example--is
this what your example shows? If so, your way is clearly superior.

Any words appreciated. Thanks again Bob! I think MSDN should pay you
money for providing your service--it's really helpful and MSDN had
nothing on Matrices (as easy to understand as yours, or I could not
find it).

RL

PS--besides getting to the bottom of the rectangle I also want the
viewing area (viewport) to be centered at the center of the
rectangle. I do this by adding yet another small invisible button to
the center of the rectangle, using .add, .remove as necessary,
everytime the resolution is changed. If you have any better way of
doing this please let me know. Thanks again!

I plan on looking at your code but feel free to comment anyway--just a
few words of encouragement is all I need.
Nov 12 '08 #5
If you look at the canvas code I sent you, the control is quite happy to
deal with large images.

The scroll bars are set using the info from my "understand ing autoscroll"
article.

Centering on the screen is easy. Just set the origin of the picture to:

center of screen - width/height of picture /2
--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
"raylopez99 " <ra********@yah oo.comwrote in message
news:bc******** *************** ***********@u18 g2000pro.google groups.com...
On Nov 10, 3:00 pm, "Bob Powell [MVP]" <bob@_spamkille r_bobpowell.net >
wrote:
You're working too hard..
What is that with the buttons all about? I have no clue what you're
explaining...

How can percentages require a complicated case statement?? you divide by
100
and multiply by whatever percentage you like...

See after my signature for some inspiration...

--
Bob Powell [MVP]
Visual C#, System.Drawing

WOW! Bob Powell has emailed me! This is cool. Bob you are a real
inspiration and my program would not work without your BacktrackMouse
method, which I got from your site. I notice in your example above
(which I will compile and examine later) it's also present.

WHat I notice (just looking at your code) is that the OnPaint and
Mouse handlers have the same matrix transform, which is great, and
same as in my program. You have to sync screen and mouse.

What I do, which you also do with different and better logic, is to
try and get the scroll bars to work to scroll past my drawing object:
a big rectangle. I have a huge rectangle that is bigger than the
screen. How to get to the bottom of this rect? Well as you know if
you just paint it, it will be truncated (only the upper left corner
will be shown). So to get to the lower right corner, I do the
following: place a small invisible button (create it, add it) at the
lower right corner. This works. But, if you change the _zoom factor
(I have a series of set zooms, e.g. a normal, a small, a large, extra
large, etc), you must .remove this button and .add it again to the new
rect., otherwise you cannot scroll to the lower right corner of the
new rectangle.

It's complicated (involving numerous enums and bit flags) but it
works. I can add any number of fixed (set) resolutions this way:
i.e., 25% of normal, 75% of normal, 100% (default) and 200%, etc, but
I cannot do a "variable" resolution using a slider bar for example--is
this what your example shows? If so, your way is clearly superior.

Any words appreciated. Thanks again Bob! I think MSDN should pay you
money for providing your service--it's really helpful and MSDN had
nothing on Matrices (as easy to understand as yours, or I could not
find it).

RL

PS--besides getting to the bottom of the rectangle I also want the
viewing area (viewport) to be centered at the center of the
rectangle. I do this by adding yet another small invisible button to
the center of the rectangle, using .add, .remove as necessary,
everytime the resolution is changed. If you have any better way of
doing this please let me know. Thanks again!

I plan on looking at your code but feel free to comment anyway--just a
few words of encouragement is all I need.
Nov 13 '08 #6
Bob,

Thanks again. I tried to compile your code in your OP this morning,
and though it compiled I could not get it to work as a 'form' (I tried
making it a form and could not get it to load as a form, after trying
for example Canvas myCanvasForm = new Canvas();. It might be missing
some resource files or something (I notice it references some image
file).

Anyway, it did compile, and I printed it out and will go through it.
Any further comments appreciated. I really do need one complete
example for my library (for future reference--right now my kludge way
of doing things 'works' and that's 'fine for now').

Cheers from a time zone about -7 hours behind yours...

RL

On Nov 12, 11:37*pm, "Bob Powell [MVP]" <b...@spamkille rbobpowell.net>
wrote:
If you look at the canvas code I sent you, the control is quite happy to
deal with large images.

The scroll bars are set using the info from my "understand ing autoscroll"
article.

Centering on the screen is easy. Just set the origin of the picture to:

center of screen - width/height of picture /2

--
--
Bob Powell [MVP]
Visual C#, System.Drawing
Nov 13 '08 #7
On Nov 12, 11:37*pm, "Bob Powell [MVP]" <b...@spamkille rbobpowell.net>
wrote:
If you look at the canvas code I sent you, the control is quite happy to
deal with large images.
No, it did not work, though I finally got it to work past just
compilation. Reproduced below. It did give a nice white screen with
a grey border that can be resized to any arbitrary size, using the
_zoom, but if you set _zoom to a very large number, say 2.0F, then no
scroll bars show up (despite, using the Designer Wizard, I did check
the scrollbars property to True).
>
The scroll bars are set using the info from my "understand ing autoscroll"
article.
Is that in your canvas code?
>
Centering on the screen is easy. Just set the origin of the picture to:

center of screen - width/height of picture /2

--
Where do I add this? In what function call / event handler?

--
Bob Powell [MVP]
Visual C#, System.Drawing
Con permission, I have a few more optional questions (you can feel
free to answer as many or few as you please; I appreciate your time):

1) below is my code. I notice that the Color.White background seems
to not allow a very bright overlay of say a red rectangle (see the
rectangle I draw below). It comes out (or so it seems) a bit pink,
like the white background is bleeding through.

2) How to use scrollbars, as I mentioned above. AutoScrollPosit ion is
shown throughout the code, but, unlike my working example in the
original thread (which was inspired by your website examples), the one
that uses hidden tiny buttons, this time the form doesn't scroll. If
you can point out in your code where this feature is, maybe I can
check that I didn't copy and paste wrong--since to make the program
work past the compile stage I had to create a form from scratch and
copy and paste selectively, until everything (I hope) was copied from
your code.

3). Minor but important for me: this line made things work without
the invalidation problem: "this.SetSt yle
( ControlStyles.A llPaintingInWmP aint | ControlStyles.U serPaint |
ControlStyles.R esizeRedraw ,true); "
How to set this using the Wizard (I like to use the wizard whenever
possible)?

Thank you.

I like your "canvas" example for my library because, though the
scrollbars don't work, for _zoom < 1.0F you can resize the window by
grapping a corner, and the white canvas with grey border will
automatically stay in the middle of the resized window, and, of
course, the BackTrackMouse function and Matrix will correctly adjust
your mouse coordinates (I added a function for right-button down to
test this, as you can see below). Very nice, but I do like the idea of
scrollbars and want to add them.

RL

using System;
using System.Collecti ons.Generic;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows. Forms;
using System.Drawing. Drawing2D;

namespace Canvas2
{
public partial class Canvas : Form
{
private Size _pageSize; // = new Size(640, 480);
private bool _clipToPage;
private float _zoom;
private Color _pageColor; // = Color.White;

public Canvas()
{
InitializeCompo nent();
_pageSize = new Size(640, 480);
_zoom = 0.5F;
_pageColor = Color.White; //Color.Transpare nt //
Color.Empty; //do not work, give dark background, use Color.White
//

this.SetStyle( ControlStyles.A llPaintingInWmP aint |
ControlStyles.U serPaint | ControlStyles.R esizeRedraw ,true);

}

// private Color _pageColor = Color.White;
[
Category("Appea rance"),
Description("Th e base color of the page")
]
public Color PageColor
{
get { return _pageColor; }
set
{
_pageColor = value;
Invalidate();
}
}

// private bool _clipToPage;
[
Category("Behav ior"),
Description("Ge ts or sets the clipping flag. When true no
drawing is allowed outside page boundaries")
]
public bool ClipToPage
{
get { return _clipToPage; }
set
{
_clipToPage = value;
Invalidate();
}
}
// private Size _pageSize = new Size(640, 480);
[
Category("Appea rance"),
Description("Th e size of the virtual page")
]
public Size PageSize
{
get { return _pageSize; }
set
{
_pageSize = value;
OnPageSizeChang ed(EventArgs.Em pty);
}
}

protected virtual void OnPageSizeChang ed(EventArgs e)
{
CalcScroll();
if (PageSizeChange d != null)
PageSizeChanged (this, e);
}
public event EventHandler PageSizeChanged ;

void CalcScroll()
{
Size cs = new Size((int)(this ._pageSize.Widt h * _zoom),
(int)(this._pag eSize.Height * _zoom));
this.AutoScroll MinSize = cs;
Invalidate();
}

[Category("Behav ior"),
Description("Th e multiplying factor for the zoom level"),
DefaultValue(1. 0f)]
public float Zoom
{
get { return _zoom; }
set
{
_zoom = value;
//A zoom may not be negative
if (_zoom < 0)
_zoom = Math.Abs(_zoom) ;
//a zoom may be very small but never zero.
if (_zoom == 0)
_zoom = 0.000001f;
//The scrollbars should be recalculated
CalcScroll();
//and the host application code informed if needs be
OnZoomChanged(E ventArgs.Empty) ;
}
}

public event EventHandler ZoomChanged;
protected virtual void OnZoomChanged(E ventArgs e)
{
if (this.ZoomChang ed != null)
ZoomChanged(thi s, e);
Invalidate();
}

protected override void OnPaint(PaintEv entArgs e)
{
base.OnPaintBac kground(e);

Matrix mx = new Matrix(_zoom, 0, 0, _zoom, 0, 0);
Size s = new Size((int)(this .ClientSize.Wid th * (1f /
_zoom)), (int)(this.Clie ntSize.Height * (1f / _zoom)));
if (s.Width PageSize.Width)
mx.Translate((s .Width / 2) - (_pageSize.Widt h / 2),
0);
else
mx.Translate((f loat)this.AutoS crollPosition.X * (1f /
_zoom), 0);
if (s.Height PageSize.Height )
mx.Translate(0, (s.Height / 2) -
(this._pageSize .Height / 2) + (this.AutoScrol lPosition.Y));
else
mx.Translate(0, (float)this.Aut oScrollPosition .Y *
(1f / _zoom));
e.Graphics.Tran sform = mx;
SolidBrush b = new SolidBrush(Colo r.FromArgb(64,
Color.Black));
e.Graphics.Fill Rectangle(b, new Rectangle(new Point(20,
20), PageSize));
b.Color = PageColor;
e.Graphics.Fill Rectangle(b, new Rectangle(new Point(0, 0),
PageSize));
if (ClipToPage)
e.Graphics.SetC lip(new Rectangle(0, 0, PageSize.Width,
PageSize.Height ));

//SolidBrush b1 = new SolidBrush(Colo r.FromArgb(64,
Color.Red));
//e.Graphics.Fill Rectangle(b1, new Rectangle(new Point(75,
75), new Size(20, 30)));

base.OnPaint(e) ;
}
protected virtual MouseEventArgs BacktrackMouse( MouseEventArgs e)
{
Matrix mx=new Matrix(_zoom,0, 0,_zoom,0,0);
Size s=new Size( (int)(this.Clie ntSize.Width*(1 f/_zoom)),
(int)(this.Clie ntSize.Height*( 1f/_zoom)));
if(s.Width>Page Size.Width)
mx.Translate((s .Width/2)-(_pageSize.Widt h/2),0);
else
mx.Translate((f loat)this.AutoS crollPosition.X *(1f/_zoom),0);
if(s.Height>Pag eSize.Height)
mx.Translate(0, (s.Height/2)-(this._pageSize .Height/2)+
(this.AutoScrol lPosition.Y));
else
mx.Translate(0, (float)this.Aut oScrollPosition .Y*(1f/_zoom));
mx.Invert();
Point[] px=new Point[]{new Point(e.X,e.Y)} ;
mx.TransformPoi nts(px);
MouseEventArgs et=new
MouseEventArgs( e.Button,e.Clic ks,px[0].X,px[0].Y,e.Delta);
return et;
}
protected override void OnMouseMove(Mou seEventArgs e)
{
MouseEventArgs et=this.Backtra ckMouse(e);
base.OnMouseMov e(et);
}
protected override void OnMouseUp(Mouse EventArgs e)
{
MouseEventArgs et=this.Backtra ckMouse(e);
base.OnMouseUp( et);
}
protected override void OnMouseDown(Mou seEventArgs e)
{
MouseEventArgs et=this.Backtra ckMouse(e);
base.OnMouseDow n(et);
}

private void Canvas_Paint(ob ject sender, PaintEventArgs e)
{
SolidBrush b1 = new SolidBrush(Colo r.FromArgb(64, Color.Red));
e.Graphics.Fill Rectangle(b1, new Rectangle(new Point(75, 75),
new Size(20, 30)));
}

private void Canvas_MouseUp( object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Ri ght)
{
MessageBox.Show ("pt.X,Y = " + e.X.ToString() + "," +
e.Y.ToString()) ;
}
}
}
}


Nov 13 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
9245
by: FL | last post by:
Hi Everyone, I know howto center a block using margin-left: auto ; margin-right: auto ; but I'm trying to center vertically a box, any idea to solve this?
10
26874
by: john T | last post by:
Is there anyway to vertically center a html table using css in such a way it does not alter the html table. When I tryied it just screws up.
32
274524
by: Axel Dahmen | last post by:
Hi, I'd like to align a <div> within the center of the visual canvas. The text within the div should be left-aligned. How can I possibly achieve this? So far I can only align text blocks centrally by using <table align="center" .... . Is this also possible for vertical alignment? TIA, Axel Dahmen
7
3242
by: Alex | last post by:
Hi Everone, I need some advice on how to setup 4 columns where the outside two are absolute (120px) and the inner two (side by side) are relevent (Fluid) and change with the screen. Here's my rough layout:
11
5239
by: Mark Schneider | last post by:
I'm trying to avoid using <table> for formatting purposes where other, reasonable means exist. I'm stuck trying to find a way to find an equivalent for the code below. <table align="center"> <tr> <td>abc</td> </tr> </table>
6
30664
by: Rene | last post by:
I tried searching the newsgroups to see how do you draw a dotted line but I was unable to find an answer, drawing a straight line is very easy but not a dotted one. So the question is, how do I draw a dotted line? Thank you.
3
4539
by: Mark Urish | last post by:
I want to center-align the text in 2 Label controls, and I want the 1st char of their text to line up ------------------------------------------------------------------------------ label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter label1.Text = "IDLE"; //4 char strin label2.Text = "RUN ";//4 char string, //but trailing space ignored and it is centered as thoug...
6
4056
by: James dean | last post by:
I have heard that the video drivers in GDI+ are a big performance issue. But is this only an issue with something like Games Programming i think...is this wrong?. What about a drawing application just drawing simple one dimensional shapes(Polygons,beziers,polylines etc...) are these video drivers still useful for this?. If the video drivers are not a problem then is there any other performance problems that would be disastrous for a...
6
8161
by: johannblake | last post by:
I am wondering whether it is easy to setup a coordinate system for drawing (using GDI+) that uses meters (or any custom scaling for that matter). Currently, I need to convert from pixels to meters for scaling. This can sometimes get rather complex when you need to take scaling into account or other things like window resizing, scrolling, etc. There is a property called PageUnit which can be set to World. I could not find any examples...
0
8760
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8670
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9122
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8967
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6592
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4433
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2458
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.