Dimming inactive forms

前端 未结 3 1519
囚心锁ツ
囚心锁ツ 2021-01-16 13:36

When opening Dialog form using Form.ShowDialog() I want to dim the rest of application with a shade of gray.

From my own research it seems that the way to do it is

3条回答
  •  清歌不尽
    2021-01-16 14:05

    I'm not sure what you mean by dimming the "rest of the application" but I will show you how to colour the application with a shade of gray with an opacity less than 100%.

    Code (I'm assuming you're using c#):

    Graphics g = this.CreateGraphics(); // Creating graphics for this form.
    g.FillRectangle(Color.FromArgb(80, 102, 90, 95), 0, 0, this.Width, this.Height); 
    // Draws a gray rectangle with an opacity of 30% over the whole form.
    

    Then to get rid of the gray rectangle you can use:

    this.Invalidate();
    

    Which will redraw the form, all the controls will stay the same but the gray will go away.

    Hope this Helps!

提交回复
热议问题