Click to See Complete Forum and Search --> : Vis 2008 Drawing Controls?
Salbrismind
March 1st, 2009, 05:46 PM
I'm wondering if anyone knows of some standard drawing controls in VS 2008. I'm trying to build a windows form which creates and shows some data in a form of branching diagrams. I wanted to place it in a control which I could allow to be manipulated similar to how Google Maps works.
The idea is for the user to be able to scroll the view by holding left click and dragging to move the view. I'm stuck trying to find a simple control which allows me to draw in it and when the view is moved that objects drawn don't simply get drawn on the rest of the window.
-Thanks, in Advance.
Edit: I'm using Visual C# 2008 Express Edition
Salbrismind
March 5th, 2009, 08:09 PM
Anyone know anything, at all??
BigEd781
March 6th, 2009, 12:57 AM
You paint a control by overriding the OnPaint method and drawing to the graphics object supplied.
class DrawOnMe : Panel
{
protected override OnPain(PaintEventArgs e)
{
using (Graphics g = e.Graphics)
{
rect = this.ClientRectangle;
g.FillRectangle(Brushes.Pink, rect);
}
}
}
Salbrismind
March 8th, 2009, 05:01 PM
So I can create my own control, and when it draws itself I can use that to draw things inside it which will not just flood out into the rest of the window?
What happens if I tell it to draw things outside of its visible bounds?
BigEd781
March 8th, 2009, 05:58 PM
You could always try it and see. You can draw wherever you want, but a control probably should not need to draw outside of its own area.
Salbrismind
March 10th, 2009, 10:26 AM
I tried creating a new class called DrawPanel:
class DrawPanel : Panel
And this is what it looks like:
class DrawPanel : Panel
{
protected override void OnPaint(PaintEventArgs e)
{
using (Graphics g = e.Graphics)
{
Rectangle rect = this.ClientRectangle;
g.FillRectangle(Brushes.Pink, rect);
}
}
}
But it draws nothing to the screen.
I have this in my window:
private DrawPanel drawPanel;
public MainWindow()
{
InitializeComponent();
//Drawing Control
drawPanel = new DrawPanel();
drawPanel.Location = new Point(50, 50);
drawPanel.Size = new Size(200, 500);
BigEd781
March 10th, 2009, 12:08 PM
You need to add the panel to the Controls collection of the form (I assume that "MainWindow" derives from Form):
private DrawPanel drawPanel;
public MainWindow()
{
InitializeComponent();
//Drawing Control
drawPanel = new DrawPanel();
drawPanel.Location = new Point(50, 50);
drawPanel.Size = new Size(200, 500);
this.Controls.Add(drawPanel);
Salbrismind
March 10th, 2009, 02:19 PM
Thanks, It works perfectly!
Thank you very much for all the help.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.