Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6769063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:08:55+00:00 2026-05-26T15:08:55+00:00

I have code which will draw a graph that scales if the user attempts

  • 0

I have code which will draw a graph that scales if the user attempts to resize the form(by dragging the form’s corners). The form will get an x and y co-ordinate in a textbox. When a button is pushed, i want to plot the point which they have indicated. However, the Click event contains the parameters Object Sender and EventArgs e. The OnPaint method (which i am overriding in order to draw the graph) has the parameter PaintEventArgs.

Due to this, when the button is clicked i cannot do the following code:

g.DrawString("♫", new Font("Calibri", 12), new SolidBrush(Color.HotPink), (PlotArea.X + (7 - xMin)* PlotArea.Width/(xMax - xMin)), (PlotArea.Bottom - (6 - yMin) * PlotArea.Height / (yMax - yMin)));

This is because “g” is of type PaintEventArgs. How do i get around this so that in the onClick method i can plot the co-ordinate?

My code is as follows:

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 PlotIt
{
    public partial class Form1 : Form
    {
        public static List<TheList> GraphPoints = new List<TheList>();

        //Define the drawing area
        private Rectangle PlotArea;
        //Unit defined in world coordinate system:
        private float xMin = 0f;
        private float xMax = 10f;
        private float yMin = 0f;
        private float yMax = 10f;
        //Define the offset in pixel:
        private int offset = 150;
        Graphics g;

        Boolean buttonPressed = false; 
        public Form1()
        {
            InitializeComponent();
            this.SetStyle(ControlStyles.ResizeRedraw, true);
            this.BackColor = Color.White;

        }

        protected override void OnPaint(PaintEventArgs e)
        {
            g = e.Graphics;

            //Calculate the location and size of the drawing area
            //within which we want to draw the graphics:
            Rectangle rect = ClientRectangle;

            PlotArea = new Rectangle(rect.Location, rect.Size);
            PlotArea.Inflate(-offset, -offset);

            g.DrawRectangle(Pens.Black, PlotArea);

            Pen aPen = new Pen(Color.Green, 3);
            g.DrawLine(aPen, Point2D(new PointF(5, 0)), Point2D(new PointF(5, 10)));
            g.DrawLine(aPen, Point2D(new PointF(0, 5)), Point2D(new PointF(10, 5)));

            aPen.Dispose();
            g.Dispose();


        }



        private PointF Point2D(PointF ptf)
        {
            PointF aPoint = new PointF();

            aPoint.X = PlotArea.X + (ptf.X - xMin) * PlotArea.Width / (xMax - xMin);

            aPoint.Y = PlotArea.Bottom - (ptf.Y - yMin) * PlotArea.Height / (yMax - yMin);

            return aPoint;
        }



        private void btnPlotGraph_Click(object sender, EventArgs e)
        {



            g.DrawString("♫", new Font("Calibri", 12), new SolidBrush(Color.HotPink),    (PlotArea.X + (7 - xMin)* PlotArea.Width/(xMax - xMin)), (PlotArea.Bottom - (6 - yMin) * PlotArea.Height / (yMax - yMin)));
        }



    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:08:56+00:00Added an answer on May 26, 2026 at 3:08 pm

    Look into the Control.CreateGraphics Method. That should allow you to get the Graphic object you need.

    Graphics g = this.CreateGraphics();
    g.DrawString("♫", new Font("Calibri", 12), new SolidBrush(Color.HotPink), (PlotArea.X + (7 - xMin)* PlotArea.Width/(xMax - xMin)), (PlotArea.Bottom - (6 - yMin) * PlotArea.Height / (yMax - yMin)));
    g.Dispose();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code which will include template.php file from inside each of these
i am generating *.reg file using code which will have some important data. and
I have the following code, which will not work. The javascript gives no errors
I have the following code, which will retrieve a filename from a table and
I have this piece of code which I'm hoping will be able to tell
I have a basic ajax application, which will not work, instead the php code
I have an application that uses the mapview-overlay-manager code to draw map markers on
I want to draw a circle which will have (inside) triangle fans with the
I have code which needs to do something like this There is a list
I have code which looks like: private static DirectiveNode CreateInstance(Type nodeType, DirectiveInfo info) {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.