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 9247169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:39:54+00:00 2026-06-18T09:39:54+00:00

I have a problem with object ChartSettings from my form initialization. It’s my own

  • 0

I have a problem with object ChartSettings from my form initialization.

It’s my own class added below Form1 code:

public partial class Form1 : Form
{


    public Form1(bool archivePlotPreview)
    {
        InitializeComponent();
        ChartSettings chartOne = new ChartSettings(this.chart1, archivePlotPreview);
    }

    public ChartSettings chartOne;

    //Form1 variables and functions
}

public class ChartSettings
{

    public ChartSettings(Chart settingsRelatedChart, bool archivePlotPreview)
    {
        // przypisanie wykresu do ktorego odnosza sie ustawienia
        ChartObject = settingsRelatedChart;
        ChartObject.MouseMove += new System.Windows.Forms.MouseEventHandler(this.chart1_MouseMove);

        barchivePlotPreview = archivePlotPreview;

    }

    // other variables and functions
}

The reason of creating this class is the need of additional variables related to Chart object (chart1 added in Designer window) like CSV save options, min/max markers options etc. So in constructor of Form1 I’ve added line creating my ChartSettings object as can be seen above. It assings chart1 to it and in further code I’d like to use chartOne.ChartObject instead of this.chart1.

When I create new Form1 instance a window shows up, chart1 is visible etc. but when I push the “Load data” button where I use chartOne.ChartObject reference it crashes because chartOne is null :/ Direct operations on this.chart1 seems to be ok.
When I debug my code, chartOne IS created in constructor and is not a null, but when I press mentioned button it acts like above anyway.
Why my chartOne dissapears somewhere between? And how should it be done right way?

  • 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-06-18T09:39:55+00:00Added an answer on June 18, 2026 at 9:39 am

    you are not initializing the property ChartSettings chartOne but you are creating an instance inside constructor, and it is disposed when constructor finishes. It means you have never initialized the class level property chartOne; thus it will be always null.

    When you use this.chartOne you are declaring that you want to use the property defined in the class.

    Change it to;

    public ChartSettings chartOne{ get; set;}
    
    public Form1(bool archivePlotPreview)
    {
        InitializeComponent();
        chartOne = new ChartSettings(this.chart1, archivePlotPreview);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem with my code Public Class Form1 Dim lm(4, 4) As Char
I have problem with deserialize document to object using XmlSerializer class. Code my function
I have a problem cloning dynamic object with the code like this: public void
I have problem with session and query execution, please see code below. class A
I have problem with session and query execution,please see code below. class A implements
I have problem with ObjectContext.SaveChanges method: public void Save(Action<object, object> action) { EventAggregator.GetEvent<EntityServiceRequestingEvent>().Publish(true); var
I have the following problem: I have the class: class Word(object): def __init__(self): self.id
I have an API that returns a promise from a deferred object. The problem
Hi i have a problem with object composition. The class CInvoice needs to have
I have problem with sending a object from my webservice. I have created a

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.