issue in opacity of the parent form and panel

Shaifali jain 420 Reputation points
2023-09-23T11:43:45.1433333+00:00

Hi ,

my other problem is there is a scenario in which i have a form named child which is opened inside a panel of a form named father . what i am trying is when i press F2 on my keyboard a new form opens asking for current date . at this moment i want to blur the parent form as well as the child form so that until the date form is closed , the user cannot do anything except to close the date form first .in other words the previous form controls should be blocked until i close the date form . Any suggestion would be much grateful .

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

Accepted answer
  1. KOZ6.0 6,735 Reputation points
    2023-09-23T12:11:17.8733333+00:00

    prepared two types. Press F2 or F3 to see it working.

    using System;
    using System.Drawing;
    using System.Windows.Forms;
    
    public partial class Father : Form
    {
        public Father() {
            InitializeComponent();
        }
    
        protected override void OnShown(EventArgs e) {
            base.OnShown(e);
            TransparencyKey = Color.Magenta;
        }
    
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
            if (keyData == (Keys.F2)) {
                BeginInvoke((Action)ShowDateForm1);
                return true;
            }
            if (keyData == (Keys.F3)) {
                BeginInvoke((Action)ShowDateForm2);
                return true;
            }
            return base.ProcessCmdKey(ref msg, keyData);
        }
    
        private void ShowDateForm1() {
            Opacity = 0.5d;
            using (var dateForm = new DateForm()) {
                dateForm.ShowDialog();
            }
            Opacity = 1.0d;
        }
    
        Color panelBackColor;
        Color formBackColor;
    
        private void ShowDateForm2() {
            // save BacColor
            formBackColor = BackColor;
            panelBackColor = FatherPanel.BackColor;
            // make transparent
            BackColor = TransparencyKey;
            FatherPanel.BackColor = TransparencyKey;
            FatherPanel.Enabled = false;
            // Open DateForm
            var dateForm = new DateForm();
            dateForm.FormClosed += DateForm_FormClosed;
            dateForm.Show();
        }
    
        private void DateForm_FormClosed(object sender,
                                        FormClosedEventArgs e) {
            // restore BacColor
            BackColor = formBackColor;
            FatherPanel.BackColor = panelBackColor;
            FatherPanel.Enabled = true;
            // activate
            Activate();
        }
    }
    
    

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.