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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:59:18+00:00 2026-06-05T23:59:18+00:00

I have two classess and a Userform. I am trying not to use any

  • 0

I have two classess and a Userform. I am trying not to use any Form related code in my classess but i am rather new to OOP. In the CreateGraph() method, i would like to prompt the user with a Yes/No dialog. The code in the method would continue based on the result. I have read some examples on MVP but not exactly sure how i can implement in this case.

Can someone guide me on this? I do believe there is some serious design issues in my code

//singleton class
public class MyApplication
{
    private int state;
    private static MyApplication instance = null;

    public void Task1()
    {
        GraphGenerator gg = new GraphGenerator();
        gg.CreateGraph();
        state = 1;
    }

    public void Task2()
    {
        //some other tasks..
        state = 2;

    }
}

Class where i have issue..

public class GraphGenerator
{
    public void CreateGraph()
    {
        //some code for creating a graph..
        //here i want to prompt the user with a
        // Yes/No dialog box..
    }
}

The userform

public partial class Form1 : Form
{
    private void btnTask1_Click(object sender, EventArgs e)
    {
        MyApplication ma = MyApplication.Instance;
        ma.Task1();
    }

    private void btnTask1_Click(object sender, EventArgs e)
    {
        MyApplication ma = MyApplication.Instance;
        ma.Task2();
    }
}
  • 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-05T23:59:19+00:00Added an answer on June 5, 2026 at 11:59 pm

    First , it is best to design your classes as much as possible such that you don’t need to intermingle UI code with your domain objects. Can you restructure the code so that the caller/owner of GraphGenerator decides if it needs to ask the user something instead of GraphGenerator doing it? Try to keep GraphGenerator solely focused on his task or making graphs.

    Failing that, you could define events (or delegates or callback interface, but lets call these related mechanisms events for now) within GraphGenerator such that the caller/owner can listen for notifications from GraphGenerator and in turn interact with the user. For example, define an event called QueryConfirmSave to raise and the caller can handle the event and prompt the user and then pass back a boolean as an EventArg field.

    (The code would be something like this (from the hip, not editor checked):

    GraphGenerator gg = new GraphGenerator();
    gg.QueryConfirmSave += new EventHandler<ConfirmSaveArgs>(GraphGenerator_QueryConfirmSave);
    

    and then:

    private void GraphGenerator_QueryConfirmSave(object sender, ConfirmSaveArgs args)
    {
       if (MessageBox.Show("Save?") == DialogResult.Yes)
       {
          args.SaveConfirmed = true;
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two classes, but don't what kind of relation i should use. I
I have two classes.... Parcel and FundParcel...and I'm trying to convert an IEnumerable of
I have two classes that refer to each other, but obviously the compiler complains.
I have two classes; Area and LanguageArea . I use LanguageArea to handle translated
I have two classes one of which inherits from the other. Im trying to
I have two classes Teacher and Student . I am trying to get teacher
I have two classes in a many-to-many relationship, but only one of them have
I have two classes declared in C# code: public class A { public static
I have two classes, Phone.class and Time.class. I would like to use their methods
I have two classes: public class Article { private ISet<IdentNumber> identNumbers = new HashedSet<IdentNumber>();

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.