TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Bill Cappoli
NA
12
0
Help needed on program that draws shapes
Dec 16 2008 2:17 AM
I'm working on some homework and need to create an application that draws 3 shapes when the form is clicked. The objects are suppose to be drawn on specified surface area within the form. I have the surface area being created but cannot seem to get a shape to be drawn onto it when clicked. I'm thinking that there is a problem with my event handling of the mouse click but I cannot seem to figure out how to fix it. I have included my code and would appreciate any help or direction that you guys could provide me.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace William_Cappoli_IT466_Unit_6_Project
{
public partial class frmMain : Form
{
private DrawImage imgDraw;
public frmMain()
{
imgDraw = new DrawImage();
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs paintEvnt)
{
// Get the graphics object
Graphics gfx = paintEvnt.Graphics;
// calls draw method from DrawImage class and passes it the graphics object
imgDraw.DrawBoundingBox(gfx);
}
private void frmMain_Click(PaintEventArgs e)
{
Graphics imgObj = e.Graphics;
imgDraw.Draw(imgObj);
}
} // end partial class frmMain class
}
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class DrawImage
{
// private members that determine where drawing surface starts, how big it is and the color of it
private float xCoordinate = 0;
private float yCoordinate = 60;
private float width = 521;
private float height = 560;
private Color backcolor = Color.White;
// creates surface for drawing objects onto
public void DrawBoundingBox(Graphics g)
{
// Create a new pen that we shall use for drawing the line
Pen myPen = new Pen(Color.Black);
SolidBrush myBrush = new SolidBrush(backcolor);
g.DrawRectangle(myPen, xCoordinate, yCoordinate, width, height);
g.FillRectangle(myBrush, xCoordinate, yCoordinate, width, height);
} // end DrawBoundingBox method
// draws rectangle when form is clicked
public void Draw(Graphics o)
{
Pen imgPen = new Pen(Color.Black);
o.DrawRectangle(imgPen, 90, 100, 45, 75);
}
} // end DrawImage class
Thanks in advance
Reply
Answers (
3
)
Data trnsfer from text file to access file using C#
Javascript Parameters containing Apostrophes in asp