Position and border colour of borderless form

rahul kumar 605 Reputation points
2023-06-21T09:04:45.6366667+00:00

Hi , I had created a form which should be used for the confirmation when the user presses enter . The problem is I want this form to have the black borders on all sides and that black border should be visible within the Panel1 area (not outside it ) . Also it should be positioned to the right bottom side of the panel .

downsideblackborderform

Developer technologies | Windows Forms
Developer technologies | C#
{count} votes

Accepted answer
  1. Minxin Yu 13,501 Reputation points Microsoft External Staff
    2023-06-22T09:08:11.4566667+00:00

    Hi,

    To create a black border:

    In order to make the effect more obvious, I set a width of 10.

    form2:

            protected override void OnPaint(PaintEventArgs e)
            {
                Rectangle borderRect = new Rectangle(0, 0, Width, Height);
                ControlPaint.DrawBorder(e.Graphics, borderRect, Color.Black, 10, ButtonBorderStyle.Solid, Color.Black, 10, ButtonBorderStyle.Solid, Color.Black, 10, ButtonBorderStyle.Solid, Color.Black, 10, ButtonBorderStyle.Solid);
            }
    
    

    be positioned to the right bottom side of the panel

    Create form2 in form1.

    Gets the position of the panel relative to the screen and minus the length of the message form.

               Form2 messForm = new Form2();
    
                Point panelPositionX = panel1.PointToScreen(Point.Empty);
                int panelRightScreenX = panelPositionX.X + panel1.Width;
    
                Point panelPositionY = panel1.PointToScreen(Point.Empty);
                int panelDownScreenY = panelPositionY.Y + panel1.Height;
               
                messForm.StartPosition = FormStartPosition.Manual;
                messForm.Location =new Point(panelRightScreenX - messForm.Width, panelDownScreenY - messForm.Height);
                messForm.ShowDialog();
    

    enter image description here

    Best regards,

    Minxin Yu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.