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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:10:07+00:00 2026-06-09T13:10:07+00:00

I have to draw a honeycomb pattern and recognize each cell(row,column) on mousemove. this

  • 0

I have to draw a honeycomb pattern and recognize each cell(row,column) on mousemove.
Honeycomb graph description

this is how i am generating the graph.

protected override void GenerateGridBitmap()
    {
        if (_circleGrid != null)
        {
            _circleGrid.Dispose();
            _circleGrid = null;
        }
        Bitmap _texture = new Bitmap(circleSize, circleSize);
        using (Graphics g = Graphics.FromImage(_texture))
        {
            g.SmoothingMode = SmoothingMode.HighQuality;
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            g.PixelOffsetMode = PixelOffsetMode.HighQuality;
            Rectangle r = new Rectangle(0, 0, circleSize, circleSize);
            g.DrawEllipse(Pens.Black, r);
        }

        Bitmap rowBlock = new Bitmap(CanvasSize.Width - (circleSize/ 2), circleSize);

        using (Brush b = new TextureBrush(_texture))
        {
            using (Graphics g = Graphics.FromImage(rowBlock))
            {
                g.CompositingQuality = CompositingQuality.HighQuality;
                g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                g.SmoothingMode = SmoothingMode.HighQuality;
                g.FillRectangle(b, new Rectangle(new Point(0, 0), rowBlock.Size));
            }
        }
        //rowBlock.Save("rowblock.bmp");
        _circleGrid = new Bitmap(CanvasSize.Width, CanvasSize.Height);
        using (Graphics g = Graphics.FromImage(_circleGrid))
        {
            g.CompositingQuality = CompositingQuality.HighQuality;
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            g.SmoothingMode = SmoothingMode.HighQuality;
            int x, y;
            for (int i = 0; i < rows; i++)
            {
                x = 0;
                if (i % 2 != 0)
                    x = (circleSize/ 2);

                y = (i * circleSize);
                if (i != 0)
                {
                    y -= (VERTICAL_PIXEL_OFFSET * i);
                }
                g.DrawImage(rowBlock, x, y);
                //g.DrawImage(DrawCodedCrystal(i,rowBlock), x, y);
                Console.WriteLine(i);
            }
        }
        _circleGrid.Save("grid.bmp");
        Console.WriteLine(_circleGrid.Size);
        _texture.Dispose();
        _texture = null;
        rowBlock.Dispose();
        rowBlock = null;
    }

and this what i am doing to get the coordinates of the graph. but the problem is i am able to get the column perfectly. but for the row i think there is a small difference in calculation. for eg. on the 99 row, for the (1/4) circle it say {row 98} and for the remaining circle it says {row 99}. the deviation increases as the number of rows increases.

protected override CanvasCell GetCanvasCellAt(int x, int y)
    {

        Rectangle rect = GetImageViewPort();
        Point pt = new Point(x, y);

        CanvasCell c = new CanvasCell() { Row = -1, Column = -1 };
        if (rect.Contains(pt))
        {
            double zoomedCircleSize = CircleSize * ZoomFactor;
            Point p = pt;// PointToClient(new Point(x, y));
            p.X -= (int)(rect.X + (AutoScrollPosition.X) );
            p.Y -= (int)(rect.Y + (AutoScrollPosition.Y));

            int row = (int)((p.Y) / (zoomedCircleSize));
            //row = (int)((p.Y + (row * ZoomFactor)) / zoomedCircleSize);
            int col;
            if (row % 2 != 0)
            {
                if (p.X >= 0 && p.X < (zoomedCircleSize / 2))
                {
                    col = -1;
                }
                else
                    col = (int)((p.X - (zoomedCircleSize / 2)) / zoomedCircleSize);
            }
            else
            {
                if (p.X > (zoomedCircleSize * cols))
                {
                    col = -1;
                }
                else
                {
                    col = (int)((p.X) / zoomedCircleSize);

                }
            }
            //if (!GetRectangle(row, col).ContainsWithInBoundingCircle(p))
            //{
            //    c.Column = -1;
            //    c.Row = -1;
            //}
            //else
            {
                c.Column = col;
                c.Row = row;
            }
        }
        //

        return c;
    }

hope i was clear in explaining my problem.

EDIT:
the VERTICAL_PIXEL_OFFSET is 1 and the circle size is 16

  • 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-09T13:10:08+00:00Added an answer on June 9, 2026 at 1:10 pm

    I also posted this on msdn, Stefan Hoffmann was kind enough to post an SSCCE of how to do that. Basically the idea was to precalculate the honeycombs, as @usr suggested in the comments section.
    Here is the link to MSDN post.

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

Sidebar

Related Questions

I have tried to draw a bar in a cell of my table. Everything
I have the code that draw a point inside a polygon. Each time I
I have this code to draw an ellipse in the screen but I don't
I have to draw a graph of elements composing a topological model of a
The problem looks like this, You have to draw N px width line as
I have developed the xtrareport in win-form.NET. In this, i have draw the xtracharts
I have to draw some shapes depending on the status of the row. For
I have to draw a graph with many nodes, and I thought that an
I have to draw a colored map on a graph. The problem is that
I have a problem where I have to draw a graph on an applet

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.