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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:44:00+00:00 2026-06-10T17:44:00+00:00

I’m currently working on a program in WinForms that will require a lot of

  • 0

I’m currently working on a program in WinForms that will require a lot of special logic for rendering and mouse clicks on a PictureBox. I’d rather not have all of that logic stored in a custom control or even worse the main form that hosts the picture box. An added complication is there are certain objects that need to be known about in order to draw them correctly or handle clicking them.

Currently, the only idea I have is to make separate “Renderer” and “MouseHandler” classes that have a handle to the picture box and I can handle whatever events inside there. The issue is doing this while maintaining an MVP structure.

So, here’s a little example code to better explain what’s going on.

Main Form

public partial class Form1 : Form, IView
{
    private Renderer _render;
    private MouseHandler _mouseHandler;

    public Form1() { InitializeComponent(); }

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);

        _render = new Renderer(Picbox);
        _mouseHandler = new MouseHandler(Picbox);
    }

    #region Implementation of IView

    public string FirstName { get; set; }
    public string LastName { get; set; }

    #endregion
}

Presenter for Main Form

public class Presenter
{
    private readonly IView _view;
    private readonly Model _model;

    public Presenter(IView view)
    {
        _view = view;
        _model = new Model("John", "Doe");
    }
}

Renderer

public class Renderer
    {
        private readonly PictureBox _pictureBox;

        public Renderer(PictureBox pictureBox)
        {
            _pictureBox = pictureBox;
            _pictureBox.Paint += PictureBoxOnPaint;
        }

        private static void PictureBoxOnPaint(object sender, PaintEventArgs e)
        {
            // TODO: Draw stuff like First and Last Name
        }

        public void Refresh() { _pictureBox.Invalidate(); }
    }

Model

public class Model
{
    private string FirstName { get; set; }
    private string LastName { get; set; }

    public Model(string firstName, string lastName)
    {
        FirstName = firstName;
        LastName = lastName;
    }
}

I cannot figure out a way to have the Renderer draw FirstName and LastName from the Main View’s model without:

A. Giving the parent hosting the PictureBox the job of pushing information to the auxiliary classes by pushing the model info to the view from the presenter, then having the view push that to the Renderer.

or B. Adding a reference to the Forms library in the presenter to tie everything together. This would allow me to make views out of the auxillary classes and add a PictureBox property, but I’d like to avoid this in case the view turns into an MVC Application or WPF Application and the view does not use windows forms.

Is there any way I can get these auxiliary classes to work? Or is there a better method for this entirely? I’d hate to think I’m doomed to cram all of it in a custom control. Thanks in advance for any suggestions!

  • 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-10T17:44:02+00:00Added an answer on June 10, 2026 at 5:44 pm

    In place where you instantiate the renderer, why don’t you give it a reference to the model object that contains the data? Surely, it is the “A” way, but as you are ‘manually’ binding it hard to the PictureBox, so I do not see anything wrong in additionally passing it the model instance altogether with the picbox. It seems natural to me that when I’m creating an object and configuring it – I configure it fully. Otherwise, you’d have to add some renderer-building-layer, because, naturally, the renderer simply must get the data somehow..

    Actually, giving the model to the renderer is not (at least for me) any breach in the architecture and does not place any extra burden/logic on the ‘hoster’, provided that you will pass ‘the whole model’ and the renderer will be responsible for reading the actual data it needs. IMHO, in such way, everything would be exactly right in its place.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a function that will clean a strings' special characters. I do NOT
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into

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.