Create dashboard with center at user click point

Asked

Viewed 155 times

3

I need to create a Panel in a Form Getting kind of like this:

inserir a descrição da imagem aqui

When you click the mouse on Form create the Panel taking the location of the click and create the Panel centralized.

I did so:

Panel panel = new Panel();

private void criarLabel()
{
      panel.Size = new System.Drawing.Size(200, 100);
      panel.Visible = true;
      this.grid.Controls.Add(panel);
}
private void grid_CellClick(object sender, DataGridViewCellEventArgs e)
{
     criarLabel();
}
  • Have you ever tried to do anything?

  • I can create the Panel.

  • I just can’t center it on the Click site. My panel has a fixed height

  • 1

    It’s just that I think you missed some part of your question. Come on, you want to click on an area of the screen and create a panel that has the "center" in the part that the user clicked, right?

  • 1

    It has how to put the code you have so far?

  • I edited the question.

  • That’s right @jbueno..

  • 1

    I liked the question, just think she could be better written, anyway +1.

  • @jbueno can change the question to make it better written!

  • Did you make it? @Lilloh

Show 5 more comments

1 answer

3


Place this code block in the event MouseClick of Form (or the control that will have the Panel added).

var panel = new Panel
{
    BackColor = Color.Black,
    Height = 100,
    Width = 200
};

panel.Location = new Point(e.X - (panel.Width / 2), e.Y - (panel.Height / 2));

this.Controls.Add(panel);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.