Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to get an array of Pens in a user defined class to "work" in a WinForm?

How to get an array of Pens in a user defined class to "work" in a WinForm?

Scheduled Pinned Locked Moved C#
graphicshelpdata-structurestutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anonymous
    wrote on last edited by
    #1

    Why won't the Form see this method? /////////////////////////////////////////// //Here's a snippet of my Complex2.cs code (seperate Sol'n file) private Pen [] activePen; private int _penIndex = -1; public Complex2() { Pen[] activePen = new Pen[] { new Pen( Color.Blue, 2 ), new Pen( Color.Green, 2 ), new Pen(Color.Red, 2) }; activePen[0].StartCap = System.Drawing.Drawing2D.LineCap.Triangle; // TODO: Add constructor logic here real = 0; imag = 0; } public Complex2(double _re, double _im) { real = _re; imag = _im; } public Pen GetNextPen() { _penIndex = (_penIndex + 1) % 3; activePen[_penIndex].StartCap = System.Drawing.Drawing2D.LineCap.Triangle; return activePen[_penIndex]; } ////////////////////////////////////////////// //Here's some relevant code form Form1.cs protected Complex2 cmplxValue1 = new Complex2(0,0); //these get values changed from TestBoxes... protected Complex2 cmplxValue2 = new Complex2(0,0); void DrawComplexNumber1(Graphics g) { Pen p = GetNextPen(); c_xy.SetOrigin(xIndent + graphRect.Width/2, yIndent + graphRect.Y/2); cmplxValue1.Real = Convert.ToDouble(textComplex_1Real.Text); cmplxValue1.Imaginary = Convert.ToDouble(textComplex_1Imaginary.Text); g.DrawLine(GetNextPen(), 250, 250, (float)(250 + (xIndent * cmplxValue1.Real)), (float)(250 - (yIndent * cmplxValue1.Imaginary))); } ERROR CForm1.cs(335): The name 'GetNextPen' does not exist in the class or namespace 'ComplexTest2.Form1' Even if I try this: g.DrawLine(cmplxValue1.GetNextPen()....) the instantiated object doesn't "see" the method... please help thanks a lot....

    M 1 Reply Last reply
    0
    • A Anonymous

      Why won't the Form see this method? /////////////////////////////////////////// //Here's a snippet of my Complex2.cs code (seperate Sol'n file) private Pen [] activePen; private int _penIndex = -1; public Complex2() { Pen[] activePen = new Pen[] { new Pen( Color.Blue, 2 ), new Pen( Color.Green, 2 ), new Pen(Color.Red, 2) }; activePen[0].StartCap = System.Drawing.Drawing2D.LineCap.Triangle; // TODO: Add constructor logic here real = 0; imag = 0; } public Complex2(double _re, double _im) { real = _re; imag = _im; } public Pen GetNextPen() { _penIndex = (_penIndex + 1) % 3; activePen[_penIndex].StartCap = System.Drawing.Drawing2D.LineCap.Triangle; return activePen[_penIndex]; } ////////////////////////////////////////////// //Here's some relevant code form Form1.cs protected Complex2 cmplxValue1 = new Complex2(0,0); //these get values changed from TestBoxes... protected Complex2 cmplxValue2 = new Complex2(0,0); void DrawComplexNumber1(Graphics g) { Pen p = GetNextPen(); c_xy.SetOrigin(xIndent + graphRect.Width/2, yIndent + graphRect.Y/2); cmplxValue1.Real = Convert.ToDouble(textComplex_1Real.Text); cmplxValue1.Imaginary = Convert.ToDouble(textComplex_1Imaginary.Text); g.DrawLine(GetNextPen(), 250, 250, (float)(250 + (xIndent * cmplxValue1.Real)), (float)(250 - (yIndent * cmplxValue1.Imaginary))); } ERROR CForm1.cs(335): The name 'GetNextPen' does not exist in the class or namespace 'ComplexTest2.Form1' Even if I try this: g.DrawLine(cmplxValue1.GetNextPen()....) the instantiated object doesn't "see" the method... please help thanks a lot....

      M Offline
      M Offline
      Mohamad Al Husseiny
      wrote on last edited by
      #2

      You wrote Anonymous wrote: Pen p = GetNextPen(); this will generate The name 'GetNextPen' does not exist in the class or namespace 'ComplexTest2.Form1' error because the compiler will think GetNextPen() member of Form and this not true because it is a member of complex2 and you didn't call it from an object of this class Anonymous wrote: Even if I try this: g.DrawLine(cmplxValue1.GetNextPen()....) the instantiated object doesn't "see" the method... please help thanks a lot.... are you replaced all places you call this function or gust this line? you need to replace all the places like Pen p = GetNextPen(); too MCAD -- modified at 1:01 Thursday 6th October, 2005

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups